public P3 normal(P3 p) { P3 v2 = p.sub(this.center); return v2.scale(1 / radius); }
//public static SceneObject shootRay(Ray r, out double d) //{ // float dist; // SceneObject obj = closest(r); // if (obj == null) // { // return null; // } // dist = obj.distance(r); // if (dist == infinity) // { // return null; // } // else // { // return obj; // } //} //public static SceneObject closest(Ray ray) //{ // SceneObject sceneObj = null; // float dist, smallestDist = infinity; // foreach (SceneObject obj in objects) // { // if ((dist = obj.distance(ray)) <= smallestDist) // { // smallestDist = dist; // sceneObj = obj; // } // } // return sceneObj; //} public void noName() { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float size1 = size; P3 p = new P3(i / size1 * 2.0f - 1, 0, j / size1 * 2.0f - 1); Ray r = new Ray(camera, p.sub(camera).normalize()); float distance = sphere.intersect(r); if (distance != -1) { P3 sp = r.travel(distance); P3 n = sphere.normal(sp); float intensity = n.dotProduct(direction); if (intensity < 0) { intensity = 0; } pixels[i, j] = directional.scalarMultiply(intensity); } else { pixels[i, j] = new RColor(0, 0, 0); } } } panel.Refresh(); }