//-------------------------------------------------------------------------------------------------- public static void SupportEdge(Transform tx, Vec3 e, Vec3 n, out Vec3 aresult, out Vec3 bresult) { n = Transform.MulT(tx.rotation, n); Vec3 absN = Vec3.Abs(n); Vec3 a = new Vec3(), b = new Vec3(); // x > y if (absN.x > absN.y) { // x > y > z if (absN.y > absN.z) { a.Set(e.x, e.y, e.z); b.Set(e.x, e.y, -e.z); } // x > z > y || z > x > y else { a.Set(e.x, e.y, e.z); b.Set(e.x, -e.y, e.z); } } // y > x else { // y > x > z if (absN.x > absN.z) { a.Set(e.x, e.y, e.z); b.Set(e.x, e.y, -e.z); } // z > y > x || y > z > x else { a.Set(e.x, e.y, e.z); b.Set(-e.x, e.y, e.z); } } double signx = Sign(n.x); double signy = Sign(n.y); double signz = Sign(n.z); a.x *= signx; a.y *= signy; a.z *= signz; b.x *= signx; b.y *= signy; b.z *= signz; aresult = Transform.Mul(tx, a); bresult = Transform.Mul(tx, b); }
// http://box2d.org/2014/02/computing-a-basis/ public static void ComputeBasis(Vec3 a, ref Vec3 b, ref Vec3 c) { // Suppose vector a has all equal components and is a unit vector: a = (s, s, s) // Then 3*s*s = 1, s = sqrt(1/3) = 0.57735027. This means that at least one component of a // unit vector must be greater or equal to 0.57735027. Can use SIMD select operation. if (Math.Abs(a.x) >= (0.57735027)) { b.Set(a.y, -a.x, 0); } else { b.Set(0, a.z, -a.y); } b = Vec3.Normalize(b); c = Vec3.Cross(a, b); }
//-------------------------------------------------------------------------------------------------- public static void ComputeReferenceEdgesAndBasis(Vec3 eR, Transform rtx, Vec3 n, int axis, byte[] result, out Mat3 basis, out Vec3 e) { basis = new Mat3(); e = new Vec3(); n = Transform.MulT(rtx.rotation, n); if (axis >= 3) { axis -= 3; } switch (axis) { case 0: if (n.x > 0) { result[0] = 1; result[1] = 8; result[2] = 7; result[3] = 9; e.Set(eR.y, eR.z, eR.x); basis.SetRows(rtx.rotation.ey, rtx.rotation.ez, rtx.rotation.ex); } else { result[0] = 11; result[1] = 3; result[2] = 10; result[3] = 5; e.Set(eR.z, eR.y, eR.x); basis.SetRows(rtx.rotation.ez, rtx.rotation.ey, -rtx.rotation.ex); } break; case 1: if (n.y > 0) { result[0] = 0; result[1] = 1; result[2] = 2; result[3] = 3; e.Set(eR.z, eR.x, eR.y); basis.SetRows(rtx.rotation.ez, rtx.rotation.ex, rtx.rotation.ey); } else { result[0] = 4; result[1] = 5; result[2] = 6; result[3] = 7; e.Set(eR.z, eR.x, eR.y); basis.SetRows(rtx.rotation.ez, -rtx.rotation.ex, -rtx.rotation.ey); } break; case 2: if (n.z > 0) { result[0] = 11; result[1] = 4; result[2] = 8; result[3] = 0; e.Set(eR.y, eR.x, eR.z); basis.SetRows(-rtx.rotation.ey, rtx.rotation.ex, rtx.rotation.ez); } else { result[0] = 6; result[1] = 10; result[2] = 2; result[3] = 9; e.Set(eR.y, eR.x, eR.z); basis.SetRows(-rtx.rotation.ey, -rtx.rotation.ex, -rtx.rotation.ez); } break; } }
public void Set(double a, double b, double c, double d, double e, double f, double g, double h, double i) { ex.Set(a, b, c); ey.Set(d, e, f); ez.Set(g, h, i); }
//-------------------------------------------------------------------------------------------------- // Vec3 //-------------------------------------------------------------------------------------------------- public static void Identity(ref Vec3 v) { v.Set(0, 0, 0); }