public static Vec3 operator *(Quarentenion rotation, Vec3 point) { Quarentenion qPoint = Euler(point); qPoint *= rotation; return(qPoint.eulerAngles); }
// // Resumen: // Interpolates between a and b by t and normalizes the result afterwards. The parameter // t is not clamped. // // Parámetros: // a: // // b: // // t: public static Quarentenion LerpUnclamped(Quarentenion a, Quarentenion b, float t) { Quarentenion difference = new Quarentenion(b.x - a.x, b.y - a.y, b.z - a.z, b.w - b.w); Quarentenion differenceLerped = new Quarentenion(difference.x * t, difference.y * t, difference.z * t, difference.w * t); return(new Quarentenion(a.x + differenceLerped.x, a.y + differenceLerped.y, a.z + differenceLerped.z, a.w + differenceLerped.w).normalized); }
public Quarentenion(Quarentenion q) { x = q.x; y = q.y; z = q.z; w = q.w; }
// // Resumen: // Creates a rotation which rotates from fromDirection to toDirection. // // Parámetros: // fromDirection: // // toDirection: public void SetFromToRotation(Vec3 fromDirection, Vec3 toDirection) { Quarentenion q = FromToRotation(fromDirection, toDirection); x = q.x; y = q.y; z = q.z; w = q.w; }
// // Resumen: // Creates a rotation with the specified forward and upwards directions. // // Parámetros: // view: // The direction to look in. // // up: // The vector that defines in which direction up is. public void SetLookRotation(Vec3 view, [DefaultValue("Vector3.up")] Vec3 up) { Quarentenion q = LookRotation(view, up); x = q.x; y = q.y; z = q.z; w = q.w; }
// // Resumen: // Creates a rotation with the specified forward and upwards directions. // // Parámetros: // view: // The direction to look in. // // up: // The vector that defines in which direction up is. public void SetLookRotation(Vec3 view) { Quarentenion q = LookRotation(view); x = q.x; y = q.y; z = q.z; w = q.w; }
public static MatrixRecargada TRS(Vec3 pos, Quarentenion q, Vec3 s) { MatrixRecargada matTrans = Translate(pos); MatrixRecargada matRot = Rotate(q); MatrixRecargada matScale = Scale(s); MatrixRecargada trs = matTrans * matRot * matScale; return(trs); }
public void Normalize() { Quarentenion normalQ = new Quarentenion(normalized); x = normalQ.x; y = normalQ.y; z = normalQ.z; w = normalQ.w; }
// // Resumen: // Returns the angle in degrees between two rotations a and b. // // Parámetros: // a: // // b: public static float Angle(Quarentenion a, Quarentenion b) { Quarentenion inv = Inverse(a); Quarentenion result = b * inv; float angle = Mathf.Acos(result.w) * 2.0f * Mathf.Rad2Deg; return(angle); }
public static MatrixRecargada Rotate(Quarentenion q) { MatrixRecargada mRot = identity; mRot.m00 = 1 - 2.0f * (q.y * q.y) - 2.0f * (q.z * q.z); mRot.m01 = 2.0f * (q.x * q.y) - 2.0f * (q.z * q.w); mRot.m02 = 2.0f * (q.x * q.z) + 2.0f * (q.y * q.w); mRot.m10 = 2.0f * (q.x * q.y) + 2.0f * (q.z * q.w); mRot.m11 = 1 - 2.0f * (q.x * q.x) - 2.0f * (q.z * q.z); mRot.m12 = 2.0f * (q.y * q.z) - 2.0f * (q.x * q.w); mRot.m20 = 2.0f * (q.x * q.z) - 2.0f * (q.y * q.w); mRot.m21 = 2.0f * (q.y * q.z) + 2.0f * (q.x * q.w); mRot.m22 = 1 - 2.0f * (q.x * q.x) - 2.0f * (q.y * q.y); return(mRot); }
// // Resumen: // Spherically interpolates between a and b by t. The parameter t is not clamped. // // Parámetros: // a: // // b: // // t: public static Quarentenion SlerpUnclamped(Quarentenion a, Quarentenion b, float t) { float num1; float num2; Quarentenion quaternion; float dot = (((a.x * b.x) + (a.y * b.y)) + (a.z * b.z)) + (a.w * b.w); bool neg = false; if (dot < 0f) { neg = true; dot = -dot; } if (dot >= 1.0f) { num1 = 1.0f - t; if (neg) { num2 = -t; } else { num2 = t; } } else { float num3 = (float)Math.Acos(dot); float num4 = (float)(1.0 / Math.Sin(num3)); num1 = ((float)Math.Sin(((1f - t) * num3))) * num4; if (neg) { num2 = (((float)-Math.Sin((t * num3))) * num4); } else { num2 = (((float)Math.Sin((t * num3))) * num4); } } quaternion.x = ((num1 * a.x) + (num2 * b.x)); quaternion.y = ((num1 * a.y) + (num2 * b.y)); quaternion.z = ((num1 * a.z) + (num2 * b.z)); quaternion.w = ((num1 * a.w) + (num2 * b.w)); return(quaternion); }
// // Resumen: // Returns a rotation that rotates z degrees around the z axis, x degrees around // the x axis, and y degrees around the y axis. // // Parámetros: // euler: public static Quarentenion Euler(Vec3 euler) { Quarentenion qX = identity; Quarentenion qY = identity; Quarentenion qZ = identity; float sin = Mathf.Sin(Mathf.Deg2Rad * euler.x * 0.5f); float cos = Mathf.Cos(Mathf.Deg2Rad * euler.x * 0.5f); qX.Set(sin, 0.0f, 0.0f, cos); sin = Mathf.Sin(Mathf.Deg2Rad * euler.y * 0.5f); cos = Mathf.Cos(Mathf.Deg2Rad * euler.y * 0.5f); qY.Set(0.0f, sin, 0.0f, cos); sin = Mathf.Sin(Mathf.Deg2Rad * euler.z * 0.5f); cos = Mathf.Cos(Mathf.Deg2Rad * euler.z * 0.5f); qZ.Set(0.0f, 0.0f, sin, cos); return(new Quarentenion(qX * qY * qZ)); }
// // Resumen: // Returns the Inverse of rotation. // // Parámetros: // rotation: public static Quarentenion Inverse(Quarentenion rotation) { return(new Quarentenion(-rotation.x, -rotation.y, -rotation.z, rotation.w)); }
// // Resumen: // Converts this quaternion to one with the same orientation but with a magnitude // of 1. // // Parámetros: // q: public static Quarentenion Normalize(Quarentenion q) { return(new Quarentenion(q.normalized)); }
// // Resumen: // Rotates a rotation from towards to. // // Parámetros: // from: // // to: // // maxDegreesDelta: public static Quarentenion RotateTowards(Quarentenion from, Quarentenion to, float maxDegreesDelta) { throw new NotImplementedException(); }
// // Resumen: // Spherically interpolates between a and b by t. The parameter t is clamped to // the range [0, 1]. // // Parámetros: // a: // // b: // // t: public static Quarentenion Slerp(Quarentenion a, Quarentenion b, float t) { t = Mathf.Clamp(t, 0, 1); return(SlerpUnclamped(a, b, t)); }
// // Resumen: // The dot product between two rotations. // // Parámetros: // a: // // b: public static float Dot(Quarentenion a, Quarentenion b) { return((a.x * b.x) + (a.y * b.y) + (a.z * b.z) + (a.w * b.w)); }