public InterResult Intersect(Ray ray) { Vec3d r = ray.direction.Cross(e2); Vec3d s = ray.position - v1; float a = e1 % r; float f = 1 / a; Vec3d q = s.Cross(e1); float u = s % r; if (a > 1e-6f) { if (u < 0 || u > a) { return(null); } float v = ray.direction % q; if (v < 0 || u + v > a) { return(null); } float t = f * (e2 % q); return(new InterResult(t, ray.GetFront(t), this)); } return(null); }
public Triangle(Vec3d v1, Vec3d v2, Vec3d v3) { this.v1 = v1; this.v2 = v2; this.v3 = v3; e1 = v2 - v1; e2 = v3 - v1; normal = e1.Cross(e2); normal.Normalize(); }
public PerspectiveCamera(Vec3d vp, Vec3d f, Vec3d refUp, float fov) { viewPoint = vp; f.Normalize(); front = f; right = f.Cross(refUp); right.Normalize(); up = right.Cross(f); fovScale = (float)Math.Tan(fov * Pi * 0.5f / 180) * 2; }