示例#1
0
 def test_create_direction_scale(self):
     m = matrix33.create_direction_scale([0., 1., 0.], 0.5)
     v = np.array([[1., 0., 0.], [1., 1., 1.], [10., 10., 10.]])
     result = np.array([
         matrix33.apply_to_vector(m, v[0]),
         matrix33.apply_to_vector(m, v[1]),
         matrix33.apply_to_vector(m, v[2]),
     ])
     expected = np.array([[1., 0., 0.], [1., .5, 1.], [10., 5., 10.]])
     self.assertTrue(np.allclose(result, expected))
示例#2
0
 def test_create_direction_scale(self):
     m = matrix33.create_direction_scale([0.,1.,0.], 0.5)
     v = np.array([
         [1.,0.,0.],
         [1.,1.,1.],
         [10.,10.,10.]
     ])
     result = np.array([
         matrix33.apply_to_vector(m, v[0]),
         matrix33.apply_to_vector(m, v[1]),
         matrix33.apply_to_vector(m, v[2]),
     ])
     expected = np.array([
         [1.,0.,0.],
         [1.,.5,1.],
         [10.,5.,10.]
     ])
     self.assertTrue(np.allclose(result, expected))
示例#3
0
    def translate_backward(self, amount):
        """Translates the object backward along the inertial X,Z
        plane.
        """
        quat = quaternion.set_to_rotation_about_y(self.yaw)

        matrix = matrix33.create_from_quaternion(quat)
        vec = matrix33.apply_to_vector([0.0, 0.0, 1.0], matrix)
        vec *= amount
        self.transform.inertial.translate(vec)
示例#4
0
        def identity():
            mat = matrix33.create_identity()
            vec = vector3.unit.x

            result = matrix33.apply_to_vector( mat, vec )

            expected = vec

            self.assertTrue(
                numpy.array_equal( result, expected ),
                "Matrix33 apply_to_vector incorrect with identity"
                )
示例#5
0
        def rotated_z():
            mat = matrix33.create_from_z_rotation( math.pi )
            vec = vector3.unit.x

            result = matrix33.apply_to_vector( mat, vec )

            expected = -vec

            self.assertTrue(
                numpy.allclose( result, expected ),
                "Matrix33 apply_to_vector incorrect with rotation about Y"
                )
    def translate_forward( self, amount ):
        """Translates the object forward along the inertial X,Z
        plane.
        """
        quat = quaternion.set_to_rotation_about_y( self.yaw )

        matrix = matrix33.create_from_quaternion( quat )
        vec = matrix33.apply_to_vector(
            [0.0, 0.0,-1.0],
            matrix
            )
        vec *= amount
        self.transform.inertial.translate( vec )
示例#7
0
    def y(self):
        """Returns the object's local Y axis.

        This is the Y axis rotated by the objects orientation.

        .. note::
            This is NOT the world orientation.
            To get inertial Y axis, simply use [0.0, 1.0, 0.0].
        """
        # convert our quaternion to a matrix
        matrix = matrix33.create_from_quaternion(self.transform.orientation)
        # apply the matrix to a Y vector
        return matrix33.apply_to_vector(matrix, vector3.unit.y)
示例#8
0
    def test_operators_vector3(self):
        m = Matrix33.identity()
        v = Vector3([1,1,1])

        # add
        self.assertRaises(ValueError, lambda: m + v)

        # subtract
        self.assertRaises(ValueError, lambda: m - v)

        # multiply
        self.assertTrue(np.array_equal(m * v, matrix33.apply_to_vector(matrix33.create_identity(), [1,1,1])))

        # divide
        self.assertRaises(ValueError, lambda: m / v)
示例#9
0
    def test_operators_vector3(self):
        m = Matrix33.identity()
        v = Vector3([1,1,1])
        
        # add
        self.assertRaises(ValueError, lambda: m + v)

        # subtract
        self.assertRaises(ValueError, lambda: m - v)

        # multiply
        self.assertTrue(np.array_equal(m * v, matrix33.apply_to_vector(matrix33.create_identity(), [1,1,1])))

        # divide
        self.assertRaises(ValueError, lambda: m / v)
示例#10
0
    def translate(self, vector):
        """Translates the transform locally.

        The vector will have the node's current orientation
        applied to it and then be added to the translation.
        """
        if numpy.array_equal(vector, [0.0, 0.0, 0.0]):
            # don't bother to update anything
            return

        # multiply the vector by our local orientation
        # convert our quaternion to a matrix
        matrix = matrix33.create_from_quaternion(self.transform._orientation)
        # apply the matrix to the specified vector
        self.transform.translation += matrix33.apply_to_vector(
            matrix, numpy.array(vector))
示例#11
0
    def y( self ):
        """Returns the object's local Y axis.

        This is the Y axis rotated by the objects orientation.

        .. note::
            This is NOT the world orientation.
            To get inertial Y axis, simply use [0.0, 1.0, 0.0].
        """
        # convert our quaternion to a matrix
        matrix = matrix33.create_from_quaternion(
            self.transform.orientation
            )
        # apply the matrix to a Y vector
        return matrix33.apply_to_vector(
            matrix,
            vector3.unit.y
            )
示例#12
0
    def _set_velocity_for_speed_and_direction(self, speed: float, direction: float):
        # get the heading
        dx = self.model.target_x - self.model.ball.x
        dy = self.model.target_y - self.model.ball.y

        # direction is meaningless if we're already at the target
        if (dx != 0) or (dy != 0):

            # set the magnitude
            vel = vector.set_length([dx, dy, 0.0], speed)

            # rotate by direction around Z-axis at ball position
            rot = matrix33.create_from_axis_rotation([0.0, 0.0, 1.0], direction)
            vel = matrix33.apply_to_vector(rot, vel)

            # unpack into ball velocity
            self.model.ball_vel.x = vel[0]
            self.model.ball_vel.y = vel[1]
            self.model.ball_vel.z = vel[2]
示例#13
0
    def translate( self, vector ):
        """Translates the transform locally.

        The vector will have the node's current orientation
        applied to it and then be added to the translation.
        """
        if numpy.array_equal( vector, [ 0.0, 0.0, 0.0 ] ):
            # don't bother to update anything
            return

        # multiply the vector by our local orientation
        # convert our quaternion to a matrix
        matrix = matrix33.create_from_quaternion(
            self.transform._orientation
            )
        # apply the matrix to the specified vector
        self.transform.translation += matrix33.apply_to_vector(
            matrix,
            numpy.array( vector )
            )
示例#14
0
 def test_apply_to_vector_rotated_z(self):
     mat = matrix33.create_from_z_rotation(np.pi)
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = -vec
     self.assertTrue(np.allclose(result, expected))
示例#15
0
 def test_apply_to_vector_rotated_z(self):
     mat = matrix33.create_from_z_rotation(np.pi)
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = -vec
     self.assertTrue(np.allclose(result, expected))
示例#16
0
 def test_apply_to_vector_identity(self):
     mat = matrix33.create_identity()
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = vec
     self.assertTrue(np.array_equal(result, expected))
示例#17
0
 def test_apply_to_vector_identity(self):
     mat = matrix33.create_identity()
     vec = vector3.unit.x
     result = matrix33.apply_to_vector(mat, vec)
     expected = vec
     self.assertTrue(np.array_equal(result, expected))