Okay, so I was following this tutorial to help me with making a camera in OpenGL: http://nehe.gamedev.net/data/articles/article.asp?article=08
So I followed it, and after some struggling, finally had a solution where I now had 3 vectors that represented the 3 axes of my camera.
The problem though? I can't figure out how to use that information to actually get the right rotations/translations! I tried using gluLookAt, using the camera's position for the first parameters, then the Z axis of the camera for the target, and the Y axis for the up parameters. The result is that the camera never stops looking at a single point, regardless if I move up/down/left/right, and rotations behave even more weirdly...
Am I taking the complete wrong approach? I've considered using quaternions to somehow calculate the transformations I need, but can't figure out how to get the parameters I need for it/ how to get started... essentially I just want a simple FPS-like camera to begin with, where I can move around, and look up/down and to the sides (previously I had it mostly working, except when looking up and then turning around, the rotation screwed up...)
General or specific help would be much appreciated! Because I've been working on this for hours and hours, and the situation just isn't improving...
To sum it up... I need help making a camera that can yaw/pitch/roll... without being stuck to staring at a single point.
开发者_Go百科EDIT: Okay, so, apparently rotating in the correct order can really help out! Silly me. Regardless, I'd still be interested to know how if I could use the three axes of my camera to form a quaternion for my transformations.
I tried using gluLookAt, using the camera's position for the first parameters, then the Z axis of the camera for the target, and the Y axis for the up parameters.
The second set of parameters isn't the look-at direction, but the look-at position. You need to take the camera position and offset it by the Z-axis to get a look-at position in the direction you want to look in.
Regardless, I'd still be interested to know how if I could use the three axes of my camera to form a quaternion for my transformations.
Yes. You turn them into a matrix, then convert the matrix into a quaternion. There are many online resources that explain the process of converting a rotation matrix into a quaternion.
精彩评论