예제 #1
0
def calculate_view_matrix(position, rotation):
    """TReturns 4x4 view matrix from the (x.y,z) position and XYZ Euler rotation, in degrees."""
    # Set View Matrix

    trans_mat = transformations.translation_matrix((-position[0], -position[1], -position[2]))

    rotation = tuple(-np.radians(coord) for coord in rotation)
    rot_mat = transformations.euler_matrix(rotation[0], rotation[1], rotation[2], 'rxyz')

    return np.dot(rot_mat, trans_mat)
예제 #2
0
def calculate_model_matrix(position, rotation, scale):
    """Returns 4x4 model matrix from the (x.y,z) position and XYZ Euler rotation, in degrees."""

    # Set Model and Normal Matrices
    trans_mat = transformations.translation_matrix(position)

    rotation = tuple(np.radians(coord) for coord in rotation)
    rot_mat = transformations.euler_matrix(rotation[0], rotation[1], rotation[2])
    scale_mat = transformations.scale_matrix(scale)

    return np.dot(np.dot(trans_mat, rot_mat), scale_mat)
예제 #3
0
파일: main.py 프로젝트: GNHua/learn-stuff
 def draw(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     with self.shaderProg, bindVAO(self.VAO), \
       bindTexture(GL_TEXTURE0, GL_TEXTURE_2D, self.texture1), \
       bindTexture(GL_TEXTURE1, GL_TEXTURE_2D, self.texture2):
         glUniform1i(glGetUniformLocation(self.shaderProg, 'ourTexture1'), 0)
         glUniform1i(glGetUniformLocation(self.shaderProg, 'ourTexture2'), 1)
         
         view = translation_matrix([0, 0, -0.5]).T
         projection = perspective_matrix(np.radians(45), WIDTH/HEIGHT, 0.1, 100).T
         viewLoc = glGetUniformLocation(self.shaderProg, 'view')
         glUniformMatrix4fv(viewLoc, 1, GL_FALSE, view)
         projectionLoc = glGetUniformLocation(self.shaderProg, 'projection')
         glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, projection)
         
         modelLoc = glGetUniformLocation(self.shaderProg, 'model')
         for i in range(10):
             model = translation_matrix(self.cubePositions[i]).T
             angle = 20 * i
             model = rotation_matrix(angle, [1, 0.3, 0.5]).T @ model
             glUniformMatrix4fv(modelLoc, 1, GL_FALSE, model)
             glDrawArrays(GL_TRIANGLES, 0, 36)
     glfw.swap_buffers(self.window)
예제 #4
0
 def to_matrix(self):
     return trans.translation_matrix(self._array)