# Using Pure Quaternion for model/camera

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

## Recommended Posts

Hey guys, I've fallen in love with the quaternion world, however, I've been having problems using them in certain aspects. I'm building a Half-Life 2 mod, and in this mod I'm trying to use quaternions to rotate my model, and my camera angles. Rotating a vector is pretty simple. However rotating a model to match the correct orientation of this vector to the ground normal is yielding me unwanted results. It's mostly with the rolling of the model. I have 3 unit vectors representing the Forward, Right, and UP vectors. My forward vector is the direction my object moves, which I'm constantly clipping to match perpendicular to the ground (UP) vector. EDIT: ---------------------------- I'm building a racing mod, and I'd like for karts to be able to drive over all surfaces as long as each surface is at a reasonable incline to the next. When I said I'm having trouble doing the orientation with quats it's mostly because I'm doing the math wrong. For matrixes, I use something like this and it gives me perfect orientation. VMatrix axis; axis.SetBasisVectors(pPlayer->m_vecForwardDir, pPlayer->m_vecRightDir, pPlayer->m_vecGroundNormal); MatrixToAngles( axis, angFinal ); angFinal is return as Euler angles. When I tried using quaternions, I believe my math went wrong in concating the quats. I did something like this for my camera orientation. float yawAng = pPlayer->m_flYawDirection; Quaternion qYaw, qPitch, qResult; AxisAngleQuaternion( pPlayer->m_vecGroundNormal, yawAng, qYaw ); AxisAngleQuaternion( pPlayer->m_vecRightDir, 30, qPitch ); QuaternionMult(qPitch, qYaw, qResult ); QuaternionAngles( qResult, angleDirection ); This effectly rotates my yaw to the direction i'm facing, and the pitch upwards 30 degrees. But when I go on ramps my roll begins tilting. I then began experimenting trying to rotate around the forward direction and setting it to a constant value, but I failed at concating the transforms, which would pretty much rotate my view around kinda like a sine wave depending on the direction I was facing. The reason I wanted to use quaternions is for the SLERP function quats have, I wasn't to sure how to slerp a matrix. [Edited by - OneEyed on July 25, 2007 1:13:59 PM]

##### Share on other sites
Quote:
 Original post by OneEyedMy question is how can I use quaternions to rotate my models Euler angles to match the orientation of these 3 vectors?I have pre-made quaternion functions for everything a quaternion can do. My goal here is to do my model rotation without the use of matrices as it currently seems, only matrices can fix my roll problem.
I've got to run at the moment so I can't go into as much detail as I'd like, but it seems you may have some misconceptions about the various rotation representations and their behavioral characteristics.

In particular, I'm a little confused by this sentence:
Quote:
 My goal here is to do my model rotation without the use of matrices as it currently seems, only matrices can fix my roll problem.
Can you perhaps restate this? Is it possible you wrote 'matrices' where you meant 'quaternions', or vice versa? As it is, I can't make much sense of it.

It might also be a good idea to provide a more detailed description of what sort of behavior you're after. 'HL2 mod' suggests standard FPS-style motion, but you also mention aligning the model with a surface normal, which isn't typical for FPSs. Anyway, a little clarification might be in order.

##### Share on other sites

Edited first post.

[Edited by - OneEyed on July 25, 2007 1:15:16 PM]

##### Share on other sites
The problem is that the player's basis vectors are not the vectors you want to rotate around. When you perform one of the axis rotations it changes the other axes. Those axes must then be rotated to account for the change in coordinate system.

Or look here for a page about converting rotation matrices to quaternions.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633725
• Total Posts
3013558
×