Permalink
Browse files

more cleanup.

  • Loading branch information...
1 parent f377592 commit c77d77d484e7253f3ac5c4c41bd9cfee192e71e0 @stefanoborini committed Jul 31, 2011
Showing with 37 additions and 11 deletions.
  1. +0 −1 raytrace/ShadeRecord.py
  2. +7 −1 raytrace/__init__.py
  3. +0 −3 raytrace/math.py
  4. +24 −0 raytrace/mathop.py
  5. +5 −5 raytrace/objects.py
  6. +0 −1 raytrace/samplers.py
  7. +1 −0 scripts/test3.py
View
@@ -1 +0,0 @@
-
View
@@ -25,7 +25,7 @@ def __init__(self):
self.viewplane = ViewPlane(resolution=(200,200), pixel_size=1.0)
self.background_color = (0.0,0.0,0.0)
self.sampler = samplers.Regular(9,10)
- self.camera = cameras.PinholeCamera(eye_point = (300,400,500), look_at = (0,0,-50), up_vector=(0,1,0), viewplane_distance=400)
+ self.camera = cameras.PinholeCamera(eye_point = (100,100,100), look_at = (0,0,0), up_vector=(0,1,0), viewplane_distance=10)
self.objects=[]
def set_bgcolor(self,bgcolor):
@@ -55,3 +55,9 @@ def set_sampler(self, sampler):
def render(self):
self.camera.render(self)
+
+ def set_camera(self, camera):
+ self.camera = camera
+ def get_camera(self):
+ return camera
+
View
@@ -1,3 +0,0 @@
-def dot(a,b):
- return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]
-
View
@@ -0,0 +1,24 @@
+import math
+
+def dot(a,b):
+ return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]
+
+def norm(a):
+ return math.sqrt(sum(map(lambda x: x*x, a)))
+
+def normalized(a):
+ n = norm(a)
+ return (a[0]/n, a[1]/n, a[2]/n)
+
+def cross(b,c):
+ a= ( b[1]*c[2] - b[2]*c[1],
+ b[2]*c[0] - b[0]*c[2],
+ b[0]*c[1] - b[1]*c[0],
+ )
+
+def vecmul(n,v):
+ return (v[0]*n, v[1]*n, v[2]*n)
+
+def vecsum(a,b):
+ return (a[0]+b[0], a[1]+b[1], a[2]+b[2])
+
View
@@ -1,7 +1,7 @@
from __future__ import absolute_import
import math
import sys
-from . import math as rtmath
+from . import mathop
class Sphere(object):
def __init__(self, center, radius, color):
@@ -14,9 +14,9 @@ def hit(self, ray):
ray.origin[1] - self.center[1],
ray.origin[2] - self.center[2])
- a = rtmath.dot(ray.direction, ray.direction)
- b = 2.0 * rtmath.dot(temp, ray.direction)
- c = rtmath.dot(temp, temp) - self.radius * self.radius
+ a = mathop.dot(ray.direction, ray.direction)
+ b = 2.0 * mathop.dot(temp, ray.direction)
+ c = mathop.dot(temp, temp) - self.radius * self.radius
disc = b * b - 4.0 * a * c
if (disc < 0.0):
@@ -48,7 +48,7 @@ def hit(self, ray):
ray.origin[1] + t * ray.direction[1],
ray.origin[2] + t * ray.direction[2]
)
- return ShadeRecord.ShadeRecord(normal=normal, hit_point=hit_point, parameter=t, color=self.color)
+ return ShadeRecord(normal=normal, hit_point=hit_point, parameter=t, color=self.color)
return None
View
@@ -1,4 +1,3 @@
-from __future__ import absolute_import
import math
import random
View
@@ -9,5 +9,6 @@
w.add_object(objects.Sphere(center=(50.0,0.0,0.0), radius=10.0, color=(1.0,0.0,0.0)))
w.add_object(objects.Sphere(center=(0.0,50.0,0.0), radius=10.0, color=(0.0,1.0,0.0)))
w.add_object(objects.Sphere(center=(0.0,0.0,50.0), radius=10.0, color=(0.0,0.0,1.0)))
+w.set_camera(cameras.PinholeCamera(look_at=(0.0,0.0,0.0), eye_point=(100.0,0.0,0.0), viewplane_distance=90.0, up_vector=(0.0,1.0,0.0)))
w.render()

0 comments on commit c77d77d

Please sign in to comment.