Added OrbitControls

This commit is contained in:
Thomas FORGIONE 2016-11-25 15:41:52 +01:00
parent fcac434881
commit 7d3eea3c7e
2 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -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)