summaryrefslogtreecommitdiff
path: root/camera.py
diff options
context:
space:
mode:
Diffstat (limited to 'camera.py')
-rw-r--r--camera.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/camera.py b/camera.py
index f00cc56..5a05535 100644
--- a/camera.py
+++ b/camera.py
@@ -1,22 +1,33 @@
import numpy as np
+from itertools import product
class Camera(object):
- def __init__(self, size = (800, 600), film_size = (0.035, 0.024), focal_length=0.05):
- width, height = size
+ """
+ Pinhole camera object.
- grid = []
- for i, x in enumerate(np.linspace(-film_size[0]/2, film_size[0]/2, width)):
- for j, z in enumerate(np.linspace(-film_size[1]/2, film_size[1]/2, height)):
- grid.append((x,0,z))
+ Args:
+ - size: tuple, *optional*
+ Pixel array shape.
+ - film_size: tuple, *optional*
+ Physical size of photographic film. Defaults to 35mm film size.
+ - focal_length: float, *optional*
+ Focal length of camera.
+ """
+ def __init__(self, size = (800, 600), film_size = (0.035, 0.024), \
+ focal_length=0.05):
+ x = np.linspace(-film_size[0]/2, film_size[0]/2, size[0])
+ z = np.linspace(-film_size[1]/2, film_size[1]/2, size[1])
- self.grid = np.array(grid)
- self.grid += (0,focal_length,0)
+ self.grid = np.array(tuple(product(x,[0],z)))
+ self.grid += (0,focal_length,0)
self.focal_point = np.zeros(3)
def position(self, position):
+ """Translate the camera to `position`."""
self.grid += position
self.focal_point += position
def get_rays(self):
+ """Return the position and direction for each pixel ray."""
return self.grid, self.focal_point-self.grid