def test_linearVelocity(self): body = RigidBody() body.setLinearVelocity(Vector3(1, 2, 3)) velocity = body.getLinearVelocity() self.assertEquals(velocity.x, 1) self.assertEquals(velocity.y, 2) self.assertEquals(velocity.z, 3)
def test_isInWorld(self): body = RigidBody() self.assertFalse(body.isInWorld()) world = DiscreteDynamicsWorld() world.addRigidBody(body) self.assertTrue(body.isInWorld()) world.removeRigidBody(body) self.assertFalse(body.isInWorld())
def test_getInvInertiaDiagLocal(self): """ L{RigidBody.getInvInertiaDiagLocal} returns the inverse of the local inertia vector. """ body = RigidBody() inertia = body.getInvInertiaDiagLocal() self.assertTrue(isinstance(inertia, Vector3))
def test_linearVelocity(self): world = DiscreteDynamicsWorld() world.setGravity(Vector3(0, 0, 0)) obj = RigidBody(None, None, 1) obj.setLinearVelocity(Vector3(1, 2, 3)) world.addRigidBody(obj) expectedSteps = 64 numSteps = world.stepSimulation(1.0, expectedSteps, 1.0 / expectedSteps) self.assertEqual(numSteps, expectedSteps) position = obj.getMotionState().getWorldTransform().getOrigin() self.assertEquals(position.x, 1) self.assertEquals(position.y, 2) self.assertEquals(position.z, 3)
def test_stepSimulation(self): world = DiscreteDynamicsWorld() world.setGravity(Vector3(1, 2, 3)) obj = RigidBody(None, None, 1) world.addRigidBody(obj) expectedSteps = 64 numSteps = world.stepSimulation(1.0, expectedSteps, 1.0 / expectedSteps) self.assertEqual(numSteps, expectedSteps) position = obj.getMotionState().getWorldTransform().getOrigin() # Unfortunately, there is some error (as compared to physical reality) # in Bullet's results. My fault? Bullet's fault? I'm not sure. self.assertEqual(position.x, 0.5 + 0.5 / expectedSteps) self.assertEqual(position.y, 1.0 + 1.0 / expectedSteps) self.assertEqual(position.z, 1.5 + 1.5 / expectedSteps)
def test_applyImpulse(self): body = RigidBody(mass=1.0) body.applyImpulse(Vector3(1, 2, 3), Vector3(1, 1, 1)) world = DiscreteDynamicsWorld() world.setGravity(Vector3(0, 0, 0)) world.addRigidBody(body) expectedSteps = 64 numSteps = world.stepSimulation(1.0, expectedSteps, 1.0 / expectedSteps) self.assertEqual(numSteps, expectedSteps) transform = body.getMotionState().getWorldTransform() position = transform.getOrigin() self.assertEqual(position.x, 1.0) self.assertEqual(position.y, 2.0) self.assertEqual(position.z, 3.0) rot = transform.getRotation() self.assertNotEqual((rot.getX(), rot.getY(), rot.getZ(), rot.getW()), (0, 0, 0, 1))
def test_removeRigidBody(self): world = DiscreteDynamicsWorld() body = RigidBody() world.addRigidBody(body) world.removeRigidBody(body)
def objAt(pos): obj = RigidBody(None, BoxShape(Vector3(1, 1, 1)), 1.0) xform = Transform() xform.setOrigin(pos) obj.setWorldTransform(xform) return obj
def test_friction(self): body = RigidBody() body.setFriction(3.5) self.assertEqual(3.5, body.getFriction())
def test_setAngularFactor(self): body = RigidBody() body.setAngularFactor(1.0)
def test_getInvMass(self): """ L{RigidBody.getInvMass} returns the inverse of the mass of the body. """ body = RigidBody(mass=16) self.assertEqual(1. / 16, body.getInvMass())