public NuGenRot3F(NuGenVec3F from, NuGenVec3F to) { from.Normalize(); to.Normalize(); float cost = NuGenVec3F.Dot(from, to) / (float)Math.Sqrt(NuGenVec3F.Dot(from, to) * NuGenVec3F.Dot(to, to)); if (cost > 0.99999) { r = 1; v = new NuGenVec3F(0, 0, 0); } else if (cost < -0.99999) { NuGenVec3F frm = from.Normalized; v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitX); if (v.Length < 0.00001) v = NuGenVec3F.Cross(frm, NuGenVec3F.UnitY); r = 0; v.Normalize(); } else { r = (float)Math.Sqrt(0.5 * (1.0 + cost)); v = NuGenVec3F.Cross(from, to); v *= (float)Math.Sqrt((0.5 * (1.0 - cost))/NuGenVec3F.Dot(v, v)); } }
public bool Intersect(NuGenRay3F ray, ref float t, ref NuGenVec3F normal) { NuGenVec3F l = center - ray.Point; float s = NuGenVec3F.Dot(l, ray.Direction); float l2 = l.SquaredLength; float rr = radius * radius; if (s < 0.0f && l2 > rr) { return(false); } float m2 = l2 - s * s; if (m2 > rr) { return(false); } float q = (float)Math.Sqrt(rr - m2); if (l2 > rr) { t = s - q; } else { t = s + q; } normal = (ray.Point + ray.Direction * t) - center; normal.Normalize(); return(true); }
public bool Intersect(NuGenRay3F ray, ref float t, ref float u, ref float v, ref NuGenVec3F normal) { NuGenVec3F e1 = p1 - p0; NuGenVec3F e2 = p2 - p0; NuGenVec3F p = NuGenVec3F.Cross(ray.Direction, e2); float a = NuGenVec3F.Dot(e1, p); if (a > -NuGenVector.TINY_FLOAT && a < NuGenVector.TINY_FLOAT) { return(false); } float f = 1.0f / a; NuGenVec3F s = ray.Point - p0; u = f * NuGenVec3F.Dot(s, p); if (u < 0.0f || u > 1.0f) { return(false); } NuGenVec3F q = NuGenVec3F.Cross(s, e1); v = f * NuGenVec3F.Dot(ray.Direction, q); if (v < 0.0f || (u + v) > 1.0f) { return(false); } t = f * NuGenVec3F.Dot(e2, q); normal = NuGenVec3F.Cross(e1, e2); normal.Normalize(); return(true); }
public static bool ApproxEquals(NuGenVec3F a, NuGenVec3F b) { return Math.Abs(a._x[0] - b._x[0]) < NuGenVector.TINY_FLOAT && Math.Abs(a._x[1] - b._x[1]) < NuGenVector.TINY_FLOAT && Math.Abs(a._x[2] - b._x[2]) < NuGenVector.TINY_FLOAT; }
public bool Intersect(NuGenRay3F ray, ref float t, ref NuGenVec3F normal) { NuGenVec3F l = center - ray.Point; float s = NuGenVec3F.Dot(l, ray.Direction); float l2 = l.SquaredLength; float rr = radius * radius; if (s < 0.0f && l2 > rr) return false; float m2 = l2 - s * s; if (m2 > rr) return false; float q = (float)Math.Sqrt(rr - m2); if (l2 > rr) t = s - q; else t = s + q; normal = (ray.Point + ray.Direction * t) - center; normal.Normalize(); return true; }
public bool Intersect(NuGenRay3F ray, ref float t, ref float u, ref float v, ref NuGenVec3F normal) { NuGenVec3F e1 = p1 - p0; NuGenVec3F e2 = p2 - p0; NuGenVec3F p = NuGenVec3F.Cross(ray.Direction, e2); float a = NuGenVec3F.Dot(e1, p); if (a > -NuGenVector.TINY_FLOAT && a < NuGenVector.TINY_FLOAT) return false; float f = 1.0f / a; NuGenVec3F s = ray.Point - p0; u = f * NuGenVec3F.Dot(s, p); if (u < 0.0f || u > 1.0f) return false; NuGenVec3F q = NuGenVec3F.Cross(s, e1); v = f * NuGenVec3F.Dot(ray.Direction, q); if (v < 0.0f || (u + v) > 1.0f) return false; t = f * NuGenVec3F.Dot(e2, q); normal = NuGenVec3F.Cross(e1, e2); normal.Normalize(); return true; }
public NuGenRay3F(NuGenPnt3F p, NuGenVec3F v) { this.p = p; this.v = v; }
public NuGenRot3F(float radians, NuGenVec3F axis) { axis.Normalize(); r = (float)Math.Cos(radians/2.0); v = axis.Normalized * (float)Math.Sin(radians/2.0); }
public NuGenShift3F(NuGenVec3F shift) { v = shift; }
public NuGenShift3F(float x, float y, float z) { v = new NuGenVec3F(x,y,z); }
public NuGenScale3F(NuGenVec3F shift) { v = shift; }
public NuGenScale3F(float x, float y, float z) { v = new NuGenVec3F(x,y,z); }