summaryrefslogtreecommitdiff
path: root/camera.py
diff options
context:
space:
mode:
Diffstat (limited to 'camera.py')
-rw-r--r--camera.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/camera.py b/camera.py
new file mode 100644
index 0000000..5a05535
--- /dev/null
+++ b/camera.py
@@ -0,0 +1,33 @@
+import numpy as np
+from itertools import product
+
+class Camera(object):
+ """
+ Pinhole camera object.
+
+ 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(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