def rotate(self, yaw_angle, pitch_angle): cam_focus_vector = Vec3d(self.eye.x - self.center.x, self.eye.y - self.center.y, self.eye.z - self.center.z, 1.0) ymat = Mat3d() pmat = Mat3d() ymat.define_rotation_matrix(yaw_angle, "y") pmat.define_rotation_matrix(pitch_angle, "x") ymat.matmul(pmat) cam_focus_vector = ymat.vecmul(cam_focus_vector) cam_focus_vector += self.center self.eye = cam_focus_vector.copy() self.compute_camera_space()
def get_matrix(self, points): m = [] for i in points: k = [i.x, i.y, i.z, i.w] m.append(k) return Mat3d(m).transpose()
def __init__(self): self.vertices = [] self.faces = [] self.subdivision_level = 0 self.original_vertices = [] self.transformation_matrix_stack = [] self.final_transformation_matrix = Mat3d()
def __init__(self): """Constructor of class """ self.vertices_list = Set([]) self.faces = [] self.subdivision_level = 0 self.transform_operations_stack = [] self.transform_matrix = Mat3d().transform_matrix
def rotate_y(self, Q): m = Mat3d([]) new_matrix = m.get_rotation_matrix_y_axis(Q).matrixMul(self.matrix) self.set_points(new_matrix) self.transformations.append(Transformations.Rotate_Y) self.transformation_matrix = m.get_rotation_matrix_y_axis(Q).matrixMul( self.transformation_matrix)
def translate(self, x, y, z): m = Mat3d([]) new_matrix = m.get_translation_matrix(x, y, z).matrixMul(self.matrix) self.set_points(new_matrix) self.transformations.append(Transformations.Translate) self.transformation_matrix = m.get_translation_matrix( x, y, z).matrixMul(self.transformation_matrix)
def scale(self, scalar): m = Mat3d([]) new_matrix = m.get_scale_matrix(scalar).matrixMul(self.matrix) self.set_points(new_matrix) self.transformations.append(Transformations.Scale) self.transformation_matrix = m.get_scale_matrix(scalar).matrixMul( self.transformation_matrix)
def construct_transform_matrix(self): """Constructs transformation matrix Arguments: shape {Shape} -- Shape to change mat {Mat3d} -- Matrix class related to given Shape """ self.transform_matrix = Mat3d().reset_transform_matrix() for i in range(len(self.transform_operations_stack)): self.transform_matrix = Mat3d.multiply_matrices_for_transform( self.transform_matrix, self.pop_from_stack())
def __init__(self, type, vertices, faces): self.type = type self.vertices = vertices self.faces = faces self.colors = [] self.create_colors() self.operation = Mat3d() self.wireOnShaded = False self.wireWidth = 2 self.wireOnShadedColor = HCoordinates(1.0, 1.0, 1.0, 1.0)
def __init__(self, vertices, faces): self._vertices = vertices self._faces = faces self._edges = [] self.create_edge_list() self._subdivision_history = [] self._subdivision_level = 0 self._size = 0 self._subdivider = None self.transformation_matrix_stack = [] self.final_transformation_matrix = Mat3d()
def __init__( self, points ): #points are vec3d(can be in homogeneus coordinates) objects in a list self.points = points self.matrix = self.get_matrix(points) self.center = self.get_center(points) mat = Mat3d([]) self.transformation_matrix = mat.get_scale_matrix(1) self.subdivision_level = 0 self.subdivisionMemory = [ ] #for going back and forth in subdivision level (caching the data) self.subdivisionMemory.append(points) self.meshMemory = [] #note that we are not forgeting the structure of original object, it stays in our array(the cache) self.vertexTable = [] self.faceTable = [] self.edgeTable = []
def rotate_point_y( self, Q, point): #rotates according to a point, and according to z axis. m = Mat3d([]) new_matrix = m.get_translation_matrix(-point.x, -point.y, -point.z).matrixMul(self.matrix) new_matrix = m.get_rotation_matrix_y_axis(Q).matrixMul(new_matrix) new_matrix = m.get_translation_matrix(point.x, point.y, point.z).matrixMul(new_matrix) self.set_points(new_matrix) self.transformations.append(Transformations.Translate) self.transformations.append(Transformations.Rotate_Z) self.transformations.append(Transformations.Translate) self.transformation_matrix = m.get_translation_matrix( -point.x, -point.y, -point.z).matrixMul(self.transformation_matrix) self.transformation_matrix = m.get_rotation_matrix_y_axis(Q).matrixMul( self.transformation_matrix) self.transformation_matrix = m.get_translation_matrix( point.x, point.y, point.z).matrixMul(self.transformation_matrix)
def InitGL(Width, Height): # We call this right after our OpenGL window is created. glClearColor(0.0, 0.0, 0.0, 0.0) # This Will Clear The Background Color To Black glClearDepth(1.0) # Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS) # The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST) # Enables Depth Testing glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading # Add vertices to the object triangle.add_vertex(Vec3d(0.0, 1.0, 0.0, 1.0)) triangle.add_vertex(Vec3d(1.0, -1.0, 0.0, 1.0)) triangle.add_vertex(Vec3d(-1.0, -1.0, 0.0, 1.0)) square.add_vertex(Vec3d(-1.0, 1.0, 0.0, 1.0)) square.add_vertex(Vec3d(1.0, 1.0, 0.0, 1.0)) square.add_vertex(Vec3d(1.0, -1.0, 0.0, 1.0)) square.add_vertex(Vec3d(-1.0, -1.0, 0.0, 1.0)) # Add transformation matrices to the object first_matrix = Mat3d() second_matrix = Mat3d() third_matrix = Mat3d() square.add_transformation(first_matrix.define_translation_matrix(-1, -1, 0)) # To rotate around one vertex, we perform transformation as TRT^-1 square.add_transformation(second_matrix.define_rotation_matrix(5, "z")) square.add_transformation(third_matrix.define_translation_matrix(1, 1, 0)) fourth_matrix = Mat3d() fifth_matrix = Mat3d() sixth_matrix = Mat3d() triangle.add_transformation(fourth_matrix.define_translation_matrix(1, 1, 0)) triangle.add_transformation(fifth_matrix.define_rotation_matrix(5, "z")) triangle.add_transformation(sixth_matrix.define_translation_matrix(-1, -1, 0)) glMatrixMode(GL_PROJECTION) glLoadIdentity() # Reset The Projection Matrix # Calculate The Aspect Ratio Of The Window gluPerspective(45.0, float(Width) / float(Height), 0.1, 100.0) glMatrixMode(GL_MODELVIEW)
def __init__(self): self.vertices = [] self.original_vertices = [] self.transformation_matrix_stack = [] self.final_transformation_matrix = Mat3d()
def main(): # Defines global elements to use global window global triangle_shape global square_shape global mat3d_triangle global mat3d_square global transform_matrix_triangle global transform_matrix_square triangle_shape = Shape() square_shape = Shape() mat3d_triangle = Mat3d() mat3d_square = Mat3d() # For now we just pass glutInit one empty argument. I wasn't sure what should or could be passed in (tuple, list, ...) # Once I find out the right stuff based on reading the PyOpenGL source, I'll address this. glutInit(sys.argv) # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) # get a 640 x 480 window glutInitWindowSize(640, 480) # the window starts at the upper left corner of the screen glutInitWindowPosition(0, 0) # Okay, like the C version we retain the window id to use when closing, but for those of you new # to Python (like myself), remember this assignment would make the variable local and not global # if it weren't for the global declaration at the start of main. window = glutCreateWindow("Jeff Molofee's GL Code Tutorial ... NeHe '99") # Register the drawing function with glut, BUT in Python land, at least using PyOpenGL, we need to # set the function pointer and invoke a function to actually register the callback, otherwise it # would be very much like the C version of the code. glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. # glutFullScreen() # When we are doing nothing, redraw the scene. glutIdleFunc(DrawGLScene) # Register the function called when our window is resized. glutReshapeFunc(ReSizeGLScene) # Register the function called when the keyboard is pressed. glutKeyboardFunc(keyPressed) # Initialize our window. InitGL(640, 480) # Below, we construct transformation matrices for each Shape transform_matrix_triangle = construct_transform_matrix(triangle_shape, mat3d_triangle) transform_matrix_square = construct_transform_matrix(square_shape, mat3d_square) # Start Event Processing Engine glutMainLoop()
def apply_transformation_matrix(self): m = Mat3d([]) new_matrix = self.transformation_matrix.matrixMul(self.matrix) self.set_points(new_matrix)
def __init__(self): """Consructor of class """ self.vertices_list = [] self.transform_operations_stack = [] self.transform_matrix = Mat3d().transform_matrix