Ello! As the title indicates, I'm making a free flying camera in which the rotation component is defined by a quaternion. I've been wrestling with it for quite a while, making my own quaternion class and incorporating it into my camera class. I've run into some problems with trying to decipher C++ example code into Java code and understanding quaternions in general. Ergo, I have some questions before I dive into this never ending wrestling match with camera controls. - I've mostly based my Quaternion code on this guy's http://www.youtube.com/user/BSVino?feature=watch tuts and the "3D math primer for graphics and game development" book.

Q: Using mouse deltaX and deltaY to rotate the camera, do I multiply or SLERP?

Q: If SLERP is the way to go, what's the best way to do rotation, for example, about the y+ (or up relative to worldspace) axis? After a 180 deg rotation there isn't much to rotate to.

Q: If multiplication is the way to go, how exacly? Dividing x, y and z up into different Quaternions and then multiplying?

Q: I want to rotate my camera's pitch and yaw with mouse movement in the x and y direction. Yet I get some roll, which is quite annoying. How can I negate all roll? Or is there some way to convert my x&y movement into a quaternion with which I can multiply my camera rotation quaternion?

Q: LWJGL's Quaternion class seems to be missing SLERP and multiplyVector methods, should I just extend it and use my own? Or use a quaternion class entirely of my own?

Q: When is normalising your quaternion appropriate?

Questions may seem obvious, but my head is quite the cluster-f**k after contemplating quaternions a lot. Yet, I'm not asking for anyone to provide ready-made code/pseudocode (unless you feel it's the easiest way to explain), telling me to multiply a with b for example helps me enough.

Q1 + Q2:For a free-flying camera, you have only two components: a quaternion for orientation and a vec3 for position.

For looking around, you multiply the change in rotation with the current quaternion.For position movement, you store the change in movement in a temporary vec3, multiply it by the inverse of the orientation quaternion, then add it in to the position vec3.

When rendering, the view matrix is built by converting the orientation quaternion to a matrix and translating by the position vec3.

Now that I've found the time to integrate your solutions, and so graciously given code, into my code, I've run across some issues. First of all, I must say, the produced viewMatrix does its job well enough, no trippy deformations. (I managed those far too often) So, I seem to be doing something wrong >_<Yet, when I move forward (or in any direction for that matter) there is a non-forward deviation. Looking straight has no effect, WASD translates like it should, yet when I look up and press W I move down instead of up, rotating 90 degrees has the effect of opposite movement (W = backwards), and rotating 180 degrees negates the effect again. Any idea what might be causing this? - I considered this solved when realising, thanks to you, that multiplying the delta position vector with a quaternion was the way to go. (I was mucking around with w&s & forward Vector from the viewmatrix) Well, bummer, I guess. WHOA! Scratch that! Turns out that the orientation does not need to be inverted before multiplying the delta (change in position) vector. I guess it's because the multiply vector by quaternion already does the q*v*-q, wait that might not make sense... But it works now!

Yet one thing remains. (might be able to solve this myself given enough shower-contemplating and in-bed-sleep-stalling-contemplation)Second, how do I negate rotation about the z axis? Meaning, I don't want roll, just yaw and pitch. Roll still happens when moving the mouse diagonally, an effect of using quaternions I guess.

Concerning the deleted portion: that's the behavior when you multiply the delta by the original. The correct behavior is when you multiply the delta by the inverse, so you must be doing something wrong, post code

Second part: simple, you have to think about what space is being multiplied by. Since you don't want roll, you want horizontal movements to be fixed on the world's X-axis, therefore you should multiply the current orientation with the Quaternion created using (0, 1, 0) as the rotation angle (for Mouse.getDX()) so it looks like this:

Here goes the code dump! Strangely enough, all my issues have been solved by partially doing the opposite of what you're suggesting I guess it might be caused by my chaotic shenanigans constantly adding functionality and trying to make the code work.

Here's some of the code bits, first one is the rotate method in my QuaternionCamera class. Do note me using your suggestion on y (pitch) instead of x .

Since my endless mucking around with my code the last months, the problem might be outside these methods, so I'll post my QuaternionCamera, InputManager and Quaternion (your code) classes on pastebin. The Quaternion class was edited a bit to make it work with LWJGL's Vector3f and Matrix4f classes, and prewritten code which uses "mul" instead of "mult" ( I blame lwjgl! )QuaternionCamera: http://pastebin.com/fKVe6cJNInputManager: http://pastebin.com/NhhqpCv5Quaternion: http://pastebin.com/48Vq9UhP

When fidgeting around with the viewMatrix, I had indeed noticed the position being the inverse of the world position, or at least the position I used for the modelMatrix. Stupidly, I let it fly because it was of no inconvenience... yet. Also since I had no idea what the implications were and how to deal with it.

I'll adapt my code later today, gotta catch the bus to college. I plan on making a video of the result, detailing the functionality I have in the program as of now. ( To hand in for a free choice ects assignment, it's not for a course, there isn't even a Java course ) I'll post it in this thread too, along with most of the code so future newbs like me won't have to take months to figure it out. With your permission of course, since the Quaternion & some, if not most, of the camera code is yours.

I guess I shouldn't cheer before editing the solution into my code... Got some typical problems, rotating still causes increasing roll when I pan my cam 90 deg to the side, 180 = no roll again. Plus pointing down makes the cam go up again when pressing forward, same effect on translation in other directions.

Sorry for the late reaction, college kinda screwed me over with quite the workload. I hope you, or someone else is interested in looking into my renderer class and shaders. I've looked through it myself and can't find anything out of place.

If someone knows a good book/link that details this kind of stuff, I'd love that too.

// Setup what to do when the texture has to be scaledGL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);

// GL20.glGetShader was deprecated, was told to use GL20.glGetShaderi. Still takes the same params though...if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {System.err.println("Could not compile shader.");System.exit(-1); }

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org