Gra_3d/camera.py
2017-08-10 17:53:55 +02:00

30 lines
784 B
Python

from OpenGL.GLU import *
import math
class Camera:
def __init__(self,x,y,z):
self.x=x
self.y=y
self.z=z
self.tx=0.0
self.ty=0.0
self.tz=0.0
self.pitch=0.0
self.roll=0.0
def move(self,x,y,z):
self.x+=x
self.y+=y
self.z+=z
def moveTo(self,x,y,z):
self.x=x
self.y=y
self.z=z
def rotate(self,x,y):
self.roll+=x
self.pitch+=y
self.tx=math.cos(self.roll)*math.sin(self.pitch)
self.ty=math.cos(self.pitch)
self.tz=math.sin(self.roll)*math.sin(self.pitch)
def look(self):
gluLookAt(self.x,self.y,self.z,self.x+self.tx,self.y+self.ty,self.z+self.tz,0,1,0)
def getPos(self):
return self.x,self.y,self.z