public static void Test() { Debug.Log("IsLittleEndian " + BitConverter.IsLittleEndian); Debug.Log(FixPointMathTest.ConvertFloatToBinStr(1f)); Debug.Log(FixPointMathTest.ConvertFloatToBinStr(17.625f)); Debug.Log(FixPointMath.SqrtOld(new FloatL(0.955d))); Debug.Log(Mathf.Sqrt(0.955f)); Debug.Log(FixPointMath.Sqrt(new FloatL(0.955d))); Vector3L dir = new Vector3L(-0.093d, -0.093d, 0.988d); FloatL angle1 = Vector3L_Angle(Vector3L.forward, dir); float angle2 = Vector3_Angle(Vector3.forward, dir.Convert()); Debug.Log("angle1 " + angle1 + " angle2 " + angle2); Debug.Log("sin 10 " + Mathf.Sin(10 * Mathf.Deg2Rad)); Debug.Log("sinL 10 " + FixPointMath.Sin(10 * Mathf.Deg2Rad)); Debug.Log("cos 10 " + Mathf.Cos(10 * Mathf.Deg2Rad)); Debug.Log("cosL 10 " + FixPointMath.Cos(10 * Mathf.Deg2Rad)); Debug.Log("acos 0.1 " + Mathf.Acos(0.1f)); Debug.Log("acosL 0.1 " + FixPointMath.Acos(0.1f)); Debug.Log("atan2 3/2 " + Mathf.Atan2(3, 2)); Debug.Log("atan2L 3/2 " + FixPointMath.Atan2(3, 2)); Debug.Log("asin 0.6 " + Mathf.Asin(0.6f)); Debug.Log("asinL 0.6 " + FixPointMath.Asin(0.6f)); }
public static QuaternionL LookRotation(Vector3L forward, Vector3L up) { forward = Vector3L.Normalize(forward); Vector3L right = Vector3L.Normalize(Vector3L.Cross(up, forward)); up = Vector3L.Cross(forward, right); FloatL m00 = right.x; FloatL m01 = right.y; FloatL m02 = right.z; FloatL m10 = up.x; FloatL m11 = up.y; FloatL m12 = up.z; FloatL m20 = forward.x; FloatL m21 = forward.y; FloatL m22 = forward.z; FloatL num8 = (m00 + m11) + m22; QuaternionL quaternion = new QuaternionL(); if (num8 > 0f) { FloatL num = FixPointMath.Sqrt(num8 + 1f); quaternion.w = num * 0.5f; num = 0.5f / num; quaternion.x = (m12 - m21) * num; quaternion.y = (m20 - m02) * num; quaternion.z = (m01 - m10) * num; return(quaternion); } if ((m00 >= m11) && (m00 >= m22)) { FloatL num7 = FixPointMath.Sqrt(((1f + m00) - m11) - m22); FloatL num4 = 0.5f / num7; quaternion.x = 0.5f * num7; quaternion.y = (m01 + m10) * num4; quaternion.z = (m02 + m20) * num4; quaternion.w = (m12 - m21) * num4; return(quaternion); } if (m11 > m22) { FloatL num6 = FixPointMath.Sqrt(((1f + m11) - m00) - m22); FloatL num3 = 0.5f / num6; quaternion.x = (m10 + m01) * num3; quaternion.y = 0.5f * num6; quaternion.z = (m21 + m12) * num3; quaternion.w = (m20 - m02) * num3; return(quaternion); } FloatL num5 = FixPointMath.Sqrt(((1f + m22) - m00) - m11); FloatL num2 = 0.5f / num5; quaternion.x = (m20 + m02) * num2; quaternion.y = (m21 + m12) * num2; quaternion.z = 0.5f * num5; quaternion.w = (m01 - m10) * num2; return(quaternion); }
static void ToAxisAngleRad(QuaternionL q, out Vector3L axis, out FloatL angle) { if (FixPointMath.Abs(q.w) > 1.0f) { q.Normalize(); } angle = 2.0f * FixPointMath.Acos(q.w); // angle FloatL den = FixPointMath.Sqrt(1.0f - q.w * q.w); if (den > 0.0001f) { axis = q.xyz / den; } else { // This occurs when the angle is zero. // Not a problem: just set an arbitrary normalized axis. axis = new Vector3L(1, 0, 0); } }
public static FloatL Magnitude(Vector3L a) { return(FixPointMath.Sqrt(a.x * a.x + a.y * a.y + a.z * a.z)); }
public static FloatL Distance(Vector3L a, Vector3L b) { Vector3L vector = new Vector3L(a.x - b.x, a.y - b.y, a.z - b.z); return(FixPointMath.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z)); }
public static FloatL Magnitude(Vector4L a) { return(FixPointMath.Sqrt(Vector4L.Dot(a, a))); }