From 575bb997f52f1cab882546d82d0c76e88e84d1b5 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Wed, 8 Oct 2003 00:40:16 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/showbase/ShadowPlacer.py | 91 +++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 direct/src/showbase/ShadowPlacer.py diff --git a/direct/src/showbase/ShadowPlacer.py b/direct/src/showbase/ShadowPlacer.py new file mode 100755 index 0000000000..65778db02d --- /dev/null +++ b/direct/src/showbase/ShadowPlacer.py @@ -0,0 +1,91 @@ +""" +ShadowPlacer.py places a shadow. + +It traces a line from a light source to the opposing surface. +Or it may do that later, right now it puts a node on the surface under +the its parent node. +""" + +from ShowBaseGlobal import * + +import DirectNotifyGlobal +import DirectObject + +class ShadowPlacer(DirectObject.DirectObject): + notify = DirectNotifyGlobal.directNotify.newCategory("ShadowPlacer") + + # special methods + def __init__(self, cTrav, shadowNodePath, + wallCollideMask, floorCollideMask): + DirectObject.DirectObject.__init__(self) + self.setup(cTrav, shadowNodePath, + wallCollideMask, floorCollideMask) + + def setup(self, cTrav, shadowNodePath, + wallCollideMask, floorCollideMask): + """ + Set up the collisions + """ + assert not shadowNodePath.isEmpty() + + self.cTrav = cTrav + self.shadowNodePath = shadowNodePath + + floorOffset = 0.025 + # Set up the collison ray + # This is a ray cast from floorOffset down to detect floor polygons + self.cRay = CollisionRay(0.0, 0.0, 4.0, 0.0, 0.0, -1.0) + self.cRayNode = CollisionNode('shadowPlacer') + self.cRayNode.addSolid(self.cRay) + self.cRayNodePath = shadowNodePath.attachNewNode(self.cRayNode) + self.cRayBitMask = floorCollideMask + self.cRayNode.setFromCollideMask(self.cRayBitMask) + self.cRayNode.setIntoCollideMask(BitMask32.allOff()) + + # set up floor collision mechanism + self.lifter = CollisionHandlerFloor() + #self.lifter.setInPattern("on-floor") + #self.lifter.setOutPattern("off-floor") + self.lifter.setOffset(floorOffset) + + # activate the collider with the traverser and pusher + self.on() + + self.lifter.addColliderNode(self.cRayNode, shadowNodePath.node()) + + def delete(self): + del self.cTrav + + del self.shadowNodePath + + del self.cRay + del self.cRayNode + self.cRayNodePath.removeNode() + del self.cRayNodePath + + del self.lifter + + def off(self): + self.cTrav.removeCollider(self.cRayNode) + # Now that we have disabled collisions, make one more pass + # right now to ensure we aren't standing in a wall. + self.oneTimeCollide() + + def on(self): + self.cTrav.addCollider(self.cRayNode, self.lifter) + + 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() + tempCTrav.addCollider(self.cRayNode, self.lifter) + tempCTrav.traverse(render) + + if __debug__: + def debugPrint(self, message): + """for debugging""" + return self.notify.debug( + str(id(self))+' '+message)