Browse Source

*** empty log message ***

Dave Schuyler 20 years ago
parent
commit
948d428141
1 changed files with 65 additions and 4 deletions
  1. 65 4
      direct/src/controls/ObserverWalker.py

+ 65 - 4
direct/src/controls/ObserverWalker.py

@@ -30,10 +30,71 @@ class ObserverWalker(NonPhysicsWalker.NonPhysicsWalker):
         """
         Set up the avatar for collisions
         """
-        NonPhysicsWalker.NonPhysicsWalker.initializeCollisions(
-            self, collisionTraverser, avatarNodePath,
-            avatarRadius, floorOffset, reach)
-        self.cTrav.removeCollider(self.cRayNodePath)
+        """
+        Set up the avatar for collisions
+        """
+        assert not avatarNodePath.isEmpty()
+
+        self.cTrav = collisionTraverser
+        self.avatarNodePath = avatarNodePath
+
+        # Set up the collision sphere
+        # This is a sphere on the ground to detect barrier collisions
+        self.cSphere = CollisionSphere(0.0, 0.0, 0.0, avatarRadius)
+        cSphereNode = CollisionNode('NPW.cSphereNode')
+        cSphereNode.addSolid(self.cSphere)
+        self.cSphereNodePath = avatarNodePath.attachNewNode(cSphereNode)
+
+        cSphereNode.setFromCollideMask(self.cSphereBitMask)
+        cSphereNode.setIntoCollideMask(BitMask32.allOff())
+
+        # set up wall collision mechanism
+        self.pusher = CollisionHandlerPusher()
+        self.pusher.setInPattern("enter%in")
+        self.pusher.setOutPattern("exit%in")
+        
+        self.pusher.addCollider(self.cSphereNodePath, avatarNodePath)
+
+        # activate the collider with the traverser and pusher
+        self.setCollisionsActive(1)
+        
+        class Foo:
+            def hasContact(self):
+                return 1
+        
+        self.lifter = Foo()
+
+    def deleteCollisions(self):
+        del self.cTrav
+
+        del self.cSphere
+        self.cSphereNodePath.removeNode()
+        del self.cSphereNodePath
+
+        del self.pusher
+
+    def setCollisionsActive(self, active = 1):
+        assert(self.debugPrint("setCollisionsActive(active%s)"%(active,)))
+        if self.collisionsActive != active:
+            self.collisionsActive = active
+            if active:
+                self.cTrav.addCollider(self.cSphereNodePath, self.pusher)
+            else:
+                self.cTrav.removeCollider(self.cSphereNodePath)
+
+                # Now that we have disabled collisions, make one more pass
+                # right now to ensure we aren't standing in a wall.
+                self.oneTimeCollide()
+
+    def oneTimeCollide(self):
+        """
+        Makes one quick collision pass for the avatar, for instance as
+        a one-time straighten-things-up operation after collisions
+        have been disabled.
+        """
+        tempCTrav = CollisionTraverser("oneTimeCollide")
+        tempCTrav.addCollider(self.cSphereNodePath, self.pusher)
+        tempCTrav.traverse(render)
 
     def enableAvatarControls(self):
         """