Exemple #1
0
    def test_ConstructionInfo(self):
        """
        Create a RigidBodyConstructionInfo class and set/get some attributes.
        """
        mass = 1.5
        pos = Vec3(1, 2, 3)
        rot = Quaternion(0, 0, 0, 1)
        t = Transform(rot, pos)
        ms = DefaultMotionState(t)
        cs = EmptyShape()
        ci = RigidBodyConstructionInfo(mass, ms, cs)

        # Mass was specified in Ctor.
        assert ci.mass == mass
        ci.mass = 1.1
        assert ci.mass == 1.1
        ci.mass = 1.1
        assert ci.mass == 1.1

        # Local inertia was specified in Ctor.
        assert ci.localInertia == Vec3(0, 0, 0)
        inert = Vec3(1, 2, 10)
        ci.localInertia = inert
        assert ci.localInertia == inert
        inert = Vec3(1, 2, 20)
        ci.localInertia = inert
        assert ci.localInertia == inert

        # Verify the 'motionState' attribute.
        assert ci.motionState.getWorldTransform().getOrigin() == pos
        assert ci.motionState.getWorldTransform().getRotation() == rot

        # Verify the 'collisionShape' attribute.
        assert ci.collisionShape.getName() == b"Empty"
Exemple #2
0
    def test_ConstructionInfo_to_RigidBody(self):
        """
        Verify that the initial motion state is transferred correctly to the
        RigidBody.
        """
        mass = 10
        pos = Vec3(1, 2, 3)
        rot = Quaternion(0, 1, 0, 0)
        t = Transform(rot, pos)
        ms = DefaultMotionState(t)
        cs = EmptyShape()
        inert = Vec3(1, 2, 4)

        # Compile the Rigid Body parameters.
        ci = RigidBodyConstructionInfo(mass, ms, cs, Vec3(2, 4, 6))
        assert ci.localInertia == Vec3(2, 4, 6)
        ci.localInertia = inert
        assert ci.localInertia == inert

        # Construct the rigid body and delete the construction info.
        body = RigidBody(ci)
        del ci

        # Verify that the object is at the correct position and has the correct
        # mass and inertia.
        t = body.getMotionState().getWorldTransform()
        assert t.getOrigin() == pos
        assert t.getRotation() == rot
        assert body.getInvMass() == 1 / mass
        assert body.getInvInertiaDiagLocal() == Vec3(1, 0.5, 0.25)
Exemple #3
0
def getRB(pos=Vec3(0, 0, 0), cshape=SphereShape(1)):
    """
    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)
    return RigidBody(ci)
Exemple #4
0
from azBullet import RigidBody, RigidBodyConstructionInfo

# Instantiate the Bullet simulation.
sim = azBullet.BulletBase()
sim.setGravity(Vec3(0, -10, 0))

# Create the collision shape for Ball and Ground.
ballShape = SphereShape(1)
groundShape = StaticPlaneShape(Vec3(0, 1, 0), 1)

# Create the rigid body for the Ground. Since it is a static body its mass must
# be zero.
mass = 0
groundRigidBodyState = DefaultMotionState(
    Transform(Quaternion(0, 0, 0, 1), Vec3(0, -1, 0)))
ci = RigidBodyConstructionInfo(mass, groundRigidBodyState, groundShape)
groundRigidBody = RigidBody(ci)
groundRigidBody.setRestitution(1.0)
sim.addRigidBody(groundRigidBody)
del mass, ci

# Create the rigid body for the Ball. Since it is a dynamic body we need to
# specify mass and inertia. The former we need to do ourselves but Bullet can
# do the heavy lifting for the Inertia and compute it for us.
fallRigidBodyState = DefaultMotionState(
    Transform(Quaternion(0, 0, 0, 1), Vec3(0, 20, 0)))
mass = 1
fallInertia = ballShape.calculateLocalInertia(mass)
ci = RigidBodyConstructionInfo(mass, fallRigidBodyState, ballShape,
                               fallInertia)
fallRigidBody = RigidBody(ci)