Updated controls

This commit is contained in:
Thomas FORGIONE 2017-01-18 14:10:16 +01:00
parent 29ec3e1a3d
commit dc3889437d
No known key found for this signature in database
GPG Key ID: 2A210FFC062E00C3
1 changed files with 28 additions and 1 deletions

View File

@ -5,26 +5,43 @@ import OpenGL.GL as gl
import math import math
class Controls: class Controls:
"""Abstract class for controls
"""
def __init__(self): def __init__(self):
pass pass
def apply(self): def apply(self):
"""Apply the controls modification to the model view matrix
"""
pass pass
def update(self, time = 10): def update(self, time = 10):
"""Update according to the user's inputs
"""
pass pass
class TrackBallControls(Controls): class TrackBallControls(Controls):
"""Trackball controls
Simple trackball controls"""
def __init__(self): def __init__(self):
"""Creates a TrackBallControls
The trackball is centered at the origin
"""
super().__init__() super().__init__()
self.vertex = Vector() self.vertex = Vector()
self.theta = 0 self.theta = 0
def apply(self): def apply(self):
"""Apply the rotation of the current trackball
"""
gl.glRotatef(self.theta * 180 / math.pi, self.vertex.x, self.vertex.y, self.vertex.z) gl.glRotatef(self.theta * 180 / math.pi, self.vertex.x, self.vertex.y, self.vertex.z)
def update(self, time = 10): def update(self, time = 10):
"""Checks the keyboard inputs and update the angle
"""
if not pygame.mouse.get_pressed()[0]: if not pygame.mouse.get_pressed()[0]:
return return
@ -52,7 +69,13 @@ class TrackBallControls(Controls):
self.vertex.normalize() self.vertex.normalize()
class OrbitControls(Controls): class OrbitControls(Controls):
"""Simple OrbitControls
Similar to TrackBallControls but the up vector is preserved"""
def __init__(self): def __init__(self):
"""Creates an OrbitControls with null angles
"""
super().__init__() super().__init__()
self.phi = 0 self.phi = 0
self.theta = 0 self.theta = 0
@ -65,6 +88,10 @@ class OrbitControls(Controls):
gl.glRotatef(self.phi * 180 / math.pi, 0.0, 1.0, 0.0) gl.glRotatef(self.phi * 180 / math.pi, 0.0, 1.0, 0.0)
def apply_event(self, event): def apply_event(self, event):
"""Manages the wheel event
:param event: a pyevent
"""
if event.type == pygame.MOUSEBUTTONDOWN: if event.type == pygame.MOUSEBUTTONDOWN:
# Wheel up # Wheel up
if event.button == 4: if event.button == 4: