Beispiel #1
0
 def test_addCollisionObject(self):
     world = CollisionWorld()
     obj = CollisionObject()
     shape = SphereShape(3)
     obj.setCollisionShape(shape)
     world.addCollisionObject(obj)
     self.assertEqual(world.getNumCollisionObjects(), 1)
Beispiel #2
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)
Beispiel #3
0
 def test_setCollisionShape(self):
     obj = CollisionObject()
     # Let go of the shape reference, it shouldn't matter.
     obj.setCollisionShape(SphereShape(3))
     shape = obj.getCollisionShape()
     self.assertTrue(isinstance(shape, SphereShape))
     self.assertEquals(shape.getRadius(), 3)
Beispiel #4
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)
Beispiel #5
0
 def test_removeAction(self):
     world = DiscreteDynamicsWorld()
     action = KinematicCharacterController(SphereShape(1), 1.0, 1)
     world.addAction(action)
     world.removeAction(action)
Beispiel #6
0
 def test_instantiate(self):
     shape = SphereShape(3.0)
     self.assertTrue(isinstance(shape, CollisionShape))