Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Mirrors a heading rotation (z-forward) across a plane
- /// </summary>
- /// <param name="origHeading">the rotation to mirror</param>
- /// <param name="planeNormal">the normal of the plane across which to mirror the rotation</param>
- /// <returns>the mirrored rotation</returns>
- static public Quaternion MirrorHeading(Quaternion origHeading, Vector3 planeNormal)
- {
- Vector3 origHeadingVec = origHeading * Vector3.forward;
- Vector3 origUpVec = origHeading * Vector3.up;
- if (Vector3.Dot(origHeadingVec, planeNormal) < 0.0f) { planeNormal = -planeNormal; }
- Vector3 newHeadingVec = MirrorVector(origHeadingVec, planeNormal);
- Vector3 newUpVec = MirrorVector(origUpVec, planeNormal);
- return Quaternion.LookRotation(newHeadingVec, newUpVec);
- }
- #endregion
- #region Vector Math
- static public Vector3 MirrorVector(Vector3 vector, Vector3 normal)
- {
- Vector3 flipVec = normal * Vector3.Dot(vector, normal); // (project the vector onto the normal, then...)
- return vector - (2f * flipVec); // (subtracting 1x gets you v on the plan, subtracting 2x gets you the mirror)
- }
Advertisement
Add Comment
Please, Sign In to add comment