def test_motionstate(self): """ Set and get a motion state. """ # Get RigidBody object. body = getRB() # Create a new Transform. pos = Vec3(1, 2, 3.5) rot = Quaternion(0, 1, 0, 0) t = Transform() t.setOrigin(pos) t.setRotation(rot) # It must be impossible to instantiate 'MotionState' directly. with pytest.raises(NotImplementedError): MotionState() # Create a MotionState and apply the new transform. ms_ref = DefaultMotionState() ms_ref.setWorldTransform(t) # Verify the MotionState does not yet match ours. ms = body.getMotionState() assert ms.getWorldTransform().getOrigin() != pos assert ms.getWorldTransform().getRotation() != rot # Apply- and query the MotionState. body.setMotionState(ms_ref) ms = body.getMotionState() # Verify the MotionState is correct. assert ms.getWorldTransform().getOrigin() == pos assert ms.getWorldTransform().getRotation() == rot
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)
def moveBody(rb, pos): trans = Transform() trans.setOrigin(pos) ms = DefaultMotionState() ms.setWorldTransform(trans) rb.setMotionState(ms)
from azBullet import StaticPlaneShape, SphereShape from azBullet import DefaultMotionState, Transform 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)