Esempio n. 1
0
	def AdjustView(self, eyePosition, targetPosition, upVector):
		eye = Vector3(eyePosition)
		target = Vector3(targetPosition)
		up = Vector3(upVector)
		zaxis = vector.normalise(eye - target)    # The "forward" vector.
		xaxis = vector.normalise(vector3.cross(up, zaxis)) # The "right" vector.
		yaxis = vector3.cross(zaxis, xaxis)     # The "up" vector.

		# Create a 4x4 view matrix from the right, up, forward and eye position vectors
		self.view.r1 = [xaxis[0], yaxis[0], zaxis[0], 0]
		self.view.r2 = [xaxis[1], yaxis[1], zaxis[1], 0]
		self.view.r3 = [xaxis[2], yaxis[2], zaxis[2], 0]
		self.view.r4 =[-vector3.dot( xaxis, eye ), -vector3.dot( yaxis, eye ), -vector3.dot( zaxis, eye ),  1 ]

		return self.view
Esempio n. 2
0
    def test_operators_vector3(self):
        v1 = Vector3()
        v2 = Vector3([1.,2.,3.])

        # add
        self.assertTrue(np.array_equal(v1 + v2, [1.,2.,3.]))

        # subtract
        self.assertTrue(np.array_equal(v1 - v2, [-1.,-2.,-3.]))

        # multiply
        self.assertTrue(np.array_equal(v1 * v2, [0.,0.,0.]))

        # divide
        self.assertTrue(np.array_equal(v1 / v2, [0.,0.,0.]))

        # or
        self.assertTrue(np.array_equal(v1 | v2, vector3.dot(v1, v2)))

        # xor
        self.assertTrue(np.array_equal(v1 ^ v2, vector3.cross(v1, v2)))

        # ==
        self.assertTrue(Vector3() == Vector3())
        self.assertFalse(Vector3() == Vector3([1.,1.,1.]))

        # !=
        self.assertTrue(Vector3() != Vector3([1.,1.,1.]))
        self.assertFalse(Vector3() != Vector3())
Esempio n. 3
0
    def test_operators_vector3(self):
        v1 = Vector3()
        v2 = Vector3([1.,2.,3.])

        # add
        self.assertTrue(np.array_equal(v1 + v2, [1.,2.,3.]))

        # subtract
        self.assertTrue(np.array_equal(v1 - v2, [-1.,-2.,-3.]))

        # multiply
        self.assertTrue(np.array_equal(v1 * v2, [0.,0.,0.]))

        # divide
        self.assertTrue(np.array_equal(v1 / v2, [0.,0.,0.]))

        # or
        self.assertTrue(np.array_equal(v1 | v2, vector3.dot(v1, v2)))

        # xor
        self.assertTrue(np.array_equal(v1 ^ v2, vector3.cross(v1, v2)))

        # ==
        self.assertTrue(Vector3() == Vector3())
        self.assertFalse(Vector3() == Vector3([1.,1.,1.]))

        # !=
        self.assertTrue(Vector3() != Vector3([1.,1.,1.]))
        self.assertFalse(Vector3() != Vector3())
Esempio n. 4
0
    def test_bitwise(self):
        v1 = Vector3([1.,0.,0.])
        v2 = Vector3([0.,1.,0.])

        # xor (cross)
        self.assertTrue(np.array_equal(v1 ^ v2, vector3.cross(v1, v2)))

        # or (dot)
        self.assertTrue(np.array_equal(v1 | v2, vector3.dot(v1, v2)))
Esempio n. 5
0
    def test_bitwise(self):
        v1 = Vector3([1.,0.,0.])
        v2 = Vector3([0.,1.,0.])

        # xor (cross)
        self.assertTrue(np.array_equal(v1 ^ v2, vector3.cross(v1, v2)))

        # or (dot)
        self.assertTrue(np.array_equal(v1 | v2, vector3.dot(v1, v2)))
Esempio n. 6
0
 def test_dot_batch(self):
     result = vector3.dot([
         [1.,0.,0.],
         [0.,1.,0.],
         [.2,.2,0.]
     ],[
         [0.,1.,0.],
         [0.,1.,0.],
         [2.,-.2,0.]
     ])
     expected = [0.,1.,0.36]
     np.testing.assert_almost_equal(result, expected, decimal=5)
Esempio n. 7
0
 def test_dot_batch(self):
     result = vector3.dot([
         [1.,0.,0.],
         [0.,1.,0.],
         [.2,.2,0.]
     ],[
         [0.,1.,0.],
         [0.,1.,0.],
         [2.,-.2,0.]
     ])
     expected = [0.,1.,0.36]
     np.testing.assert_almost_equal(result, expected, decimal=5)
Esempio n. 8
0
 def test_dot_angle(self):
     result = vector3.dot([.2, .2, 0.], [2., -.2, 0.])
     np.testing.assert_almost_equal(result, 0.36, decimal=5)
Esempio n. 9
0
 def test_dot_parallel(self):
     result = vector3.dot([0., 1., 0.], [0., 1., 0.])
     np.testing.assert_almost_equal(result, 1.0, decimal=5)
Esempio n. 10
0
 def test_dot_adjacent(self):
     result = vector3.dot([1., 0., 0.], [0., 1., 0.])
     np.testing.assert_almost_equal(result, 0.0, decimal=5)
Esempio n. 11
0
 def test_dot_angle(self):
     result = vector3.dot([.2,.2,0.], [2.,-.2,0.])
     np.testing.assert_almost_equal(result, 0.36, decimal=5)
Esempio n. 12
0
 def test_dot_parallel(self):
     result = vector3.dot([0.,1.,0.], [0.,1.,0.])
     np.testing.assert_almost_equal(result, 1.0, decimal=5)
Esempio n. 13
0
 def test_dot_adjacent(self):
     result = vector3.dot([1.,0.,0.], [0.,1.,0.])
     np.testing.assert_almost_equal(result, 0.0, decimal=5)