def test_double_translation(self): m0 = Matrix4.translate(1, 2, 3) m1 = Matrix4.translate(4, 5, 6) mm = m0 * m1 self.assertEqual(mm.m[12], 5) self.assertEqual(mm.m[13], 7) self.assertEqual(mm.m[14], 9) self.assertEqual(mm.m[15], 1)
xrot = 0 while window.is_opened: if window.get_key(KEY_RIGHT): yrot += 60 * window.delta_time if window.get_key(KEY_LEFT): yrot -= 60 * window.delta_time if window.get_key(KEY_UP): xrot += 60 * window.delta_time if window.get_key(KEY_DOWN): xrot -= 60 * window.delta_time glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #glClear(GL_COLOR_BUFFER_BIT) mat = Matrix4.translate(0, 0, -5) * Matrix4.rotate_x(xrot) * Matrix4.rotate_y(yrot) * Matrix4.scale(1, 1, 1) cam = Matrix4.perspective(60, window.aspect_ratio, 0.1, 100) * Matrix4.look_at(0, 0, 5, 0, 0, 0, 0, 1, 0) glUniformMatrix4fv(world, 1, GL_FALSE, mat.m) glUniformMatrix4fv(camera, 1, GL_FALSE, cam.m) # the draw call glDrawArrays(GL_TRIANGLES, 0, 6 * 6) window.update()
yrot = 0 zoom = 4 while window.is_opened: if window.get_key(KEY_RIGHT): yrot += 60 * window.delta_time if window.get_key(KEY_LEFT): yrot -= 60 * window.delta_time if window.get_key(KEY_UP): zoom -= 0.5 * window.delta_time if window.get_key(KEY_DOWN): zoom += 0.5 * window.delta_time glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #mat = Matrix4.scale(1, 1, 1) * Matrix4.rotate_y(yrot) * Matrix4.rotate_x(xrot) * Matrix4.translate(0, 0, -5) mat = Matrix4.translate(0, -1, -2) * Matrix4.rotate_y(yrot) * Matrix4.scale(1, 1, 1) cam = Matrix4.perspective(60, 800.0/600.0, 0.1, 100) * Matrix4.look_at(0, 1, zoom, 0, 0, 0, 0, 1, 0) glUniformMatrix4fv(world, 1, GL_FALSE, mat.m) glUniformMatrix4fv(camera, 1, GL_FALSE, cam.m) glDrawArrays(GL_TRIANGLES, 0, len(obj.vertices) // 3) window.update()
zoom = 4 while window.is_opened: if window.get_key(KEY_RIGHT): yrot += 60 * window.delta_time if window.get_key(KEY_LEFT): yrot -= 60 * window.delta_time if window.get_key(KEY_UP): zoom -= 0.5 * window.delta_time if window.get_key(KEY_DOWN): zoom += 0.5 * window.delta_time glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #mat = Matrix4.scale(1, 1, 1) * Matrix4.rotate_y(yrot) * Matrix4.rotate_x(xrot) * Matrix4.translate(0, 0, -5) mat = Matrix4.translate( 0, -1, -2) * Matrix4.rotate_y(yrot) * Matrix4.scale(1, 1, 1) cam = Matrix4.perspective(60, 800.0 / 600.0, 0.1, 100) * Matrix4.look_at( 0, 1, zoom, 0, 0, 0, 0, 1, 0) glUniformMatrix4fv(world, 1, GL_FALSE, mat.m) glUniformMatrix4fv(camera, 1, GL_FALSE, cam.m) glDrawArrays(GL_TRIANGLES, 0, len(obj.vertices) // 3) window.update()
xrot = 0 while window.is_opened: if window.get_key(KEY_RIGHT): yrot += 60 * window.delta_time if window.get_key(KEY_LEFT): yrot -= 60 * window.delta_time if window.get_key(KEY_UP): xrot += 60 * window.delta_time if window.get_key(KEY_DOWN): xrot -= 60 * window.delta_time glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #mat = Matrix4.scale(1, 1, 1) * Matrix4.rotate_y(yrot) * Matrix4.rotate_x(xrot) * Matrix4.translate(0, 0, -5) mat = Matrix4.translate(0, 0, -5) * Matrix4.rotate_x( xrot) * Matrix4.rotate_y(yrot) * Matrix4.scale(1, 1, 1) cam = Matrix4.perspective(60, 800.0 / 600.0, 0.1, 100) * Matrix4.look_at( 0, 0, 5, 0, 0, 0, 0, 1, 0) glUniformMatrix4fv(world, 1, GL_FALSE, mat.m) glUniformMatrix4fv(camera, 1, GL_FALSE, cam.m) glDrawArrays(GL_TRIANGLES, 0, 6 * 6) window.update()
zoom = 4 while window.is_opened: if window.get_key(KEY_RIGHT): yrot += 60 * window.delta_time if window.get_key(KEY_LEFT): yrot -= 60 * window.delta_time if window.get_key(KEY_UP): zoom -= 0.5 * window.delta_time if window.get_key(KEY_DOWN): zoom += 0.5 * window.delta_time glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) mat = Matrix4.translate( 0, -1, -2) * Matrix4.rotate_y(yrot) * Matrix4.scale(1, 1, 1) cam = Matrix4.perspective(60, window.aspect_ratio, 0.1, 100) * Matrix4.look_at( 0, 1, zoom, 0, 0, 0, 0, 1, 0) glUniformMatrix4fv(world, 1, GL_FALSE, mat.m) glUniformMatrix4fv(camera, 1, GL_FALSE, cam.m) glDrawArrays(GL_TRIANGLES, 0, len(obj.vertices) // 3) window.update()