Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import direct.directbase.DirectStart
- from direct.showbase.ShowBase import ShowBase
- from direct.showbase.InputStateGlobal import inputState
- from panda3d.core import AmbientLight
- from panda3d.core import DirectionalLight
- from panda3d.core import Vec3
- from panda3d.core import Vec4
- from panda3d.core import Point3
- from panda3d.core import TransformState
- from panda3d.core import BitMask32
- from panda3d.bullet import BulletWorld
- from panda3d.bullet import BulletPlaneShape
- from panda3d.bullet import BulletBoxShape
- from panda3d.bullet import BulletRigidBodyNode
- from panda3d.bullet import BulletDebugNode
- from panda3d.bullet import BulletHeightfieldShape
- from panda3d.bullet import ZUp
- class testingclassname(ShowBase):
- def __init__(self):
- #setup environment
- self.init()
- # Task
- taskMgr.add(self.update, 'updateWorld')
- # Physics
- self.setup()
- # _____INIT_____
- def init(self):
- base.setBackgroundColor(0.1, 0.1, 0.8, 1)
- base.setFrameRateMeter(True)
- base.cam.setPos(0, -20, 4)
- base.cam.lookAt(0, 0, 0)
- # Light
- alight = AmbientLight('ambientLight')
- alight.setColor(Vec4(0.5, 0.5, 0.5, 1))
- alightNP = render.attachNewNode(alight)
- dlight = DirectionalLight('directionalLight')
- dlight.setDirection(Vec3(1, 1, -1))
- dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
- dlightNP = render.attachNewNode(dlight)
- render.clearLight()
- render.setLight(alightNP)
- render.setLight(dlightNP)
- # ____TASK___
- def update(self, task):
- dt = globalClock.getDt()
- self.world.doPhysics(dt)
- return task.cont
- # ____SETUP___
- def setup(self):
- self.worldNP = render.attachNewNode('World')
- # World
- self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
- self.debugNP.show()
- self.debugNP.node().showWireframe(True)
- self.debugNP.node().showConstraints(True)
- self.debugNP.node().showBoundingBoxes(False)
- self.debugNP.node().showNormals(True)
- self.world = BulletWorld()
- self.world.setGravity(Vec3(0, 0, -9.81))
- self.world.setDebugNode(self.debugNP.node())
- # Plane
- #shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
- #node = BulletRigidBodyNode('Ground')
- #node.addShape(shape)
- #np = render.attachNewNode(node)
- #np.setPos(0, 0, -2)
- #self.world.attachRigidBody(node)
- # ground
- shape= BulletPlaneShape(Vec3(0,0,1),-1)
- mask = BitMask32(0x0f)
- print 'ground: ',mask
- np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
- np.node().addShape(shape)
- np.setPos(0,0,-1)
- np.setCollideMask(mask)
- self.world.attachRigidBody(np.node())
- # Box 1
- shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
- mask = BitMask32.allOff()
- print 'box-1: ', mask
- np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-1'))
- np.node().setMass(1.0)
- np.node().addShape(shape)
- np.setPos(-6, 0, 4)
- np.setCollideMask(mask)
- self.world.attachRigidBody(np.node())
- model = loader.loadModel('models/box.egg')
- model.reparentTo(np)
- # Box 2
- shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
- mask = BitMask32.bit(0)
- print 'box-2: ', mask
- np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-2'))
- np.node().setMass(1.0)
- np.node().addShape(shape)
- np.setPos(-2, 0, 4)
- np.setCollideMask(mask)
- self.world.attachRigidBody(np.node())
- model = loader.loadModel('models/box.egg')
- model.reparentTo(np)
- # Box 3
- shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
- mask = BitMask32.bit(2)
- print 'box-3: ', mask
- np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-3'))
- np.node().setMass(1.0)
- np.node().addShape(shape)
- np.setPos(2, 0, 4)
- np.setCollideMask(mask)
- self.world.attachRigidBody(np.node())
- model = loader.loadModel('models/box.egg')
- model.reparentTo(np)
- # Box 4
- shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
- mask = BitMask32(0x3)
- print 'box-4: ', mask
- np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-4'))
- np.node().setMass(1.0)
- np.node().addShape(shape)
- np.setPos(6, 0, 4)
- np.setCollideMask(mask)
- self.world.attachRigidBody(np.node())
- model = loader.loadModel('models/box.egg')
- model.reparentTo(np)
- game = testingclassname()
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement