Quaternion - Even when CryEngine draws it out, I still don't get it

#1
So I read this article
I prefer thinking of a quaternion as an object that contains a vector and a scalar.
so I just vaguely understand quaternion as a vector with weight/scalar.
So I tried to visualize it in CryEngine.

Code: Select all

if (m_pCharacterController->IsWalking())
{
Vec3 dir = m_pCharacterController->GetVelocity().GetNormalized();
dir.z = 0.0f;

IPersistantDebug *pDebug = gEnv->pGameFramework->GetIPersistantDebug();
if (pDebug)
{
pDebug->Begin("InteractionVector", false);
Vec3 pos = m_pEntity->GetWorldPos() + m_pEntity->GetWorldRotation().GetColumn2() * 2.0f;
pDebug->AddQuat(pos, Quat(dir), 1.0f, COLOR_RED, 25.0f);
pos += m_pEntity->GetWorldRotation().GetColumn1() * 2.0f;
pDebug->AddDirection(pos, 1.0f, dir, COLOR_RED, 25.0f);
}
}
As you can see, the code above will draw the velocity vector and velocity quaternion (I guess). Image But I don't understand what the meaning of the quaternion in the image above. 3 lines red,green,blue and a red square in the middle - I don't get what it's trying to show?
Small tips
How to add an image to a forum post
[C++] How to smoothly turn your character

Re: Quaternion - Even when CryEngine draws it out, I still don't get it

#2
Ok, so there is some hint
A quaternion doesn't have a direction by itself. It is a rotation. It can be used to rotate any vector by the rotation it represents. Just multiply a Vector3 by the quaternion.

Code: Select all

Vector3 targetForward = targetRot * Vector3.forward;
Vector3 targetUp = targetRot * Vector3.up;
What axis you need you have to figure out yourself since your code is just an abstract collection of code fragments.
---------------------------------
Just to be absolutely clear for beginners: When you say "Which way is this Quaternion's up?" or "Which way does this Quaternion point forward?" what you probably actually mean is:
"If you take something which is standing straight up and forward, and apply the Quaternion to it, which way is the forward vector now?"
The example code above provides exactly that information.
Small tips
How to add an image to a forum post
[C++] How to smoothly turn your character

Re: Quaternion - Even when CryEngine draws it out, I still don't get it

#3
Now think about the m_lookOrientation
with this code to add it to debug

Code: Select all

IPersistantDebug *pDebug = gEnv->pGameFramework->GetIPersistantDebug();
if (pDebug)
{
pDebug->Begin("InteractionVector", false);
Vec3 pos = m_pEntity->GetWorldPos() + m_pEntity->GetWorldRotation().GetColumn2() * 2.0f;
pDebug->AddQuat(pos, m_lookOrientation, 1.0f, COLOR_RED, 25.0f);
}
Image I guess m_lookOrientation.GetColumn0() is the red line (right of the character).
I guess m_lookOrientation.GetColumn1() is the red line (forward of the character).
I guess m_lookOrientation.GetColumn2() is the blue line (up of the character).
Small tips
How to add an image to a forum post
[C++] How to smoothly turn your character

Who is online

Users browsing this forum: No registered users and 4 guests