From 7d3eea3c7edaa0048d9eebe77f2719d99ad04904 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Fri, 25 Nov 2016 15:41:52 +0100 Subject: [PATCH] Added OrbitControls --- d3/controls.py | 14 ++++++++++++++ viewer.py | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/d3/controls.py b/d3/controls.py index 60894e7..f0af6ba 100644 --- a/d3/controls.py +++ b/d3/controls.py @@ -59,3 +59,17 @@ class OrbitControls(Controls): self.phi = 0 self.theta = 0 + def apply(self): + gl.glRotatef(self.theta * 180 / math.pi, 1.0, 0.0, 0.0) + gl.glRotatef(self.phi * 180 / math.pi, 0.0, 1.0, 0.0) + + def update(self, time = 10): + + if not pygame.mouse.get_pressed()[0]: + return + + move = pygame.mouse.get_rel() + self.theta += move[1] * 0.01 + self.phi += move[0] * 0.01 + + self.theta = max(min(self.theta, math.pi / 2), -math.pi / 2) diff --git a/viewer.py b/viewer.py index eb3204e..837bda5 100755 --- a/viewer.py +++ b/viewer.py @@ -13,7 +13,7 @@ import OpenGL.GLU as glu from d3.model.tools import load_model from d3.geometry import Vector -from d3.controls import TrackBallControls +from d3.controls import TrackBallControls, OrbitControls from d3.camera import Camera from d3.shader import DefaultShader @@ -23,7 +23,7 @@ WINDOW_HEIGHT = 768 def main(args): camera = Camera(Vector(0,0,5), Vector(0,0,0)) - controls = TrackBallControls() + controls = OrbitControls() pg.init() display = (WINDOW_WIDTH, WINDOW_HEIGHT)