public void MoveCamera(RTPoint lookFrom, RTPoint lookAt, RTVector up) { Eye = new RTPoint(lookFrom); W = (lookFrom - lookAt).Normalize(); U = RTVector.CrossProduct(up, W).Normalize(); V = RTVector.CrossProduct(W, U); }
public bool Intersect(Ray ray, bool computeGeo, out LocalGeo geo, out float pos) { RTPoint A = Vertices[0].Location; RTPoint B = Vertices[1].Location; RTPoint C = Vertices[2].Location; RTVector p0 = new RTVector(ray.Point); pos = RTVector.DotProduct(A - ray.Point, Normal) / RTVector.DotProduct(ray.Vector, Normal); geo = new LocalGeo(); if (pos >= ray.TMin && pos <= ray.TMax) { geo.Point = ray.Point + pos * ray.Vector; geo.Normal = Normal; RTVector u = B - A; RTVector v = C - A; RTVector w = geo.Point - A; RTVector vCrossW = RTVector.CrossProduct(v, w); RTVector vCrossU = RTVector.CrossProduct(v, u); if (RTVector.DotProduct(vCrossW, vCrossU) < 0) { return(false); } RTVector uCrossW = RTVector.CrossProduct(u, w); RTVector uCrossV = RTVector.CrossProduct(u, v); if (RTVector.DotProduct(uCrossW, uCrossV) < 0) { return(false); } float denom = uCrossV.Length; float r = vCrossW.Length / denom; float t = uCrossW.Length / denom; return(r + t <= 1); } return(false); }
private Normal ComputeNormal() { Normal res; bool normVertex = Vertices[0].Normal != null; if (normVertex) { // TODO res = new Normal(0, 1, 0); } else { RTPoint A = Vertices[0].Location; RTPoint B = Vertices[1].Location; RTPoint C = Vertices[2].Location; RTVector U = B - A; RTVector V = C - A; res = new Normal(RTVector.CrossProduct(U, V)); } return(res); }