# Quaternions

This topic is 2859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, as my previous posts might sound a bit unclear, i have decided to start over and ask the basics, as i just can't get this working.

My Exporter exports Translation and Rotation per frame for each bone.

- Translation ( CVector3 )

- Rotation ( CQuaternion )

Engine when doing Tick(), updates only those vertexes that are blended with Bone ( linked to bone ) - this is, how it gets done:

 for( everyVertex that has a bone linked ) { // Grab Translation of this bone in this frame CVector3 vBoneTranslation = m_vBones[iVertexBoneID].m_vTranslations[m_fCurrentFrame]; CVector3 vBoneTranslationN = m_vBones[iVertexBoneID].m_vTranslations[m_fCurrentFrame+1]; // Grab Rotation of this bone in this frame Quaternion qBoneRotation = m_vBones[iVertexBoneID].m_qRotations[m_fCurrentFrame]; Quaternion qBoneRotationN = m_vBones[iVertexBoneID].m_qRotations[m_fCurrentFrame+1]; // Apply rotation to original vertexes CVector3 vTempPos = qBoneRotation * vPos; // Apply translation to vTempPos vTempPos += vBoneTranslation; } ... // Update the VBO with vertexes that were changed ... 

The thing is, translation works properly - but i can't get this Rotation to work, here is the CQuaternion operator* definition.

 CVector3 CQuaternion::operator*(CVector3 v) { // This function is a complex function that calculates the // result of multiplying a quaternion by a vector. We perform // three calculations for different parts of the whole equation // and then add them all up to return the result: // // ResultVector = // ( vec * ( 2w^2 - 1) ) + (2 * (q_xyz dot vec) * q_xyz) + (2w * (q_xyz cross vec)) // First we store the x,y,z of the quaternion in a CVector3 CVector3 q(x, y, z); // The is the first part of the equation: ( vec * ( 2w^2 - 1) ) CVector3 t1 = v * (2.0f * w * w - 1.0f); // This is the second part of the equation: (2 * (q_xyz dot vec) * q_xyz) CVector3 t2 = 2.0f * q.Dot(v) * q; // This is the third and final part of the equation: (2 * w * (q_xyz cross vec)) CVector3 t3 = 2.0f * w * q.Cross(v); // Now add up all the vectors and return the final resultant vector return t1 + t2 + t3; } 

I would like you guys to have a look at the operator* definition and confirm it is ok, before i write how do i get the Quaternions from MAX.

Thanks and sorry for previous duplicates, as it was caused by lagged browser.

##### Share on other sites
I haven't checked your code, but the way one usually goes about applying the rotation represented by a quaternion to a vector is this:
rotated_v = q * v * conj(q)
where v is interpreted as a quaternion by assigning it a 0 real part.

To know if your code is working, set up a few simple examples (rotations of 90 degrees along different axes will do).

##### Share on other sites

I haven't checked your code, but the way one usually goes about applying the rotation represented by a quaternion to a vector is this:
rotated_v = q * v * conj(q)
where v is interpreted as a quaternion by assigning it a 0 real part.

To know if your code is working, set up a few simple examples (rotations of 90 degrees along different axes will do).

Thanks alvarao, let me check this out now and i'll post the results..

##### Share on other sites
Ok, this works like a charm, but the problem was due to 3DS MAX transformations when Physique was applied. This topic can be closed, as the root cause is Max Exporting functions, that i have posted here:

http://www.gamedev.net/topic/617380-3ds-max-exporting-object-vertexes-positions-and-physique/

Still in trouble, but at least not with quaternions..

Thanks

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 23
• 11
• 25