public void CreateOrthonormalBasis(out Vector3 u, out Vector3 v, out Vector3 n) { n = this.Normal; if (Mathf.Abs(n.x) >= Mathf.Abs(n.y)) { float num = Mathfex.InvSqrt(n.x * n.x + n.z * n.z); u.x = n.z * num; u.y = 0f; u.z = -n.x * num; } else { float num2 = Mathfex.InvSqrt(n.y * n.y + n.z * n.z); u.x = 0f; u.y = n.z * num2; u.z = -n.y * num2; } v = Vector3.Cross(n, u); }
public static void CreateOrthonormalBasis(out Vector3 u, out Vector3 v, ref Vector3 w) { if (Mathf.Abs(w.x) >= Mathf.Abs(w.y)) { float num = Mathfex.InvSqrt(w.x * w.x + w.z * w.z); u.x = -w.z * num; u.y = 0f; u.z = w.x * num; v.x = w.y * u.z; v.y = w.z * u.x - w.x * u.z; v.z = -w.y * u.x; return; } float num2 = Mathfex.InvSqrt(w.y * w.y + w.z * w.z); u.x = 0f; u.y = w.z * num2; u.z = -w.y * num2; v.x = w.y * u.z - w.z * u.y; v.y = -w.x * u.z; v.z = w.x * u.y; }
public void Include(ref Box3 box) { Box3 box2 = default(Box3); box2.Center = 0.5f * (this.Center + box.Center); Matrix4x4 matrix4x; Matrix4x4ex.CreateRotationFromColumns(ref this.Axis0, ref this.Axis1, ref this.Axis2, out matrix4x); Quaternion a; Matrix4x4ex.RotationMatrixToQuaternion(ref matrix4x, out a); Matrix4x4 matrix4x2; Matrix4x4ex.CreateRotationFromColumns(ref box.Axis0, ref box.Axis1, ref box.Axis2, out matrix4x2); Quaternion b; Matrix4x4ex.RotationMatrixToQuaternion(ref matrix4x2, out b); if (Quaternion.Dot(a, b) < 0f) { b.x = -b.x; b.y = -b.y; b.z = -b.z; b.w = -b.w; } Quaternion quaternion; quaternion.x = a.x + b.x; quaternion.y = a.x + b.y; quaternion.z = a.x + b.z; quaternion.w = a.x + b.w; float num = Mathfex.InvSqrt(Quaternion.Dot(quaternion, quaternion)); quaternion.x *= num; quaternion.y *= num; quaternion.z *= num; quaternion.w *= num; Matrix4x4 matrix4x3; Matrix4x4ex.QuaternionToRotationMatrix(ref quaternion, out matrix4x3); box2.Axis0 = matrix4x3.GetColumn(0); box2.Axis1 = matrix4x3.GetColumn(1); box2.Axis2 = matrix4x3.GetColumn(2); Vector3 zero = Vector3ex.Zero; Vector3 zero2 = Vector3ex.Zero; Vector3[] array = this.CalcVertices(); for (int i = 0; i < 8; i++) { Vector3 vector = array[i] - box2.Center; for (int j = 0; j < 3; j++) { float num2 = vector.Dot(box2.GetAxis(j)); if (num2 > zero2[j]) { zero2[j] = num2; } else if (num2 < zero[j]) { zero[j] = num2; } } } box.CalcVertices(out array[0], out array[1], out array[2], out array[3], out array[4], out array[5], out array[6], out array[7]); for (int i = 0; i < 8; i++) { Vector3 vector = array[i] - box2.Center; for (int j = 0; j < 3; j++) { float num2 = vector.Dot(box2.GetAxis(j)); if (num2 > zero2[j]) { zero2[j] = num2; } else if (num2 < zero[j]) { zero[j] = num2; } } } for (int j = 0; j < 3; j++) { box2.Center += 0.5f * (zero2[j] + zero[j]) * box2.GetAxis(j); box2.Extents[j] = 0.5f * (zero2[j] - zero[j]); } this = box2; }