Added class Camera
This commit is contained in:
		
							parent
							
								
									8e19606310
								
							
						
					
					
						commit
						ddb5f4b3d3
					
				
							
								
								
									
										0
									
								
								d3/cameras/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								d3/cameras/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										19
									
								
								d3/cameras/camera.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								d3/cameras/camera.py
									
									
									
									
									
										Normal 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)
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user