Hey everyone. I am working on a game where a character walks around the surface of a sphere (think Super Mario Galaxy), so I figured it would be wise to use quaternions for orientation since it is very important that the player and camera orientations work well. I understand the idea behind quaternions, but I don't really understand how to generate them in the first place... previously I had been storing an "up" vector and a "forward" vector to define my character's orientation, and had been doing Euler rotations to construct a rotation matrix. Each time my character moved, the up vector would be recalculated to be the vector from the center of the sphere to the player's position, and the forward vector would be the movement vector projected onto the plane that the player is standing on. I would like to have a similar way of constructing quaternions (where I can define it from and "up" and "forward" vector), but it seems that every resource that I have found online about quaternions explains how to use them for *rotations*, and not for *orientations*. I have found some source code online that supposedly implements the behavior I am looking for, but I don't really understand it and when I tried to implement it I wasn't getting the behavior I wanted.

Maybe I am thinking about quaternions all wrong? I'm not 100% sure what I'm asking, but I've been struggling with this all day to no avail. Given the description of my game, could someone who is experienced using quaternions suggest to me how they would go about using them?

Maybe I am thinking about quaternions all wrong? I'm not 100% sure what I'm asking, but I've been struggling with this all day to no avail. Given the description of my game, could someone who is experienced using quaternions suggest to me how they would go about using them?

Normally I would define construct quaternions by chaining together 'rotate around axis/angle' transforms. As for creating a quaternion from basis vectors, it should be basically the same as implementing something like 'lookAt'/'lookRotation' which seems to be based on converting it from a matrix from the various examples I found with google.

Thanks for the help. I'll look into that.

Do you have the link to the source you are talking about, or maybe just post it.

What part of implementing this gave you trouble? Are you using a math library and don't understand what to do with the code, or are you trying to do it yourself?

What part of implementing this gave you trouble? Are you using a math library and don't understand what to do with the code, or are you trying to do it yourself?

Gahh, I think I solved the issue I was having. I'm using the GLM math library (but slowly replacing it with my own structs, functions, etc.), and apparently matrix multiplication in GLM is reverse of what I was expecting. To apply a rotation matrix (that I was generating from my quaternion) to the model matrix I was doing

But I really had to do

This issue only popped up when I switched to quaternions because I was previously using a built-in GLM rotation function instead of calculating the matrix myself and doing the multiplication. Thanks for the help everyone, I think I got it working now :D

1 | model = rotation * model |

But I really had to do

1 | model = model * rotation |

This issue only popped up when I switched to quaternions because I was previously using a built-in GLM rotation function instead of calculating the matrix myself and doing the multiplication. Thanks for the help everyone, I think I got it working now :D

ClysmiC

Gahh, I think I solved the issue I was having. I'm using the GLM math library (but slowly replacing it with my own structs, functions, etc.), and apparently matrix multiplication in GLM is reverse of what I was expecting.

If you come from using DirectX or something then that's probably down to the difference between row-major and column-major vectors/matrices, it changes the order of things.