Added class Camera

This commit is contained in:
Thomas FORGIONE 2016-11-25 11:53:35 +01:00
parent 8e19606310
commit ddb5f4b3d3
4 changed files with 32 additions and 9 deletions

0
d3/cameras/__init__.py Normal file
View File

19
d3/cameras/camera.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
from ..conv.model import Vertex
from OpenGL.GL import *
from OpenGL.GLU import *
class Camera:
def __init__(self, position = None, target = None, up = None):
self.position = Vertex() if position is None else position
self.target = Vertex() if target is None else target
self.up = Vertex(0.0,1.0,0.0) if up is None else target
def look(self):
gluLookAt(
self.position.x, self.position.y, self.position.z,
self.target.x, self.target.y, self.target.z,
self.up.x, self.up.y, self.up.z)

View File

@ -57,4 +57,9 @@ class TrackBallControls(Controls):
self.vertex = A
self.vertex.normalize()
class OrbitControls(Controls):
def __init__(self):
super().__init__()
self.phi = 0
self.theta = 0

View File

@ -16,6 +16,7 @@ from OpenGL.GLUT import *
from d3.conv.loadmodel import load_model
from d3.conv.model import Vertex
from d3.controls.controls import TrackBallControls
from d3.cameras.camera import Camera
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 768
@ -25,15 +26,9 @@ y = 0.5
width = 1
height = 1
def init_frame():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0,0,5,0,0,0,0,1,0)
def main(args):
camera = Camera(Vertex(0,0,5), Vertex(0,0,0))
controls = TrackBallControls()
pygame.init()
@ -82,8 +77,12 @@ def main(args):
# Update physics
controls.update()
# Draw frame
init_frame()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
camera.look()
glPushMatrix()
controls.apply()