Created
December 15, 2016 14:42
-
-
Save FransBouma/2eaa34b7f6e0ab7110e46cdeb0cb79c9 to your computer and use it in GitHub Desktop.
Correct way to rotate in NIXXES engine's quaternion system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uses the current quaternion used by the game to calculate the new quaternion by first creating a new quaternion from the angle delta's and multiplying it with the | |
// current look quaternion like: angleQ * currentLookQ. This new quaternion is then used as the new game quaternion. | |
XMVECTOR Camera::CalculateLookQuaternion(XMVECTOR currentLookQ) | |
{ | |
// Game has Y into the screen. roll is therefore used for Y. pitch / yaw have to be negative due to the alignment of the axis vs what the user expects. | |
// Game will create tilt when rotated, as Y is into the screen. | |
/* | |
// WORKS, but creates massive tilt. | |
XMVECTOR angleQ = XMQuaternionRotationRollPitchYaw(-m_pitchDelta, m_rollDelta, -m_yawDelta); | |
XMVECTOR toReturn = XMQuaternionMultiply(angleQ, currentLookQ); | |
*/ | |
// alternative method, separated calculations, no tilt. Trick is in swapping order of (xQ*currentQ) * zQ. Doing it as zQ* (xQ*currentQ) will introduce tilt. | |
XMVECTOR xQ = XMQuaternionRotationNormal(XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f), -m_pitchDelta); | |
XMVECTOR yQ = XMQuaternionRotationNormal(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), m_rollDelta); | |
XMVECTOR zQ = XMQuaternionRotationNormal(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), -m_yawDelta); | |
XMVECTOR tmpQ = XMQuaternionMultiply(xQ, currentLookQ); | |
tmpQ = XMQuaternionMultiply(tmpQ, zQ); | |
XMVECTOR qToReturn = XMQuaternionMultiply(yQ, tmpQ); | |
XMQuaternionNormalize(qToReturn); | |
return qToReturn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment