Exemplo n.º 1
0
 def calculate_camera_variables(self):
     W = self.__lookat - self.__eye
     w_len = np.linalg.norm(W)
     U = hlp.normalize(np.cross(W, self.__up))
     V = hlp.normalize(np.cross(U, W))
     v_len = w_len * np.tan(0.5 * self.__fov * np.pi / 180.0)
     V = V * v_len
     aspect_ratio = (1.0 * self.__width) / self.__width
     u_len = v_len * aspect_ratio
     U = U * u_len
     self.__W = W
     self.__U = U
     self.__V = V
Exemplo n.º 2
0
 def intersect(self, ray: Ray, info: RayIntersectionInfo):
     O = ray.origin - self.center
     b = np.dot(O, ray.direction)
     c = np.dot(O, O) - self.radius * self.radius
     disc = b * b - c
     if disc > 0.0:
         s_disc = np.sqrt(disc)
         t = -b - s_disc
         if ray.t_min < t < ray.t_max:
             n = (O + t * ray.direction) / self.radius
             ray.t_max = t
             info.normal = n
             if len(info.t_hits) > 0:
                 info.t_hits[0] = t
             else:
                 info.t_hits.append(t)
             return True
         t = -b + s_disc
         if ray.t_min < t < ray.t_max:
             n = (O + t * ray.direction) / self.radius
             ray.t_max = t
             info.normal = hlp.normalize(n)
             if len(info.t_hits) > 0:
                 info.t_hits[0] = t
             else:
                 info.t_hits.append(t)
             return True
     return False
Exemplo n.º 3
0
 def intersect(self, ray):
     origin_local = np.dot(self.transform.inverse_transformation_matrix,
                           np.append(ray.origin, 1.0))[0:-1]
     direction_local = hlp.normalize(
         np.dot(self.transform.inverse_transformation_matrix,
                np.append(ray.direction, 0.0)))[0:-1]
     local_ray = pst.Ray(origin_local, direction_local, 0, np.inf)
     t_local, normal_local = self.obj.intersect(local_ray)
     hit_point_local = origin_local + t_local * direction_local
     hit_point = np.dot(self.transform.transformation_matrix,
                        np.append(hit_point_local, 1.0))[0:-1]
     t_hit = np.linalg.norm(ray.origin - hit_point)
     if t_hit > ray.t_min and t_hit < ray.t_max:
         #found intersection
         ray.t_max = t_hit
         normal = np.dot(self.transform.normal_matrix,
                         np.append(normal_local, 0.0))[0:-1]
         return t_hit, hlp.normalize(normal)
     else:
         return np.inf, None
Exemplo n.º 4
0
 def intersect(self, ray: Ray, info: RayIntersectionInfo):
     e0 = self.__v1 - self.__v0
     e1 = self.__v0 - self.__v2
     n = np.cross(e1, e0)
     e2 = (1.0 / np.dot(n, ray.direction)) * (self.__v0 - ray.origin)
     i = np.cross(ray.direction, e2)
     beta = np.dot(i, e1)
     gamma = np.dot(i, e0)
     t = np.dot(n, e2)
     if ray.t_max > t > ray.t_min and beta > 0.0 and gamma >= 0.0 and beta + gamma <= 1:
         ray.t_max = t
         info.normal = hlp.normalize(n)
         if len(info.t_hits) > 0:
             info.t_hits[0] = t
         else:
             info.t_hits.append(t)
         return True
     return False
Exemplo n.º 5
0
 def __init__(self, x_0: np.array, normal: np.array):
     self.x_0 = x_0
     self.normal = hlp.normalize(normal)