/** Raytrace one frame. */ private void raytrace() { double aspect = width / (double) height; Ray ray = new Ray(); camPos.set(0, -distance, 0); transform.transform(camPos); camPos.add(.5, .5, .5); for (int x = 0; x < width; ++x) { double rayx = fovTan * aspect * (.5 - ((double) x) / width); for (int y = 0; y < height; ++y) { ray.setDefault(); ray.d.set(rayx, 1, fovTan * (.5 - ((double) y) / height)); ray.d.normalize(); transform.transform(ray.d); ray.o.set(camPos); raytrace(ray); ray.color.x = QuickMath.min(1, FastMath.sqrt(ray.color.x)); ray.color.y = QuickMath.min(1, FastMath.sqrt(ray.color.y)); ray.color.z = QuickMath.min(1, FastMath.sqrt(ray.color.z)); backBuffer.setRGB(x, y, Color.getRGB(ray.color)); } } }
/** @return Next ray from free list */ public final Ray get() { Ray ray; if (size == 0) { ray = new Ray(); } else { ray = pool[--size]; } ray.setDefault(); return ray; }
/** * Initialize a ray with origin and direction. * * @param o Origin * @param d Direction */ public final void set(Vector3d o, Vector3d d) { setDefault(); this.x.set(o); this.d.set(d); }