public static FMat4 View(FVec3 position, FVec3 lookAt, FVec3 upVector) { FVec3 forward = FVec3.Normalize(lookAt - position); FVec3 xVec = FVec3.Normalize(forward.Cross(upVector)); upVector = xVec.Cross(forward); FMat4 result; result.x.x = xVec.x; result.x.y = xVec.y; result.x.z = xVec.z; result.x.w = position.Dot(-xVec); result.y.x = upVector.x; result.y.y = upVector.y; result.y.z = upVector.z; result.y.w = position.Dot(-upVector); result.z.x = -forward.x; result.z.y = -forward.y; result.z.z = -forward.z; result.z.w = position.Dot(forward); result.w.x = Fix64.Zero; result.w.y = Fix64.Zero; result.w.z = Fix64.Zero; result.w.w = Fix64.One; return(result); }
public static FMat3 LookAt(FVec3 forward, FVec3 up) { FVec3 z = FVec3.Normalize(forward); FVec3 x = FVec3.Normalize(up.Cross(z)); FVec3 y = z.Cross(x); return(new FMat3(x, y, z)); }
public static Sphere Merge(Sphere bs1, Sphere bs2) { FVec3 deltaVec = bs1.Center - bs2.Center; float dist = deltaVec.Length; float tworadius = dist + bs1.Radius + bs2.Radius; float radius = tworadius / 2; deltaVec.Normalize(); FVec3 startPt = bs1.Center - (deltaVec * bs1.Radius); FVec3 center = startPt + deltaVec * radius; return(new Sphere(center, radius)); }
public void Vector() { FVec3 fv = new FVec3(12.5f, 9, 8); FVec3 fv2 = new FVec3(4, 6, 9); Vec3 v = new Vec3(12.5f, 9, 8); Vec3 v2 = new Vec3(4, 6, 9); this._output.WriteLine((fv * fv2).ToString()); this._output.WriteLine((v * v2).ToString()); fv += fv2; v += v2; this._output.WriteLine(fv.ToString()); this._output.WriteLine(v.ToString()); this._output.WriteLine((fv - fv2).ToString()); this._output.WriteLine((v - v2).ToString()); this._output.WriteLine(fv.Dot(fv2).ToString()); this._output.WriteLine(v.Dot(v2).ToString()); this._output.WriteLine(fv.Cross(fv2).ToString()); this._output.WriteLine(v.Cross(v2).ToString()); this._output.WriteLine(FVec3.Normalize(fv).ToString()); this._output.WriteLine(Vec3.Normalize(v).ToString()); this._output.WriteLine(FVec3.Slerp(fv, fv2, ( Fix64 )0.45678).ToString()); this._output.WriteLine(Vec3.Slerp(v, v2, 0.45678f).ToString()); }
public void Quat4() { FQuat fq = FQuat.Euler(( Fix64 )45, ( Fix64 )(-23), ( Fix64 )(-48.88)); FQuat fq2 = FQuat.Euler(( Fix64 )23, ( Fix64 )(-78), ( Fix64 )(-132.43f)); Quat q = Quat.Euler(45, -23, -48.88f); Quat q2 = Quat.Euler(23, -78, -132.43f); FVec3 fv = new FVec3(12.5f, 9, 8); FVec3 fv2 = new FVec3(1, 0, 0); Vec3 v = new Vec3(12.5f, 9, 8); Vec3 v2 = new Vec3(1, 0, 0); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); this._output.WriteLine(fq2.ToString()); this._output.WriteLine(q2.ToString()); Fix64 fa = FQuat.Angle(fq, fq2); float a = Quat.Angle(q, q2); this._output.WriteLine(fa.ToString()); this._output.WriteLine(a.ToString()); fq = FQuat.AngleAxis(( Fix64 )(-123.324), fv); q = Quat.AngleAxis(-123.324f, v); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fa = FQuat.Dot(fq, fq2); a = Quat.Dot(q, q2); this._output.WriteLine(fa.ToString()); this._output.WriteLine(a.ToString()); fq = FQuat.FromToRotation(FVec3.Normalize(fv), fv2); q = Quat.FromToRotation(Vec3.Normalize(v), v2); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq = FQuat.Lerp(fq, fq2, ( Fix64 )0.66); q = Quat.Lerp(q, q2, 0.66f); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq = FQuat.Normalize(fq); q.Normalize(); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq.Inverse(); q = Quat.Inverse(q); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fv = FQuat.Orthogonal(fv); v = Quat.Orthogonal(v); this._output.WriteLine(fv.ToString()); this._output.WriteLine(v.ToString()); fq = FQuat.Slerp(fq, fq2, ( Fix64 )0.66); q = Quat.Slerp(q, q2, 0.66f); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq = FQuat.LookRotation(FVec3.Normalize(fv), fv2); q = Quat.LookRotation(Vec3.Normalize(v), v2); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq.ToAngleAxis(out fa, out fv); q.ToAngleAxis(out a, out v); this._output.WriteLine(fa.ToString()); this._output.WriteLine(a.ToString()); this._output.WriteLine(fv.ToString()); this._output.WriteLine(v.ToString()); fq = fq.Conjugate(); q = q.Conjugate(); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); fq.SetLookRotation(FVec3.Normalize(fv), fv2); q.SetLookRotation(Vec3.Normalize(v), v2); this._output.WriteLine(fq.ToString()); this._output.WriteLine(q.ToString()); }
public FRay(FVec3 origin, FVec3 direction) { this.origin = origin; this.direction = FVec3.Normalize(direction); }