FlatMeshTriangle

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

Info iconThis 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);
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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

This note was uploaded on 02/19/2010 for the course CS 390 taught by Professor Hu during the Spring '10 term at Westminster UT.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online