Exemple #1
0
        def runSimulation(sim):
            # Create the collision shapes for the ball and ground.
            cs_ball = SphereShape(1)
            cs_ground = StaticPlaneShape(Vec3(0, 1, 0), 1)

            # Create a Rigid Body for the static (ie mass=0) Ground.
            q0 = Quaternion(0, 0, 0, 1)
            ms = DefaultMotionState(Transform(q0, Vec3(0, -1, 0)))
            ci = RigidBodyConstructionInfo(0, ms, cs_ground)
            rb_ground = RigidBody(ci, bodyID=1)
            del ms, ci

            # Create a Rigid body for the dynamic (ie mass > 0) Ball.
            ms = DefaultMotionState(Transform(q0, Vec3(0, 5, 0)))
            inertia = cs_ball.calculateLocalInertia(1)
            ci = RigidBodyConstructionInfo(1, ms, cs_ball, inertia)
            rb_ball = RigidBody(ci, bodyID=2)
            del ms, inertia, ci

            # Ensure that Bullet never deactivates the objects.
            rb_ground.forceActivationState(4)
            rb_ball.forceActivationState(4)

            # Add both bodies to the simulation.
            sim.addRigidBody(rb_ground)
            sim.addRigidBody(rb_ball)

            # Sanity check: the ball must be at position y=5
            pos = rb_ball.getMotionState().getWorldTransform().getOrigin()
            pos = pos.topy()
            assert pos[1] == 5

            # Step the simulation long enough for the ball to fall down and
            # come to rest on the plane.
            for ii in range(10):
                sim.stepSimulation(1, 100)

            # Verify that the y-position of the ball is such that the ball
            # rests on the plane.
            pos = rb_ball.getMotionState().getWorldTransform().getOrigin()
            return pos.topy()
Exemple #2
0
def getRB(pos=Vec3(0, 0, 0), cshape=SphereShape(1), bodyID=0):
    """
    Return a Rigid Body plus auxiliary information (do *not* delete; see
    note below).

    .. note:: Do not delete the tuple until the end of the test
    because it may lead to memory access violations. The reason is that a
    rigid body requires several indepenent structures that need to remain
    in memory.
    """
    t = Transform(Quaternion(0, 0, 0, 1), pos)
    ms = DefaultMotionState(t)
    mass = 1

    # Build construction info and instantiate the rigid body.
    ci = RigidBodyConstructionInfo(mass, ms, cshape)
    rb = RigidBody(ci, bodyID)

    # Ensure the body remains activated.
    rb.forceActivationState(4)
    return rb