예제 #1
0
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.show()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Ground
        shape = BulletPlaneShape(Vec3(0, 0, 1.0), 0)

        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        np.node().addShape(shape)
        np.setPos(0, 0, 0)
        np.setCollideMask(BitMask32.allOn())

        cm = CardMaker('ground')
        cm.setFrame(-20, 20, -20, 20)
        gfx = render.attachNewNode(cm.generate())
        gfx.setP(-90)
        gfx.setZ(-0.01)
        gfx.setColorScale(Vec4(0.4))

        self.world.attachRigidBody(np.node())

        X = 0.3
        Y = 4.0
        Z = 1.5

        stepsY = 1.5

        shapesData = [
            dict(name='wall0',
                 size=Vec3(X, Y, Z),
                 pos=Point3(Y * 2.0, -(Y + stepsY), Z),
                 hpr=Vec3()),
            dict(name='wall1',
                 size=Vec3(X, Y, Z),
                 pos=Point3(Y * 2.0, (Y + stepsY), Z),
                 hpr=Vec3()),
            dict(name='wall4',
                 size=Vec3(X, Y, Z),
                 pos=Point3(Y, (Y * 2.0 + stepsY - X), Z),
                 hpr=Vec3(90, 0, 0)),
            dict(name='wall5',
                 size=Vec3(X, Y, Z),
                 pos=Point3(-Y, (Y * 2.0 + stepsY - X), Z),
                 hpr=Vec3(90, 0, 0)),
            dict(name='wall6',
                 size=Vec3(X, Y, Z),
                 pos=Point3(Y, -(Y * 2.0 + stepsY - X), Z),
                 hpr=Vec3(90, 0, 0)),
            dict(name='wall7',
                 size=Vec3(X, Y, Z),
                 pos=Point3(-Y, -(Y * 2.0 + stepsY - X), Z),
                 hpr=Vec3(90, 0, 0)),
            dict(name='ceiling',
                 size=Vec3(Y, Y * 2.0, X),
                 pos=Point3(0, -(Y + stepsY - X), Z),
                 hpr=Vec3(90, 0, 0)),
            dict(name='ceiling',
                 size=Vec3(Y, Z, X),
                 pos=Point3(-Z, (Y + stepsY - X), Z * 2.0 - X),
                 hpr=Vec3(90, 0, 0)),
            dict(name='ceiling',
                 size=Vec3(Y, Z, X),
                 pos=Point3(Z, (Y + stepsY - X), Z * 4.0 - X),
                 hpr=Vec3(90, 0, 0)),

            # CHANGE ROTATION TO TEST DIFFERENT SLOPES
            dict(name='slope',
                 size=Vec3(20, stepsY + Y * 2.0, X),
                 pos=Point3(-Y * 2.0, 0, 0),
                 hpr=Vec3(0, 0, 50)),
        ]

        for i in range(10):
            s = Vec3(0.4, stepsY, 0.2)
            p = Point3(Y * 2.0 + i * s.x * 2.0, 0, s.z + i * s.z * 2.0)
            data = dict(name='Yall', size=s, pos=p, hpr=Vec3())
            shapesData.append(data)

        for data in shapesData:
            shape = BulletBoxShape(data['size'])

            np = self.worldNP.attachNewNode(BulletRigidBodyNode(data['name']))
            np.node().addShape(shape)
            np.setPos(data['pos'])
            np.setHpr(data['hpr'])
            np.setCollideMask(BitMask32.allOn())

            self.world.attachRigidBody(np.node())

        shape = BulletSphereShape(0.5)
        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ball'))
        np.node().addShape(shape)
        np.node().setMass(10.0)
        np.setPos(13.0, 0, 5.0)
        np.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(np.node())

        shape = BulletBoxShape(Vec3(0.5))
        np = self.worldNP.attachNewNode(BulletRigidBodyNode('Crate'))
        np.node().addShape(shape)
        np.node().setMass(10.0)
        np.setPos(-13.0, 0, 10.0)
        np.setCollideMask(BitMask32.allOn())
        self.world.attachRigidBody(np.node())

        shape = BulletBoxShape(Vec3(1, 1, 2.5))
        self.ghost = self.worldNP.attachNewNode(BulletGhostNode('Ghost'))
        self.ghost.node().addShape(shape)
        self.ghost.setPos(-5.0, 0, 3)
        self.ghost.setCollideMask(BitMask32.allOn())
        self.world.attachGhost(self.ghost.node())

        taskMgr.add(self.checkGhost, 'checkGhost')

        self.character = PandaBulletCharacterController(
            self.world, self.worldNP, 1.75, 1.3, 0.5, 0.4)
        self.character.setPos(render, Point3(0, 0, 0.5))
예제 #2
0
# attach to the Bullet world
world.attachRigidBody(node)

# this is unnecessary since debug is on
## make it visible																#BUG: model does not match up with the shape, offset properly
#model = loader.loadModel('models/box.egg')
#model.flattenLight()
#model.reparentTo(np)

#############
# character #
#############
"""This uses peterpodgorski's kcc. Refer to the source, it's nicely documented."""

# the controller takes care of all the internal things
node = PandaBulletCharacterController(world, worldNP, 1.75, 1.3, 0.5, 0.4)

# This isn't necessary anymore due to debug
## make it visible																#BUG: this model too did not match the actual shape, be careful next time
#model = loader.loadModel('models/box.egg')
#model.flattenLight()
#model.reparentTo(node.movementParent)	# currently, the easiest way to parent a visible model is to use the movementParent


# task to update the character, this is needed for now
def c_update(task):
    dt = globalClock.getDt()
    node.update()
    return task.cont