def getPixel(self, pixelBox):
     (x, y, x2, y2) = pixelBox
     pixSize = x2 - x
     colour = Colour(0, 0, 0)
     for i in range(self.subPixels):
         colour += self.rayfunc(
             Ray3(self.eye,
                  (Point3(random.uniform(x, x2), random.uniform(y, y2), 1) -
                   self.eye)))
     return old_div(colour, self.subPixels)
Beispiel #2
0
 def calcReflections(self, scene, depth=0):
     if self.mat.reflectivity and depth < 100 and self.entry > 0:
         dir = self.ray.dir
         norm = self.normal
         if norm is None:
             print(self.obj, self.entry, self.exit)
         Rdir = -2 * dir.dot(norm) * norm + dir
         ray = Ray3(self.ray.pos(self.entry) + Rdir * 0.0000001, Rdir)
         self.reflection = scene.intersect(ray)
         if self.reflection is not None:
             self.reflection.calcReflections(scene, depth + 1)
         else:
             self.bgcolour = scene.background
 def getPixel(self, pixelBox):
     (x, y, x2, y2) = pixelBox
     pitch = old_div((x2 - x), (self.subPixels * 2))
     xx = x
     yy = y
     count = 0
     colour = Colour(0, 0, 0)
     for col in range(self.subPixels):
         for row in range(self.subPixels):
             colour += self.rayfunc(
                 Ray3(self.eye,
                      (Point3(xx + pitch, yy + pitch, 1) - self.eye)))
             count += 1
             yy += pitch * 2
         yy = y
         xx += pitch * 2
     assert count == self.subPixels * self.subPixels
     return old_div(colour, count)
def get_hit_point_draw(combined_ray, linecolor):
    start = np.array([0.0, 0.0, 0.0])

    rot = np.array([0.0, 1.0, 0, 0.0])
    # rotate a vector by quaternion rotation
    dir = rotate_vec_by_quaternion(rot, combined_ray)
    end = start + dir

    #get hitting point
    sphere = Sphere(Point3(0, 0, 0), 1)
    ray = Ray3(Point3(start[0], start[1], start[2]),
               Vector3(dir[0], dir[1], dir[2]))
    hitpoint = sphere.intersect(ray)

    #check if hitting point is on sphere surface
    # check_point_on_sphere(0, 0, 0, hitpoint, 1)

    # convert unity coordinate to python coordinate
    unity_to_python_point(start)
    unity_to_python_point(end)
    unity_to_python_point(hitpoint)

    return hitpoint
Beispiel #5
0
        O = ray.start
        D = ray.dir
        S = self.center
        R = self.radius
        a = D.dot(D)
        OS = O - S
        b = 2 * D.dot(OS)
        c = OS.dot(OS) - R * R
        disc = b * b - 4 * a * c
        if disc > 0:
            distSqrt = sqrt(disc)
            q = (-b - distSqrt) / 2.0 if b < 0 else (-b + distSqrt) / 2.0
            t0 = q / a
            t1 = c / q
            t0, t1 = min(t0, t1), max(t0, t1)
            if t1 >= 0:
                return t1 if t0 < 0 else t0
        return float("inf")

    def __repr__(self):
        return "Sphere(%s, %.3f)" % (str(self.center), self.radius)


# Two simple sanity tests if module is run directly

if __name__ == "__main__":
    sphere = Sphere(Point3(1, 0, 0), 1)
    ray = Ray3(Point3(1, 0, 5), Vector3(0, 0, -1))
    missingRay = Ray3(Point3(1, 0, 5), Vector3(0, 0, 1))
    assert abs(sphere.intersect(ray) - 4.0) < 0.00001
    assert sphere.intersect(missingRay) is None
 def getPixel(self, pixelBox):
     (x, y, x2, y2) = pixelBox
     pixelCentre = Point3(old_div((x + x2), 2), old_div((y2 + y), 2), 1)
     ray = Ray3(self.eye, pixelCentre - self.eye)
     return self.rayfunc(ray)