np.ascontiguousarray(ms.getCurrentMatrix(ms.MatrixStack.projection).T)) # note - opengl matricies use degrees ms.translate(ms.MatrixStack.view, 0.0, 0.0, -moving_camera_r) ms.rotate_x(ms.MatrixStack.view, moving_camera_rot_x) ms.rotate_y(ms.MatrixStack.view, -moving_camera_rot_y) glMatrixMode(GL_MODELVIEW) draw_ground() if animation_time < 5.0 or (animation_time > 40.0 and animation_time < 45.0): draw_axises() else: draw_axises(grayed_out=True) with ms.PushMatrix(ms.MatrixStack.model): if animation_time > 5.0: # draw paddle 1 ms.translate( ms.MatrixStack.model, paddle1.offset_x * min(1.0, (animation_time - 5.0) / 5.0), paddle1.offset_y * min(1.0, (animation_time - 5.0) / 5.0), 0.0) if animation_time > 10.0: ms.translate( ms.MatrixStack.model, paddle1.global_position[0] * min(1.0, (animation_time - 10.0) / 5.0), paddle1.global_position[1] * min(1.0, (animation_time - 10.0) / 5.0), 0.0) if (animation_time > 15.0):
def handle_inputs() -> None: global rotation_around_paddle1 if glfw.get_key(window, glfw.KEY_E) == glfw.PRESS: rotation_around_paddle1 += 0.1 global square_rotation if glfw.get_key(window, glfw.KEY_Q) == glfw.PRESS: square_rotation += 0.1 global camera move_multiple = 15.0 if glfw.get_key(window, glfw.KEY_RIGHT) == glfw.PRESS: camera.rot_y -= 0.03 if glfw.get_key(window, glfw.KEY_LEFT) == glfw.PRESS: camera.rot_y += 0.03 if glfw.get_key(window, glfw.KEY_PAGE_UP) == glfw.PRESS: camera.rot_x += 0.03 if glfw.get_key(window, glfw.KEY_PAGE_DOWN) == glfw.PRESS: camera.rot_x -= 0.03 # NEW -- reason about moving in 3D space just like placing # objects. If the up button is pressed if glfw.get_key(window, glfw.KEY_UP) == glfw.PRESS: # describe the vector to move forwards. # -1 unit in the z direction is forwards # # Although we have not covered linear algebra and # matrix multiplication in depth, all coordinates # in OpenGL are in 4D space, (x,y,z,w), # where to convert to NDC, use (x/w,y/w,z/w) # # For most purposes, by setting w to 1, we can # think in normal 3D space # forwards = np.array([0.0, 0.0, -1.0, 1.0]) # push matrix on the view stack, as we are going # to use the view matrix to determine the new position, # but then will reset the value of the view matrix with ms.PushMatrix(ms.MatrixStack.view): ms.translate(ms.MatrixStack.view, camera.x, camera.y, camera.z) ms.rotate_y(ms.MatrixStack.view, camera.rot_y) ms.scale(ms.MatrixStack.view, 5.0, 5.0, 5.0) camera.x, camera.y, camera.z, _ = ( ms.getCurrentMatrix(ms.MatrixStack.view) @ forwards) if glfw.get_key(window, glfw.KEY_DOWN) == glfw.PRESS: backwards = np.array([0.0, 0.0, 1.0, 1.0]) with ms.PushMatrix(ms.MatrixStack.view): ms.translate(ms.MatrixStack.view, camera.x, camera.y, camera.z) ms.rotate_y(ms.MatrixStack.view, camera.rot_y) ms.scale(ms.MatrixStack.view, 5.0, 5.0, 5.0) camera.x, camera.y, camera.z, _ = ( ms.getCurrentMatrix(ms.MatrixStack.view) @ backwards) global paddle1, paddle2 if glfw.get_key(window, glfw.KEY_S) == glfw.PRESS: paddle1.position[1] -= 10.0 if glfw.get_key(window, glfw.KEY_W) == glfw.PRESS: paddle1.position[1] += 10.0 if glfw.get_key(window, glfw.KEY_K) == glfw.PRESS: paddle2.position[1] -= 10.0 if glfw.get_key(window, glfw.KEY_I) == glfw.PRESS: paddle2.position[1] += 10.0 global paddle_1_rotation, paddle_2_rotation if glfw.get_key(window, glfw.KEY_A) == glfw.PRESS: paddle1.rotation += 0.1 if glfw.get_key(window, glfw.KEY_D) == glfw.PRESS: paddle1.rotation -= 0.1 if glfw.get_key(window, glfw.KEY_J) == glfw.PRESS: paddle2.rotation += 0.1 if glfw.get_key(window, glfw.KEY_L) == glfw.PRESS: paddle2.rotation -= 0.1