Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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())
Example #4
0
 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())
Example #5
0
 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))
Example #6
0
 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))
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
 def test_applyCentralImpulse(self):
     body = RigidBody(mass=1.0)
     body.applyCentralImpulse(Vector3(1, 2, 3))
     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.assertEqual(
         (rot.getX(), rot.getY(), rot.getZ(), rot.getW()), (0, 0, 0, 1))
Example #13
0
    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)
Example #14
0
 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))
Example #15
0
    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)
Example #16
0
    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)
Example #17
0
 def test_removeRigidBody(self):
     world = DiscreteDynamicsWorld()
     body = RigidBody()
     world.addRigidBody(body)
     world.removeRigidBody(body)
Example #18
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())
Example #19
0
 def test_setAngularFactor(self):
     body = RigidBody()
     body.setAngularFactor(1.0)
Example #20
0
 def objAt(pos):
     obj = RigidBody(None, BoxShape(Vector3(1, 1, 1)), 1.0)
     xform = Transform()
     xform.setOrigin(pos)
     obj.setWorldTransform(xform)
     return obj
Example #21
0
 def test_friction(self):
     body = RigidBody()
     body.setFriction(3.5)
     self.assertEqual(3.5, body.getFriction())
Example #22
0
 def test_friction(self):
     body = RigidBody()
     body.setFriction(3.5)
     self.assertEqual(3.5, body.getFriction())
Example #23
0
 def objAt(pos):
     obj = RigidBody(None, BoxShape(Vector3(1, 1, 1)), 1.0)
     xform = Transform()
     xform.setOrigin(pos)
     obj.setWorldTransform(xform)
     return obj
Example #24
0
 def test_setAngularFactor(self):
     body = RigidBody()
     body.setAngularFactor(1.0)
Example #25
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())