Added fake avatar-drive mode

This commit is contained in:
Gyedo Jeon 2007-11-16 01:33:27 +00:00
parent 384bd2bb4e
commit 1d3de3fb79

View File

@ -26,6 +26,13 @@ from direct.task import Task
import Pmw import Pmw
import __builtin__ import __builtin__
# [gjeon] to control avatar movement in drive mode
from direct.controls import ControlManager
from direct.controls import GravityWalker
from toontown.toon import RobotToon
from otp.otpbase import OTPGlobals
# Force direct and tk to be on # Force direct and tk to be on
base.startDirect(fWantDirect = 1, fWantTk = 1) base.startDirect(fWantDirect = 1, fWantTk = 1)
@ -631,6 +638,13 @@ class LevelEditor(NodePath, DirectObject):
# [gjeon] to find out currently moving camera in maya mode # [gjeon] to find out currently moving camera in maya mode
self.mouseMayaCamera = False self.mouseMayaCamera = False
# [gjeon] to find out drive mode stat
self.fDrive = False
# [gjeon] to control drive mode
self.controlManager = None
self.avatar = None
# ENABLE/DISABLE # ENABLE/DISABLE
def enable(self): def enable(self):
@ -771,6 +785,7 @@ class LevelEditor(NodePath, DirectObject):
self.collisionsOff() self.collisionsOff()
# Turn on visiblity # Turn on visiblity
self.visibilityOff() self.visibilityOff()
base.camera.wrtReparentTo(render)
# Reset cam # Reset cam
base.camera.iPos(base.cam) base.camera.iPos(base.cam)
base.cam.iPosHpr() base.cam.iPosHpr()
@ -778,39 +793,67 @@ class LevelEditor(NodePath, DirectObject):
self.enableMouse() self.enableMouse()
base.direct.enable() base.direct.enable()
# [gjeon] disable avatar and controlManager
if (self.avatar):
self.avatar.reparentTo(hidden)
if (self.controlManager):
self.controlManager.disable()
self.fDrive = False
def useDriveMode(self): def useDriveMode(self):
""" Lerp down to eye level then switch to Drive mode """ """ Lerp down to eye level then switch to Drive mode """
pos = base.direct.camera.getPos() # create avatar and set it's location to the camera
pos.setZ(4.0) if (self.avatar == None):
hpr = base.direct.camera.getHpr() self.avatar = RobotToon.RobotToon()
hpr.set(hpr[0], 0.0, 0.0) self.avatar.setName("The Inspector")
t = base.direct.camera.lerpPosHpr(pos, hpr, 1.0, blendType = 'easeInOut', self.avatar.loop('idle')
task = 'manipulateCamera')
self.avatar.setPos(base.camera.getPos())
self.avatar.reparentTo(render)
## pos = base.direct.camera.getPos()
## pos.setZ(4.0)
## hpr = base.direct.camera.getHpr()
## hpr.set(hpr[0], 0.0, 0.0)
## t = base.direct.camera.lerpPosHpr(pos, hpr, 1.0, blendType = 'easeInOut',
## task = 'manipulateCamera')
# Note, if this dies an unatural death, this could screw things up # Note, if this dies an unatural death, this could screw things up
# t.uponDeath = self.switchToDriveMode # t.uponDeath = self.switchToDriveMode
self.switchToDriveMode(None)
self.fDrive = True
def switchToDriveMode(self, state): def switchToDriveMode(self, state):
""" Disable direct camera manipulation and enable player drive mode """ """ Disable direct camera manipulation and enable player drive mode """
base.direct.minimumConfiguration() #base.direct.minimumConfiguration()
base.direct.manipulationControl.disableManipulation() #base.direct.manipulationControl.disableManipulation()
# Update vis data # Update vis data
self.initVisibilityData() self.initVisibilityData()
# Switch to drive mode ## # Switch to drive mode
base.useDrive() ## base.useDrive()
# Move cam up and back ## # Move cam up and back
base.cam.setPos(0, -5, 4) ## base.cam.setPos(0, -5, 4)
# And move down and forward to compensate ## # And move down and forward to compensate
base.camera.setPos(base.camera, 0, 5, -4) ## base.camera.setPos(base.camera, 0, 5, -4)
# Make sure we're where we want to be ## # Make sure we're where we want to be
pos = base.direct.camera.getPos() ## pos = base.direct.camera.getPos()
pos.setZ(0.0) ## pos.setZ(0.0)
hpr = base.direct.camera.getHpr() ## hpr = base.direct.camera.getHpr()
hpr.set(hpr[0], 0.0, 0.0) ## hpr.set(hpr[0], 0.0, 0.0)
# Fine tune the drive mode ## # Fine tune the drive mode
base.mouseInterface.node().setPos(pos) ## base.mouseInterface.node().setPos(pos)
base.mouseInterface.node().setHpr(hpr) ## base.mouseInterface.node().setHpr(hpr)
base.mouseInterface.node().setForwardSpeed(20.0) ## base.mouseInterface.node().setForwardSpeed(0)
base.mouseInterface.node().setReverseSpeed(20.0) ## base.mouseInterface.node().setReverseSpeed(0)
base.camera.wrtReparentTo(self.avatar)
base.camera.setHpr(0, 0, 0)
#base.camera.setPos(0, 0, 0)
base.camera.setPos(0, -11.8125, 3.9375)
base.camLens.setFov(VBase2(60, 46.8265))
# Turn on collisions # Turn on collisions
if self.panel.fColl.get(): if self.panel.fColl.get():
self.collisionsOn() self.collisionsOn()
@ -821,6 +864,32 @@ class LevelEditor(NodePath, DirectObject):
if self.panel.fColl.get() or self.panel.fVis.get(): if self.panel.fColl.get() or self.panel.fVis.get():
self.traversalOn() self.traversalOn()
if (self.controlManager == None):
# create player movement controls,camera controls, and avatar
self.controlManager = ControlManager.ControlManager()
avatarRadius = 1.4
floorOffset = OTPGlobals.FloorOffset
reach = 4.0
walkControls=GravityWalker.GravityWalker(gravity = -32.1740 * 2.0)
walkControls.setWallBitMask(OTPGlobals.WallBitmask)
walkControls.setFloorBitMask(OTPGlobals.FloorBitmask)
walkControls.initializeCollisions(self.cTrav, self.avatar,
avatarRadius, floorOffset, reach)
self.controlManager.add(walkControls, "walk")
self.controlManager.use("walk", self)
# set speeds after adding controls to the control manager
self.controlManager.setSpeeds(
OTPGlobals.ToonForwardSpeed,
OTPGlobals.ToonJumpForce,
OTPGlobals.ToonReverseSpeed,
OTPGlobals.ToonRotateSpeed
)
else:
self.controlManager.enable()
def configureDriveModeCollisionData(self): def configureDriveModeCollisionData(self):
""" """
Set up the local avatar for collisions Set up the local avatar for collisions
@ -869,8 +938,8 @@ class LevelEditor(NodePath, DirectObject):
self.cTrav = CollisionTraverser("LevelEditor") self.cTrav = CollisionTraverser("LevelEditor")
# activate the collider with the traverser and pusher # activate the collider with the traverser and pusher
self.pusher.addCollider(self.cSphereNodePath, base.camera, base.drive.node()) #self.pusher.addCollider(self.cSphereNodePath, base.camera, base.drive.node())
self.lifter.addCollider(self.cRayNodePath, base.camera, base.drive.node()) #self.lifter.addCollider(self.cRayNodePath, base.camera, base.drive.node())
# A map of zone ID's to a list of nodes that are visible from # A map of zone ID's to a list of nodes that are visible from
# that zone. # that zone.
self.nodeDict = {} self.nodeDict = {}
@ -889,11 +958,11 @@ class LevelEditor(NodePath, DirectObject):
base.cTrav = 0 base.cTrav = 0
def collisionsOff(self): def collisionsOff(self):
self.cTrav.removeCollider(self.cSphereNode) self.cTrav.removeCollider(self.cSphereNodePath)
def collisionsOn(self): def collisionsOn(self):
self.collisionsOff() self.collisionsOff()
self.cTrav.addCollider(self.cSphereNode, self.pusher) self.cTrav.addCollider(self.cSphereNodePath, self.pusher)
def toggleCollisions(self): def toggleCollisions(self):
if self.panel.fColl.get(): if self.panel.fColl.get():
@ -979,7 +1048,7 @@ class LevelEditor(NodePath, DirectObject):
# Accept event # Accept event
self.accept("on-floor", self.enterZone) self.accept("on-floor", self.enterZone)
# Add collider # Add collider
self.cTrav.addCollider(self.cRayNode, self.lifter) self.cTrav.addCollider(self.cRayNodePath, self.lifter)
# Reset lifter # Reset lifter
self.lifter.clear() self.lifter.clear()
# Reset flag # Reset flag
@ -987,7 +1056,7 @@ class LevelEditor(NodePath, DirectObject):
def visibilityOff(self): def visibilityOff(self):
self.ignore("on-floor") self.ignore("on-floor")
self.cTrav.removeCollider(self.cRayNode) self.cTrav.removeCollider(self.cRayNodePath)
self.showAllVisibles() self.showAllVisibles()
def toggleVisibility(self): def toggleVisibility(self):
@ -1000,6 +1069,7 @@ class LevelEditor(NodePath, DirectObject):
self.traversalOff() self.traversalOff()
def enterZone(self, newZone): def enterZone(self, newZone):
return
""" """
Puts the toon in the indicated zone. newZone may either be a Puts the toon in the indicated zone. newZone may either be a
CollisionEntry object as determined by a floor polygon, or an CollisionEntry object as determined by a floor polygon, or an
@ -1012,7 +1082,10 @@ class LevelEditor(NodePath, DirectObject):
# Get zone id # Get zone id
if isinstance(newZone, CollisionEntry): if isinstance(newZone, CollisionEntry):
# Get the name of the collide node # Get the name of the collide node
newZoneId = int(newZone.getIntoNode().getName()) try:
newZoneId = int(newZone.getIntoNode().getName())
except:
newZoneId = 0
else: else:
newZoneId = newZone newZoneId = newZone
# Ensure we have vis data # Ensure we have vis data
@ -2081,6 +2154,13 @@ class LevelEditor(NodePath, DirectObject):
for i in self.selectedNodePathHookHooks: for i in self.selectedNodePathHookHooks:
i() i()
# if in drive mode and some object is selected, disable
# avatar controls and camera controls to prevent conflicts
# with being able to manipulate the selected object
if self.fDrive:
if self.controlManager:
self.controlManager.disable()
def deselectedNodePathHook(self, nodePath): def deselectedNodePathHook(self, nodePath):
# Clear out old root variables # Clear out old root variables
self.selectedDNARoot = None self.selectedDNARoot = None