/** * Return the Vector's reflection direction * @return The specular direction */ Vec SpecularDirection(Vec I, Vec N) { Vec r; r = Vec.comb(1.0 / Math.Abs(Vec.dot(I, N)), I, 2.0, N); r.normalize(); return(r); }
/** * Return the Vector's transmission direction */ Vec TransDir(Surface m1, Surface m2, Vec I, Vec N) { double n1, n2, eta, c1, cs2; Vec r; n1 = m1 == null ? 1.0 : m1.ior; n2 = m2 == null ? 1.0 : m2.ior; eta = n1 / n2; c1 = -Vec.dot(I, N); cs2 = 1.0 - eta * eta * (1.0 - c1 * c1); if (cs2 < 0.0) { return(null); } r = Vec.comb(eta, I, eta * c1 - Math.Sqrt(cs2), N); r.normalize(); return(r); }
public void render(Interval interval) { int[] row = new int[interval.width * (interval.yto - interval.yfrom)]; int pixCounter = 0; //iterator int x, y, red, green, blue; double xlen, ylen; Vec viewVec; viewVec = Vec.sub(view.at, view.from); viewVec.normalize(); Vec tmpVec = new Vec(viewVec); tmpVec.scale(Vec.dot(view.up, viewVec)); Vec upVec = Vec.sub(view.up, tmpVec); upVec.normalize(); Vec leftVec = Vec.cross(view.up, viewVec); leftVec.normalize(); double frustrumwidth = view.dist * Math.Tan(view.angle); upVec.scale(-frustrumwidth); leftVec.scale(view.aspect * frustrumwidth); Ray r = new Ray(view.from, voidVec); Vec col = new Vec(); // For each line for (y = interval.yfrom; y < interval.yto; y++) { ylen = (double)(2.0 * y) / (double)interval.width - 1.0; for (x = 0; x < interval.width; x++) { xlen = (double)(2.0 * x) / (double)interval.width - 1.0; r.D = Vec.comb(xlen, leftVec, ylen, upVec); r.D.add(viewVec); r.D.normalize(); col = trace(0, 1.0, r); // computes the color of the ray red = (int)(col.x * 255.0); if (red > 255) { red = 255; } green = (int)(col.y * 255.0); if (green > 255) { green = 255; } blue = (int)(col.z * 255.0); if (blue > 255) { blue = 255; } checksum += red; checksum += green; checksum += blue; // Sets the pixels row [pixCounter] = alpha | (red << 16) | (green << 8) | (blue); pixCounter++; } } }