def init_transform(self): """Initialize VM transforms.""" self.update_rotation() camera_matrix = lookat( self.camera_eye, self.camera_center, self.camera_up) GL.glUniformMatrix4fv( GL.glGetUniformLocation( self.program_manager.program_id, b"camera"), 1, GL.GL_TRUE, camera_matrix)
def draw(self, projection, view, model, color_shader, color): super().draw(projection, view, model, color_shader) # model, projection and view transform model = np.identity( 4 ) # translate(0.4, 0.7, 0) @ rotate(vec(1, 0, 0), 25) @ scale(0.7) view = lookat(np.array((0, 3, 3), 'f'), np.array((0, 0, 0), 'f'), np.array((0, 1, 0), 'f')) projection = perspective(45.0, 4 / 3, 0.1, 100.0) # transformation mvp = projection @ view @ model matrix_location = GL.glGetUniformLocation(color_shader.glid, 'matrix') GL.glUniformMatrix4fv(matrix_location, 1, True, mvp)
def __init__(self, position, fov, aspect, near, far): self.position = position self._ProjectionMatrix = perspective(fov, aspect, near, far) self._ViewMatrix = lookat(position, vec(0, 0, 0), vec(0, 1, 0)) self._ProjectionViewMatrix = self._ProjectionMatrix @ self._ViewMatrix
def LookAt(self, target): self._ViewMatrix = lookat(self.position, target, vec(0, 1, 0)) self._ProjectionViewMatrix = self._ProjectionMatrix @ self._ViewMatrix
def draw(self, projection, view, model): new_view = view if (self.is_follow): new_view = lookat(vec(-4, 20, 0), vec(-4, 1, 1), vec(0, 1, 0)) super().draw(projection, new_view, model)