Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
    def test_getAxisAndAngle(self):
        """
        A L{Quaternion} represents a rotation around an axis.
        L{Quaternion.getAngle} returns the rotation in radians,
        L{Quaternion.getAxis} returns the axis as a L{Vector3}.
        """
        quat = Quaternion.fromScalars(0, 0, 0, 1)
        axis = quat.getAxis()
        self.assertEqual(axis.x, 1)
        self.assertEqual(axis.y, 0)
        self.assertEqual(axis.z, 0)
        self.assertEqual(quat.getAngle(), 0)

        quat = Quaternion.fromScalars(0, 0, 1, 0)
        axis = quat.getAxis()
        self.assertEqual(axis.x, 0)
        self.assertEqual(axis.y, 0)
        self.assertEqual(axis.z, 1)
        self.assertAlmostEqual(quat.getAngle(), pi, 6)
Exemple #4
0
    def test_getAxisAndAngle(self):
        """
        A L{Quaternion} represents a rotation around an axis.
        L{Quaternion.getAngle} returns the rotation in radians,
        L{Quaternion.getAxis} returns the axis as a L{Vector3}.
        """
        quat = Quaternion.fromScalars(0, 0, 0, 1)
        axis = quat.getAxis()
        self.assertEqual(axis.x, 1)
        self.assertEqual(axis.y, 0)
        self.assertEqual(axis.z, 0)
        self.assertEqual(quat.getAngle(), 0)

        quat = Quaternion.fromScalars(0, 0, 1, 0)
        axis = quat.getAxis()
        self.assertEqual(axis.x, 0)
        self.assertEqual(axis.y, 0)
        self.assertEqual(axis.z, 1)
        self.assertAlmostEqual(quat.getAngle(), pi, 6)
Exemple #5
0
 def test_fromScalars(self):
     """
     A L{Quaternion} can be constructed from four scalar values giving x, y,
     z, and w.
     """
     quat = Quaternion.fromScalars(1, 2, 3, 4)
     self.assertTrue(isinstance(quat, Quaternion))
     self.assertEquals(quat.getX(), 1)
     self.assertEquals(quat.getY(), 2)
     self.assertEquals(quat.getZ(), 3)
     self.assertEquals(quat.getW(), 4)
Exemple #6
0
 def test_fromScalars(self):
     """
     A L{Quaternion} can be constructed from four scalar values giving x, y,
     z, and w.
     """
     quat = Quaternion.fromScalars(1, 2, 3, 4)
     self.assertTrue(isinstance(quat, Quaternion))
     self.assertEquals(quat.getX(), 1)
     self.assertEquals(quat.getY(), 2)
     self.assertEquals(quat.getZ(), 3)
     self.assertEquals(quat.getW(), 4)
Exemple #7
0
 def test_unrelatedMultiplication(self):
     """
     Multiplying a L{Quaternion} but another type results in a L{TypeError}.
     """
     self.assertRaises(TypeError, mul, Quaternion.fromScalars(0, 0, 0, 1),
                       "foo")
Exemple #8
0
 def test_unrelatedMultiplication(self):
     """
     Multiplying a L{Quaternion} but another type results in a L{TypeError}.
     """
     self.assertRaises(
         TypeError, mul, Quaternion.fromScalars(0, 0, 0, 1), "foo")