private void rayTrace(ref ImgRender img, ref Camera cam, ref Shape scene) { for (int x = 0; x < img.getWidth(); x++) { for (int y = 0; y < img.getHeight(); y++) { _2DVector screen = new _2DVector((2.0 * x) / img.getWidth() - 1.0, (-2.0 * y) / img.getHeight() + 1.0); Ray ray = new Ray(cam.ShootRay(ref screen)); Intersection inter = new Intersection(ref ray); if (scene.intersectionInter(ref inter)) { img.SetPixel(x, y, inter.c); } else { img.SetPixel(x, y, new Colors(0, 0, 0, 0)); } } } }
public Ray ShootRay(ref _2DVector point) // fish eye { Vector rayShot = new Vector(direction + point.x * reso[1] * right + point.y * reso[0] * up); return(new Ray(origin, rayShot.normalisedVector())); }
public double x, y; // u,v public _2DVector(_2DVector v) { this.x = v.x; this.y = v.y; }