Update model.py example to work again with Model module changes.
import math
+from math import radians
+
import pyglet
from pyglet.gl import glEnable, GL_DEPTH_TEST, GL_CULL_FACE
+from pyglet.math import Mat4, Vec3
window = pyglet.window.Window(width=720, height=480)
@@ -23,24 +26,29 @@ def on_draw():
@window.event
def on_mouse_drag(x, y, dx, dy, buttons, modifiers):
- rot = model.rotation
- model.rotation = rot[0], rot[1] + dx / 12, rot[2] - dy / 9
- rot = model2.rotation
- model2.rotation = rot[0], rot[1] + dx / 15, rot[2] - dy / 17
+ matrix = model.matrix
+ model.matrix = matrix.rotate(0.01, Vec3(dx, dy, 0).normalize())
+
+ matrix = model2.matrix
+ model2.matrix = matrix.rotate(0.01, Vec3(-dx, -dy, 0).normalize())
def animate(dt):
global time
time += dt
- rot = model.rotation
- model.rotation = rot[0], rot[1] + dt * 27, rot[2] + dt * 35
- model.translation = -1.5, 0, math.sin(time) * 0.7 - 4.0
+ matrix = model.matrix
+ matrix = matrix.rotate(dt/2, Vec3(0, 0, 1))
+ matrix = matrix.rotate(dt/2, Vec3(0, 1, 0))
+ matrix = matrix.rotate(dt/2, Vec3(1, 0, 0))
+ model.matrix = matrix
- rot = model2.rotation
- model2.rotation = rot[0], rot[1] + dt * 20, rot[2] + dt * 45
- model2.translation = 1.5, 0, math.sin(-time) * 0.7 - 5.0
+ matrix = model2.matrix
+ matrix = matrix.rotate(dt*2, Vec3(0, 0, 1))
+ matrix = matrix.rotate(dt*2, Vec3(0, 1, 0))
+ matrix = matrix.rotate(dt*2, Vec3(1, 0, 0))
+ model2.matrix = matrix
if __name__ == "__main__":
@@ -48,9 +56,13 @@ if __name__ == "__main__":
glEnable(GL_CULL_FACE)
model = pyglet.resource.model("logo3d.obj", batch=batch)
- model.translation = 0, 0, -2.2
+ model.matrix = Mat4.from_translation(Vec3(3, 0, 0))
+
model2 = pyglet.resource.model("box.obj", batch=batch)
- model2.translation = 0, 0, -2.2
+ model2.matrix = Mat4.from_translation(Vec3(-3, 0, 0))
+
+ # Set the application wide view matrix to "zoom out":
+ window.view = Mat4.from_translation(Vec3(0, 0, -5))
pyglet.clock.schedule_interval(animate, 1/60)
pyglet.app.run()
