use is allowing setting of the avatar

This commit is contained in:
Dave Schuyler 2004-08-13 01:23:08 +00:00
parent b01c703cca
commit 8ab8656e3e
6 changed files with 114 additions and 23 deletions

View File

@ -97,7 +97,7 @@ class ControlManager:
controls.setCollisionsActive(0)
self.controls[name] = controls
def use(self, name="basic"):
def use(self, name, avatar):
"""
name is a key (string) that was previously passed to add().
@ -113,6 +113,7 @@ class ControlManager:
self.currentControls.disableAvatarControls()
self.currentControls.setCollisionsActive(0)
self.currentControls = controls
self.currentControls.setAvatar(avatar)
self.currentControls.setCollisionsActive(1)
if self.isEnabled:
self.currentControls.enableAvatarControls()

View File

@ -47,6 +47,11 @@ class DevWalker(DirectObject.DirectObject):
#assert(self.debugPrint("getSpeeds()"))
return (self.speed, self.rotationSpeed)
def setAvatar(self, avatar):
self.avatar = avatar
if avatar is not None:
pass # setup the avatar
def initializeCollisions(self, collisionTraverser, avatarNodePath,
wallCollideMask, floorCollideMask,
avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):

View File

@ -18,7 +18,7 @@ from direct.showbase.ShowBaseGlobal import *
from direct.directnotify import DirectNotifyGlobal
from direct.showbase import DirectObject
from pandac import PhysicsManager
#from pandac import PhysicsManager
import math
@ -168,6 +168,11 @@ class GravityWalker(DirectObject.DirectObject):
#assert(self.debugPrint("getSpeeds()"))
return (self.speed, self.rotationSpeed)
def setAvatar(self, avatar):
self.avatar = avatar
if avatar is not None:
pass # setup the avatar
def setupRay(self, bitmask, floorOffset, reach):
assert self.notify.debugStateCall(self)
# This is a ray cast from your head down to detect floor polygons.

View File

@ -46,6 +46,11 @@ class NonPhysicsWalker(DirectObject.DirectObject):
#assert(self.debugPrint("getSpeeds()"))
return (self.speed, self.rotationSpeed)
def setAvatar(self, avatar):
self.avatar = avatar
if avatar is not None:
pass # setup the avatar
def initializeCollisions(self, collisionTraverser, avatarNodePath,
wallCollideMask, floorCollideMask,
avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):

View File

@ -118,6 +118,11 @@ class PhysicsWalker(DirectObject.DirectObject):
#assert(self.debugPrint("getSpeeds()"))
return (self.__speed, self.__rotationSpeed)
def setAvatar(self, avatar):
self.avatar = avatar
if avatar is not None:
self.setupPhysics(avatar)
def setupRay(self, floorBitmask, floorOffset):
# This is a ray cast from your head down to detect floor polygons
# A toon is about 4.0 feet high, so start it there
@ -408,17 +413,18 @@ class PhysicsWalker(DirectObject.DirectObject):
"""
onScreenDebug.add("w controls", "PhysicsWalker")
onScreenDebug.add("w airborneHeight", self.lifter.getAirborneHeight())
onScreenDebug.add("w falling", self.falling)
onScreenDebug.add("w isOnGround", self.lifter.isOnGround())
#onScreenDebug.add("w gravity", self.lifter.getGravity())
if self.useLifter:
onScreenDebug.add("w airborneHeight", self.lifter.getAirborneHeight())
onScreenDebug.add("w isOnGround", self.lifter.isOnGround())
#onScreenDebug.add("w gravity", self.lifter.getGravity())
onScreenDebug.add("w contact normal", self.lifter.getContactNormal().pPrintValues())
onScreenDebug.add("w impact", self.lifter.getImpactVelocity())
onScreenDebug.add("w velocity", self.lifter.getVelocity())
onScreenDebug.add("w hasContact", self.lifter.hasContact())
#onScreenDebug.add("w falling", self.falling)
#onScreenDebug.add("w jumpForce", self.avatarControlJumpForce)
onScreenDebug.add("w contact normal", self.lifter.getContactNormal().pPrintValues())
onScreenDebug.add("w mayJump", self.mayJump)
onScreenDebug.add("w impact", self.lifter.getImpactVelocity())
onScreenDebug.add("w velocity", self.lifter.getVelocity())
#onScreenDebug.add("w mayJump", self.mayJump)
onScreenDebug.add("w isAirborne", self.isAirborne)
onScreenDebug.add("w hasContact", self.lifter.hasContact())
def handleAvatarControls(self, task):
"""

View File

@ -83,10 +83,10 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
#*# Debug:
if not hasattr(ship, "acceleration"):
self.ship.acceleration = 60
self.ship.maxSpeed = 100
self.ship.maxSpeed = 12
self.ship.reverseAcceleration = 10
self.ship.maxReverseSpeed = 20
self.ship.turnRate = 30
self.ship.turnRate = 3
self.ship.maxTurn = 30
self.ship.anchorDrag = .9
self.ship.hullDrag = .9
@ -229,8 +229,15 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
self.phys.attachLinearIntegrator(LinearEulerIntegrator())
self.phys.attachPhysicalnode(physicsActor.node())
self.momentumForce=LinearVectorForce(0.0, 0.0, 0.0)
fn=ForceNode("ship momentum")
fnp=NodePath(fn)
fnp.reparentTo(render)
fn.addForce(self.momentumForce)
self.phys.addLinearForce(self.momentumForce)
self.acForce=LinearVectorForce(0.0, 0.0, 0.0)
fn=ForceNode("ship vatarControls")
fn=ForceNode("ship avatarControls")
fnp=NodePath(fn)
fnp.reparentTo(render)
fn.addForce(self.acForce)
@ -263,7 +270,7 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
self.cTrav = collisionTraverser
self.floorOffset = floorOffset = 7.0
self.wallBitmask = wallBitmask
self.floorBitmask = floorBitmask
self.floorBitmask = BitMask32().allOff() #*#floorBitmask
self.avatarRadius = avatarRadius
self.floorOffset = floorOffset
self.reach = reach
@ -432,8 +439,27 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
slideRight = 0#inputState.isSet("slideRight")
jump = inputState.isSet("jump")
# Determine what the speeds are based on the buttons:
self.__speed=(forward and self.ship.acceleration or
reverse and -self.ship.reverseAcceleration)
if not hasattr(self, "sailsDeployed"):
self.sailsDeployed = 0.0
if forward and reverse:
# Way anchor:
self.__speed = 0.0
physObject.setVelocity(Vec3.zero())
elif forward:
self.sailsDeployed += 0.25
if self.sailsDeployed > 1.0:
self.sailsDeployed = 1.0
elif reverse:
self.sailsDeployed -= 0.25
if self.sailsDeployed < -1.0:
self.sailsDeployed = -1.0
self.__speed = self.ship.acceleration * self.sailsDeployed
#self.__speed=(forward and self.ship.acceleration or
# reverse and -self.ship.reverseAcceleration)
avatarSlideSpeed=self.ship.acceleration*0.5
#self.__slideSpeed=slide and (
# (turnLeft and -avatarSlideSpeed) or
@ -444,7 +470,20 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
self.__rotationSpeed=not slide and (
(turnLeft and self.ship.turnRate) or
(turnRight and -self.ship.turnRate))
#*#
if not hasattr(self, "currentTurning"):
self.currentTurning = 0.0
self.currentTurning += self.__rotationSpeed
if self.currentTurning > self.ship.maxTurn:
self.currentTurning = self.ship.maxTurn
elif self.currentTurning < -self.ship.maxTurn:
self.currentTurning = -self.ship.maxTurn
self.currentTurning *= 0.9
self.__rotationSpeed = self.currentTurning
if self.wantDebugIndicator:
self.displayDebugInfo()
@ -621,13 +660,18 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
if __debug__:
onScreenDebug.add("phys", "off")
# Check to see if we're moving at all:
if self.__speed or self.__slideSpeed or self.__rotationSpeed or moveToGround!=Vec3.zero():
if 1 or self.__speed or self.__slideSpeed or self.__rotationSpeed or moveToGround!=Vec3.zero():
distance = dt * self.__speed
slideDistance = dt * self.__slideSpeed
rotation = dt * self.__rotationSpeed
#debugTempH=self.avatarNodePath.getH()
assert self.avatarNodePath.getQuat().isSameDirection(physObject.getOrientation())
if __debug__:
q1=self.avatarNodePath.getQuat()
q2=physObject.getOrientation()
q1.normalize()
q2.normalize()
assert q1.isSameDirection(q2)
assert self.avatarNodePath.getPos().almostEqual(physObject.getPosition(), 0.0001)
# update pos:
@ -641,16 +685,36 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
step=rotMat.xform(self.__vel)
newVector = self.acForce.getLocalVector()+Vec3(step)
maxLen = self.ship.maxSpeed
#newVector = self.acForce.getLocalVector()+Vec3(step)
newVector = Vec3(step)
#newVector=Vec3(rotMat.xform(newVector))
#maxLen = self.ship.maxSpeed
maxLen = self.ship.acceleration
if newVector.length() > maxLen:
newVector.normalize()
newVector *= maxLen
newVector.normalize()
newVector *= maxLen
onScreenDebug.add("newVector",
newVector)
onScreenDebug.add("newVector length",
newVector.length())
self.acForce.setVector(Vec3(newVector))
#*#
speed = physObject.getVelocity()
speedLen = speed.length()
if speedLen > self.ship.maxSpeed:
speed.normalize()
speed *= self.ship.maxSpeed
physObject.setVelocity(speed)
#self.actorNode.updateTransform()
#physObject.setPosition(Point3(
# physObject.getPosition()+step+moveToGround))
@ -663,7 +727,12 @@ class ShipPilot(PhysicsWalker.PhysicsWalker):
# sync the change:
self.actorNode.updateTransform()
assert self.avatarNodePath.getQuat().isSameDirection(physObject.getOrientation())
if __debug__:
q1=self.avatarNodePath.getQuat()
q2=physObject.getOrientation()
q1.normalize()
q2.normalize()
assert q1.isSameDirection(q2)
assert self.avatarNodePath.getPos().almostEqual(physObject.getPosition(), 0.0001)
#assert self.avatarNodePath.getH()==debugTempH-rotation
messenger.send("avatarMoving")