def test_initial_state( unittest, node ): matrix = matrix44.identity() # # Axis # test_axis( unittest, node.transform.object, matrix ) test_axis( unittest, node.transform.inertial, matrix ) test_axis( unittest, node.world_transform.object, matrix ) test_axis( unittest, node.world_transform.inertial, matrix ) # # Quaternion # quat = quaternion.identity() unittest.assertTrue( numpy.allclose( node.transform.orientation, quat ), "Object quaternion incorrect" ) unittest.assertTrue( numpy.allclose( node.world_transform.orientation, quat ), "World quaternion incorrect" ) # # Scale # test_scale( unittest, node.transform, [1.0, 1.0, 1.0] ) test_scale( unittest, node.world_transform, [1.0, 1.0, 1.0] ) # # Translation # test_translation( unittest, node.transform, [0.0, 0.0, 0.0] ) test_translation( unittest, node.world_transform, [0.0, 0.0, 0.0] )
def test_translation_with_rotation( self ): root = SceneNode( '/root' ) child = SceneNode( '/child' ) root.add_child( child ) # # Rotate 180 deg (1 * pi) about the Y axis (yaw) # root.transform.object.rotate_y( math.pi ) identity = matrix44.identity() root_matrix = matrix44.create_from_y_rotation( math.pi ) # # Translate the child node # child.transform.translation = [1.0, 1.0, 1.0] test_translation( self, root.transform, [0.0, 0.0, 0.0] ) test_translation( self, root.world_transform, [0.0, 0.0, 0.0] ) test_translation( self, child.transform, [1.0, 1.0, 1.0] ) # Y does not invert test_translation( self, child.world_transform, [-1.0, 1.0,-1.0] )
def test_rotation( self ): """ Rotation and Inheritance """ # we'll add a child to a root node # we'll move the child # rotate the root # and check the child is where it should be # the child should be moved somewhere that will # make it easy to check root = SceneNode( '/root' ) child = SceneNode( '/child' ) root.add_child( child ) # # Rotate 180 deg (1 * pi) about the Y axis (yaw) # root.transform.object.rotate_y( math.pi ) identity = matrix44.identity() root_matrix = matrix44.create_from_y_rotation( math.pi ) # root object test_axis( self, root.transform.object, root_matrix ) test_axis( self, root.transform.inertial, identity ) test_axis( self, root.world_transform.object, root_matrix ) test_axis( self, root.world_transform.inertial, identity ) child_matrix = matrix44.identity() test_axis( self, child.transform.object, child_matrix ) test_axis( self, child.transform.inertial, identity ) test_axis( self, child.world_transform.object, root_matrix ) test_axis( self, child.world_transform.inertial, identity ) # check the node matrix matches what we're seeing in # the transform axis values self.assertTrue( numpy.allclose( root.transform.matrix, root_matrix ), "Root Local Matrix incorrect" ) self.assertTrue( numpy.allclose( root.world_transform.matrix, root_matrix ), "Root RootMatrix incorrect" ) self.assertTrue( numpy.allclose( child.transform.matrix, identity ), "Child Local Matrix incorrect" ) self.assertTrue( numpy.allclose( child.world_transform.matrix, root_matrix ), "Child RootMatrix incorrect" ) # # Rotate 180 deg (1 * pi) about the X axis (pitch) # # rotate 180 deg / 1pi about the x axis (pitch) child.transform.object.rotate_x( math.pi ) child_matrix = matrix44.multiply( matrix44.create_from_x_rotation( math.pi ), child_matrix ) child_world = matrix44.multiply( child_matrix, root_matrix ) # root object test_axis( self, root.transform.object, root_matrix ) test_axis( self, root.transform.inertial, identity ) test_axis( self, root.world_transform.object, root_matrix ) test_axis( self, root.world_transform.inertial, identity ) test_axis( self, child.transform.object, child_matrix ) test_axis( self, child.transform.inertial, identity ) test_axis( self, child.world_transform.object, child_world ) test_axis( self, child.world_transform.inertial, identity ) # check the node matrix matches what we're seeing in # the transform axis values self.assertTrue( numpy.allclose( root.transform.matrix, root_matrix ), "Root Local Matrix incorrect" ) self.assertTrue( numpy.allclose( root.world_transform.matrix, root_matrix ), "Root RootMatrix incorrect" ) self.assertTrue( numpy.allclose( child.transform.matrix, child_matrix ), "Child Local Matrix incorrect" ) self.assertTrue( numpy.allclose( child.world_transform.matrix, child_world ), "Child RootMatrix incorrect" )