FlatMeshTriangle - Point3D v2 = mesh.vertices.get(index2...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
package raytracer.geometricObjects; import raytracer.utility.*; public class FlatMeshTriangle extends MeshTriangle { // ---------------------------------------------------------------- default constructor public FlatMeshTriangle() { super(); } // ---------------------------------------------------------------- constructor public FlatMeshTriangle (Mesh mesh_ptr, int i0, int i1, int i2) { super(mesh_ptr, i0, i1, i2); } // ---------------------------------------------------------------- copy constructor public FlatMeshTriangle(FlatMeshTriangle fmt) { super(fmt); } // ---------------------------------------------------------------- clone public FlatMeshTriangle clone() { return (new FlatMeshTriangle(this)); } // ---------------------------------------------------------------- assignment operator public void set (FlatMeshTriangle rhs) { super.set(rhs); } // ---------------------------------------------------------------- hit public double hit(Ray ray, ShadeRec sr) { Point3D v0 = mesh.vertices.get(index0); Point3D v1 = mesh.vertices.get(index1);
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Point3D v2 = mesh.vertices.get(index2); double a = v0.x - v1.x, b = v0.x - v2.x, c = ray.d.x, d = v0.x - ray.o.x; double e = v0.y - v1.y, f = v0.y - v2.y, g = ray.d.y, h = v0.y - ray.o.y; double i = v0.z - v1.z, j = v0.z - v2.z, k = ray.d.z, l = v0.z - ray.o.z; double m = f * k - g * j, n = h * k - g * l, p = f * l - h * j; double q = g * i - e * k, s = e * j - f * i; double inv_denom = 1.0 / (a * m + b * q + c * s); double e1 = d * m - b * n - c * p; double beta = e1 * inv_denom; if (beta < 0.0) return (-1); double r = e * l - h * i; double e2 = a * n + d * q + c * r; double gamma = e2 * inv_denom; if (gamma < 0.0) return (-1); if (beta + gamma > 1.0) return (-1); double e3 = a * p - b * r + d * s; double t = e3 * inv_denom; if (t < Constants.kEpsilon) return (-1); sr.normal = normal; // for flat shading sr.local_hit_point = ray.o.add(ray.d.multiply(t)); return (t); } public String toString() { return "flat " + super.toString(); } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern