def test_origin(self): transform = Transform() transform.setOrigin(Vector3(1, 2, 3)) origin = transform.getOrigin() self.assertEqual(origin.x, 1) self.assertEqual(origin.y, 2) self.assertEqual(origin.z, 3)
def test_fromConstructionInfoWithoutMotionState(self): """ When L{RigidBody.fromConstructionInfo} is used to construct a L{RigidBody} without a L{MotionState}, the C{worldTransform} parameter is used to specify the body's initial position. """ mass = 8 shape = SphereShape(3) inertia = Vector3(1, 2, 3) startTransform = Transform() startTransform.setOrigin(Vector3(5, 6, 7)) linearDamping = 0.3 angularDamping = 0.4 friction = 4.5 restition = 5.4 linearSleepingThreshold = 4.3 angularSleepingThreshold = 3.2 body = RigidBody.fromConstructionInfo(None, shape, mass, inertia, startTransform, linearDamping, angularDamping, friction, restition, linearSleepingThreshold, angularSleepingThreshold) origin = body.getWorldTransform().getOrigin() self.assertEqual(5, origin.x) self.assertEqual(6, origin.y) self.assertEqual(7, origin.z)
def test_fromConstructionInfoWithoutMotionState(self): """ When L{RigidBody.fromConstructionInfo} is used to construct a L{RigidBody} without a L{MotionState}, the C{worldTransform} parameter is used to specify the body's initial position. """ mass = 8 shape = SphereShape(3) inertia = Vector3(1, 2, 3) startTransform = Transform() startTransform.setOrigin(Vector3(5, 6, 7)) linearDamping = 0.3 angularDamping = 0.4 friction = 4.5 restition = 5.4 linearSleepingThreshold = 4.3 angularSleepingThreshold = 3.2 body = RigidBody.fromConstructionInfo( None, shape, mass, inertia, startTransform, linearDamping, angularDamping, friction, restition, linearSleepingThreshold, angularSleepingThreshold) origin = body.getWorldTransform().getOrigin() self.assertEqual(5, origin.x) self.assertEqual(6, origin.y) self.assertEqual(7, origin.z)
def test_worldTransform(self): obj = CollisionObject() trans = Transform() trans.setOrigin(Vector3(3, 5, 7)) obj.setWorldTransform(trans) origin = obj.getWorldTransform().getOrigin() self.assertEquals(origin.x, 3) self.assertEquals(origin.y, 5) self.assertEquals(origin.z, 7)
def test_rotation(self): transform = Transform() transform.setRotation(Quaternion.fromScalars(1, 2, 3, 4)) quat = transform.getRotation() self.assertTrue(isinstance(quat, Quaternion)) self.assertEquals(quat.getX(), 0.18257419764995575) self.assertEquals(quat.getY(), 0.3651483952999115) self.assertEquals(quat.getZ(), 0.54772257804870605) self.assertEquals(quat.getW(), 0.73029673099517822)
def test_worldTransform(self): xform = Transform() xform.setOrigin(Vector3(3, 5, 7)) state = DefaultMotionState() state.setWorldTransform(xform) xform = state.getWorldTransform() origin = xform.getOrigin() self.assertEqual(origin.x, 3) self.assertEqual(origin.y, 5) self.assertEqual(origin.z, 7)
def test_fromConstructionInfo(self): mass = 8 motion = DefaultMotionState() shape = SphereShape(3) inertia = Vector3(1, 2, 3) transform = Transform() transform.setOrigin(Vector3(5, 6, 7)) linearDamping = 0.3 angularDamping = 0.4 friction = 4.5 restition = 5.4 linearSleepingThreshold = 4.3 angularSleepingThreshold = 3.2 body = RigidBody.fromConstructionInfo(motion, shape, mass, inertia, transform, linearDamping, angularDamping, friction, restition, linearSleepingThreshold, angularSleepingThreshold) self.assertTrue(isinstance(body, RigidBody)) self.assertEqual(1. / mass, body.getInvMass()) self.assertTrue(motion is body.getMotionState()) self.assertTrue(shape is body.getCollisionShape()) self.assertAlmostEqual(1. / inertia.x, body.getInvInertiaDiagLocal().x, 6) self.assertAlmostEqual(1. / inertia.y, body.getInvInertiaDiagLocal().y, 6) self.assertAlmostEqual(1. / inertia.z, body.getInvInertiaDiagLocal().z, 6) # The worldTransform is ignored if a MotionState is supplied. self.assertEqual(0, body.getWorldTransform().getOrigin().x) self.assertEqual(0, body.getWorldTransform().getOrigin().y) self.assertEqual(0, body.getWorldTransform().getOrigin().z) self.assertAlmostEqual(linearDamping, body.getLinearDamping(), 6) self.assertAlmostEqual(angularDamping, body.getAngularDamping(), 6) self.assertAlmostEqual(friction, body.getFriction(), 6) self.assertAlmostEqual(restition, body.getRestitution(), 6) self.assertAlmostEqual(linearSleepingThreshold, body.getLinearSleepingThreshold(), 6) self.assertAlmostEqual(angularSleepingThreshold, body.getAngularSleepingThreshold(), 6)
def test_fromConstructionInfo(self): mass = 8 motion = DefaultMotionState() shape = SphereShape(3) inertia = Vector3(1, 2, 3) transform = Transform() transform.setOrigin(Vector3(5, 6, 7)) linearDamping = 0.3 angularDamping = 0.4 friction = 4.5 restition = 5.4 linearSleepingThreshold = 4.3 angularSleepingThreshold = 3.2 body = RigidBody.fromConstructionInfo( motion, shape, mass, inertia, transform, linearDamping, angularDamping, friction, restition, linearSleepingThreshold, angularSleepingThreshold) self.assertTrue(isinstance(body, RigidBody)) self.assertEqual(1. / mass, body.getInvMass()) self.assertTrue(motion is body.getMotionState()) self.assertTrue(shape is body.getCollisionShape()) self.assertAlmostEqual( 1. / inertia.x, body.getInvInertiaDiagLocal().x, 6) self.assertAlmostEqual( 1. / inertia.y, body.getInvInertiaDiagLocal().y, 6) self.assertAlmostEqual( 1. / inertia.z, body.getInvInertiaDiagLocal().z, 6) # The worldTransform is ignored if a MotionState is supplied. self.assertEqual(0, body.getWorldTransform().getOrigin().x) self.assertEqual(0, body.getWorldTransform().getOrigin().y) self.assertEqual(0, body.getWorldTransform().getOrigin().z) self.assertAlmostEqual(linearDamping, body.getLinearDamping(), 6) self.assertAlmostEqual(angularDamping, body.getAngularDamping(), 6) self.assertAlmostEqual(friction, body.getFriction(), 6) self.assertAlmostEqual(restition, body.getRestitution(), 6) self.assertAlmostEqual( linearSleepingThreshold, body.getLinearSleepingThreshold(), 6) self.assertAlmostEqual( angularSleepingThreshold, body.getAngularSleepingThreshold(), 6)
def test_setIdentity(self): transform = Transform() transform.setOrigin(Vector3(2, 3, 4)) transform.setIdentity() origin = transform.getOrigin() self.assertEqual(origin.x, 0) self.assertEqual(origin.y, 0) self.assertEqual(origin.z, 0)
def objAt(pos): obj = RigidBody(None, BoxShape(Vector3(1, 1, 1)), 1.0) xform = Transform() xform.setOrigin(pos) obj.setWorldTransform(xform) return obj