public void SetLookAt(Float3 eye, Float3 center, Float3 up) { Float3 f = center - eye; // -direction f = f.Normalize; up = up.Normalize; Float3 s = f.Cross(up); // right Float3 u = s.Cross(f); // up world2view[0] = new Float4(s.X, u.X, -f.X, 0f); world2view[1] = new Float4(s.Y, u.Y, -f.Y, 0f); world2view[2] = new Float4(s.Z, u.Z, -f.Z, 0f); world2view[3] = new Float4(0f, 0f, 0f, 1f); Float4x4 m = Float4x4.Identity; m[3] = new Float4(-eye, 1f); world2view *= m; world2view = Float4x4.Transpose(world2view); }
public static void MathTest() { Random rand = new Random(); float x = (float)rand.NextDouble(); float y = (float)rand.NextDouble(); float z = (float)rand.NextDouble(); float w = (float)rand.NextDouble(); float v = (float)rand.NextDouble(); Float3 fpuF3 = new(x, y, z); Float4 fpuF4 = new(x, y, z, w); Float3 fpuF31 = fpuF3 * v; Float4 fpuF41 = fpuF4 * v; Float4x4 fpuF44 = new(x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w); SseMath.Float3 sseF3 = new(x, y, z); SseMath.Float4 sseF4 = new(x, y, z, w); SseMath.Float3 sseF31 = sseF3 * v; SseMath.Float4 sseF41 = sseF4 * v; SseMath.Float4x4 sseF44 = new(x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w); Console.WriteLine($"Add VV FPU: {fpuF31 + fpuF3}"); Console.WriteLine($"Add VV SSE: {sseF31 + sseF3}"); Console.WriteLine(); Console.WriteLine($"Add VS FPU: {fpuF3 + v}"); Console.WriteLine($"Add VS SSE: {sseF3 + v}"); Console.WriteLine(); Console.WriteLine($"Sub VV FPU: {fpuF31 - fpuF3}"); Console.WriteLine($"Sub VV SSE: {sseF31 - sseF3}"); Console.WriteLine(); Console.WriteLine($"Sub VS FPU: {fpuF3 - v}"); Console.WriteLine($"Sub VS SSE: {sseF3 - v}"); Console.WriteLine(); Console.WriteLine($"Mul VV FPU: {fpuF31 * fpuF3}"); Console.WriteLine($"Mul VV SSE: {sseF31 * sseF3}"); Console.WriteLine(); Console.WriteLine($"Mul VS FPU: {fpuF3 * v}"); Console.WriteLine($"Mul VS SSE: {sseF3 * v}"); Console.WriteLine(); Console.WriteLine($"Div VV FPU: {fpuF31 / fpuF3}"); Console.WriteLine($"Div VV SSE: {sseF31 / sseF3}"); Console.WriteLine(); Console.WriteLine($"Div VS FPU: {fpuF3 / v}"); Console.WriteLine($"Div VS SSE: {sseF3 / v}"); Console.WriteLine(); Console.WriteLine($"Dot VV FPU: {fpuF31.Dot(fpuF3)}"); Console.WriteLine($"Dot VV SSE: {SseMath.Float3.Dot(sseF31, sseF3)}"); Console.WriteLine(); Console.WriteLine($"Crs VV FPU: {fpuF31.Cross(fpuF3)}"); Console.WriteLine($"Crs VV SSE: {SseMath.Float3.Cross(sseF31, sseF3)}"); Console.WriteLine(); Console.WriteLine($"Nor VV FPU: {fpuF3.Normalize}"); Console.WriteLine($"Nor VV SSE: {SseMath.Float3.Normalize(sseF3)}"); Console.WriteLine(); Console.WriteLine($"Sat VV FPU: {Light.Saturate(fpuF3)}"); Console.WriteLine($"Sat VV SSE: {SseMath.Float3.Saturate(sseF3)}"); Console.WriteLine(); Console.WriteLine($"Ref VV FPU: {Float3.Reflect(fpuF31, fpuF3)}"); Console.WriteLine($"Ref VV SSE: {SseMath.Float3.Reflect(sseF31, sseF3)}"); Console.WriteLine(); Console.WriteLine($"Add VV FPU: {fpuF41 + fpuF4}"); Console.WriteLine($"Add VV SSE: {sseF41 + sseF4}"); Console.WriteLine(); Console.WriteLine($"Add VS FPU: {fpuF4 + v}"); Console.WriteLine($"Add VS SSE: {sseF4 + v}"); Console.WriteLine(); Console.WriteLine($"Sub VV FPU: {fpuF41 - fpuF4}"); Console.WriteLine($"Sub VV SSE: {sseF41 - sseF4}"); Console.WriteLine(); Console.WriteLine($"Sub VS FPU: {fpuF4 - v}"); Console.WriteLine($"Sub VS SSE: {sseF4 - v}"); Console.WriteLine(); Console.WriteLine($"Mul VV FPU: {fpuF41 * fpuF4}"); Console.WriteLine($"Mul VV SSE: {sseF41 * sseF4}"); Console.WriteLine(); Console.WriteLine($"Mul VS FPU: {fpuF4 * v}"); Console.WriteLine($"Mul VS SSE: {sseF4 * v}"); Console.WriteLine(); Console.WriteLine($"Div VV FPU: {fpuF41 / fpuF4}"); Console.WriteLine($"Div VV SSE: {sseF41 / sseF4}"); Console.WriteLine(); Console.WriteLine($"Div VS FPU: {fpuF4 / v}"); Console.WriteLine($"Div VS SSE: {sseF4 / v}"); Console.WriteLine(); Console.WriteLine($"Dot VV FPU: {fpuF41.Dot(fpuF4)}"); Console.WriteLine($"Dot VV SSE: {SseMath.Float4.Dot(sseF41, sseF4)}"); Console.WriteLine(); Console.WriteLine($"Nor VV FPU: {fpuF4.Normalize}"); Console.WriteLine($"Nor VV SSE: {SseMath.Float4.Normalize(sseF4)}"); Console.WriteLine(); Console.WriteLine($"Mul VM FPU: {fpuF44 * fpuF4}"); Console.WriteLine($"Mul VM SSE: {sseF44 * sseF4}"); Console.WriteLine(); Console.WriteLine($"Mul MM FPU: \n{fpuF44 * fpuF44}"); Console.WriteLine($"Mul MM SSE: \n{sseF44 * sseF44}"); Console.WriteLine(); }