Ver Fonte

use is allowing setting of the avatar

Dave Schuyler há 21 anos atrás
pai
commit
8ab8656e3e

+ 2 - 1
direct/src/controls/ControlManager.py

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

+ 5 - 0
direct/src/controls/DevWalker.py

@@ -47,6 +47,11 @@ class DevWalker(DirectObject.DirectObject):
         #assert(self.debugPrint("getSpeeds()"))
         #assert(self.debugPrint("getSpeeds()"))
         return (self.speed, self.rotationSpeed)
         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, 
     def initializeCollisions(self, collisionTraverser, avatarNodePath, 
             wallCollideMask, floorCollideMask,
             wallCollideMask, floorCollideMask,
             avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):
             avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):

+ 6 - 1
direct/src/controls/GravityWalker.py

@@ -18,7 +18,7 @@ from direct.showbase.ShowBaseGlobal import *
 
 
 from direct.directnotify import DirectNotifyGlobal
 from direct.directnotify import DirectNotifyGlobal
 from direct.showbase import DirectObject
 from direct.showbase import DirectObject
-from pandac import PhysicsManager
+#from pandac import PhysicsManager
 import math
 import math
 
 
 
 
@@ -168,6 +168,11 @@ class GravityWalker(DirectObject.DirectObject):
         #assert(self.debugPrint("getSpeeds()"))
         #assert(self.debugPrint("getSpeeds()"))
         return (self.speed, self.rotationSpeed)
         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):
     def setupRay(self, bitmask, floorOffset, reach):
         assert self.notify.debugStateCall(self)
         assert self.notify.debugStateCall(self)
         # This is a ray cast from your head down to detect floor polygons.
         # This is a ray cast from your head down to detect floor polygons.

+ 5 - 0
direct/src/controls/NonPhysicsWalker.py

@@ -46,6 +46,11 @@ class NonPhysicsWalker(DirectObject.DirectObject):
         #assert(self.debugPrint("getSpeeds()"))
         #assert(self.debugPrint("getSpeeds()"))
         return (self.speed, self.rotationSpeed)
         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,
     def initializeCollisions(self, collisionTraverser, avatarNodePath,
             wallCollideMask, floorCollideMask,
             wallCollideMask, floorCollideMask,
             avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):
             avatarRadius = 1.4, floorOffset = 1.0, reach = 1.0):

+ 15 - 9
direct/src/controls/PhysicsWalker.py

@@ -118,6 +118,11 @@ class PhysicsWalker(DirectObject.DirectObject):
         #assert(self.debugPrint("getSpeeds()"))
         #assert(self.debugPrint("getSpeeds()"))
         return (self.__speed, self.__rotationSpeed)
         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):
     def setupRay(self, floorBitmask, floorOffset):
         # This is a ray cast from your head down to detect floor polygons
         # 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
         # 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 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 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 isAirborne", self.isAirborne)
-        onScreenDebug.add("w hasContact", self.lifter.hasContact())
 
 
     def handleAvatarControls(self, task):
     def handleAvatarControls(self, task):
         """
         """

+ 81 - 12
direct/src/controls/ShipPilot.py

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