diff --git a/d3/cameras/__init__.py b/d3/cameras/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/d3/cameras/camera.py b/d3/cameras/camera.py new file mode 100644 index 0000000..22e5610 --- /dev/null +++ b/d3/cameras/camera.py @@ -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) diff --git a/d3/controls/controls.py b/d3/controls/controls.py index 70aeab1..ec6bc48 100644 --- a/d3/controls/controls.py +++ b/d3/controls/controls.py @@ -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 diff --git a/modelviewer.py b/modelviewer.py index 42f0f82..0fe032f 100755 --- a/modelviewer.py +++ b/modelviewer.py @@ -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()