def draw_axises(grayed_out=False): with ms.push_matrix(ms.MatrixStack.model): ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) # x axis with ms.push_matrix(ms.MatrixStack.model): ms.rotate_z(ms.MatrixStack.model, math.radians(-90.0)) glColor3f(1.0, 0.0, 0.0) if grayed_out: glColor3f(0.5, 0.5, 0.5) draw_y_axis() # z glColor3f(0.0, 0.0, 1.0) # blue z with ms.push_matrix(ms.MatrixStack.model): ms.rotate_y(ms.MatrixStack.model, math.radians(90.0)) ms.rotate_z(ms.MatrixStack.model, math.radians(90.0)) glColor3f(0.0, 0.0, 1.0) if grayed_out: glColor3f(0.5, 0.5, 0.5) draw_y_axis() # y glColor3f(0.0, 1.0, 0.0) # green y if grayed_out: glColor3f(0.5, 0.5, 0.5) draw_y_axis()
def render(self): with ms.push_matrix(ms.MatrixStack.model): # rotate the triangle along the positive z axis ms.translate(ms.MatrixStack.model, math.sin(glfw.get_time()), 0, 0) ms.rotateZ(ms.MatrixStack.model, glfw.get_time()) gl.glUseProgram(self.shader) gl.glBindVertexArray(self.vao) gl.glUniformMatrix4fv( self.mvpMatrixLoc, 1, gl.GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix( ms.MatrixStack.modelviewprojection), dtype=np.float32)) gl.glDrawArrays(gl.GL_TRIANGLES, 0, self.numberOfVertices) gl.glBindVertexArray(0)
camera.z -= 10.0 * axes_list[0][0] * math.sin(camera.rot_y) if math.fabs(float(axes_list[0][1])) > 0.19: camera.x += 10.0 * axes_list[0][1] * math.sin(camera.rot_y) camera.z += 10.0 * axes_list[0][1] * math.cos(camera.rot_y) if math.fabs(axes_list[0][3]) > 0.19: camera.rot_y -= 3.0 * axes_list[0][3] * 0.01 if math.fabs(axes_list[0][4]) > 0.19: camera.rot_x += axes_list[0][4] * 0.01 # note - opengl matricies use degrees ms.rotate_x(ms.MatrixStack.view, -camera.rot_x) ms.rotate_y(ms.MatrixStack.view, -camera.rot_y) ms.translate(ms.MatrixStack.view, -camera.x, -camera.y, -camera.z) with ms.push_matrix(ms.MatrixStack.model): # draw paddle 1 # Unlike in previous demos, because the transformations # are on a stack, the fns on the model stack can # be read forwards, where each operation translates/rotates/scales # the current space ms.translate( ms.MatrixStack.model, paddle1.position[0], paddle1.position[1], 0.0, ) ms.rotate_z(ms.MatrixStack.model, paddle1.rotation) paddle1.render() with ms.push_matrix(ms.MatrixStack.model):
def render(self, time, grayed_out=False): glDisable(GL_DEPTH_TEST) glUseProgram(self.shader) glBindVertexArray(self.vao) # pass projection parameters to the shader fov_loc = glGetUniformLocation(self.shader, "fov") glUniform1f(fov_loc, 45.0) aspect_loc = glGetUniformLocation(self.shader, "aspectRatio") glUniform1f(aspect_loc, 1.0) nearZ_loc = glGetUniformLocation(self.shader, "nearZ") glUniform1f(nearZ_loc, -5.0) farZ_loc = glGetUniformLocation(self.shader, "farZ") glUniform1f(farZ_loc, -150.00) # TODO, set the color with ms.push_matrix(ms.MatrixStack.model): # x axis with ms.push_matrix(ms.MatrixStack.model): ms.rotate_z(ms.MatrixStack.model, math.radians(-90.0)) if enlarged_axis: ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) glUniform3f(self.colorLoc, 1.0, 0.0, 0.0) if grayed_out: glUniform3f(self.colorLoc, 0.5, 0.5, 0.5) # ascontiguousarray puts the array in column major order glUniformMatrix4fv( self.mMatrixLoc, 1, GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix( ms.MatrixStack.model), dtype=np.float32), ) glUniformMatrix4fv( self.vMatrixLoc, 1, GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix( ms.MatrixStack.view), dtype=np.float32), ) glUniformMatrix4fv( self.pMatrixLoc, 1, GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix( ms.MatrixStack.projection), dtype=np.float32), ) glDrawArrays(GL_LINES, 0, self.numberOfVertices) # y if enlarged_axis: ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) glUniform3f(self.colorLoc, 0.0, 1.0, 0.0) # glColor3f(0.0,1.0,0.0) # green y if grayed_out: glUniform3f(self.colorLoc, 0.5, 0.5, 0.5) # ascontiguousarray puts the array in column major order glUniformMatrix4fv( self.mMatrixLoc, 1, GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32), ) glUniformMatrix4fv( self.vMatrixLoc, 1, GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32), ) glUniformMatrix4fv( self.pMatrixLoc, 1, GL_TRUE, np.ascontiguousarray(ms.getCurrentMatrix( ms.MatrixStack.projection), dtype=np.float32), ) glDrawArrays(GL_LINES, 0, self.numberOfVertices) glBindVertexArray(0) glEnable(GL_DEPTH_TEST)
def render(self, time, grayed_out=False): glDisable(GL_DEPTH_TEST) glUseProgram(self.shader) glBindVertexArray(self.vao) with ms.push_matrix(ms.MatrixStack.model): # x axis with ms.push_matrix(ms.MatrixStack.model): ms.rotate_z(ms.MatrixStack.model, math.radians(-90.0)) if enlarged_axis: ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) glUniform3f(self.colorLoc, 1.0, 0.0, 0.0) if grayed_out: glUniform3f(self.colorLoc, 0.5, 0.5, 0.5) # ascontiguousarray puts the array in column major order glUniformMatrix4fv( self.mMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32 ), ) glUniformMatrix4fv( self.vMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32 ), ) glUniformMatrix4fv( self.pMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.projection), dtype=np.float32 ), ) glDrawArrays(GL_LINES, 0, self.numberOfVertices) # z # glColor3f(0.0,0.0,1.0) # blue z with ms.push_matrix(ms.MatrixStack.model): ms.rotate_y(ms.MatrixStack.model, math.radians(90.0)) ms.rotate_z(ms.MatrixStack.model, math.radians(90.0)) if enlarged_axis: ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) glUniform3f(self.colorLoc, 0.0, 0.0, 1.0) if grayed_out: glUniform3f(self.colorLoc, 0.5, 0.5, 0.5) # ascontiguousarray puts the array in column major order glUniformMatrix4fv( self.mMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32 ), ) glUniformMatrix4fv( self.vMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32 ), ) glUniformMatrix4fv( self.pMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.projection), dtype=np.float32 ), ) if enlarged_axis: ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) glDrawArrays(GL_LINES, 0, self.numberOfVertices) # y if enlarged_axis: ms.scale(ms.MatrixStack.model, 10.0, 10.0, 10.0) glUniform3f(self.colorLoc, 0.0, 1.0, 0.0) # glColor3f(0.0,1.0,0.0) # green y if grayed_out: glUniform3f(self.colorLoc, 0.5, 0.5, 0.5) # ascontiguousarray puts the array in column major order glUniformMatrix4fv( self.mMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.model), dtype=np.float32 ), ) glUniformMatrix4fv( self.vMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.view), dtype=np.float32 ), ) glUniformMatrix4fv( self.pMatrixLoc, 1, GL_TRUE, np.ascontiguousarray( ms.getCurrentMatrix(ms.MatrixStack.projection), dtype=np.float32 ), ) glDrawArrays(GL_LINES, 0, self.numberOfVertices) glBindVertexArray(0) glEnable(GL_DEPTH_TEST)