forked from sd17spring/InteractiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
36 lines (30 loc) · 1.35 KB
/
camera.py
File metadata and controls
36 lines (30 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Represents the camera object, storing position/orientation information
@author: Matt Brucker
@Author: Adam Novotny
"""
from math import sin, cos, pi
class Camera:
def __init__(self, init_pos=[0, 0, 0], init_angle=[0, 0, 0], init_fov=.5*pi):
"""
Initializes a new Camera object with init_pos, init_angle, init_fov
"""
self.pos = init_pos
self.angle = init_angle
self.fov = init_fov
def __str__(self):
return "Camera object at: {}, {}, {}. Angles: {}, {}, {}. Fov: {}".format(self.pos[0], self.pos[1], self.pos[2], self.angle[0], self.angle[1], self.angle[2], self.fov)
def move(self, movement, speed=0.0001):
"""
Moves the position of the camera object along the x and z axes (the axes of movement)
"""
self.pos[0] += (movement[0]*speed*cos(self.angle[0]))+(movement[2]*speed*sin(self.angle[0]))
self.pos[2] += (movement[0]*speed*sin(-self.angle[0]))+(movement[2]*speed*cos(self.angle[0]))
def rotate(self, yaw, pitch, roll, sensitivity=.1):
"""
Rotates the orientation matrix of the camera. Restricts y-axis orientation to (-pi/2, pi/2)
"""
self.angle[0] += yaw*sensitivity
# Restricts pitch rotation
self.angle[1] = max(-pi/2, min(pi/2, self.angle[1] + pitch*sensitivity))
self.angle[2] += roll*sensitivity