Login  Register

Re: Camera Direction Messup

Posted by gouessej on Nov 26, 2014; 10:17am
URL: https://forum.jogamp.org/Camera-Direction-Messup-tp4033636p4033640.html

Hi

If you're allowed to use some source code in your project, please look at how I implemented the exact same thing in Truly Unusual Experience of Revolution® almost 8 years ago. I spent several months to make it work which was difficult because AWT isn't very good to achieve that (and don't create a Robot instance each time you want to move the mouse cursor).

You have to store the direction and to update it when you turn. You have to use the direction when you move forward or backward.

Take care of the units (degrees, radians). glRotatef takes degrees in input whereas Math.cos and sin take radians in input.

Edit.: Actually, you already take care of the units.

Edit.2: In my code, it looks like this:
x += 0.1 * (float)Math.sin(Math.toRadians(yaw - 90));
z += 0.1 * (float)Math.cos(Math.toRadians(yaw - 90));

Edit.3: You use a break then you can't strafe and move forward at the same time. Rather use several flags and conditions to update the abscissa (x) and the applicate (z).

Edit.4: I use gluLookAt with the up vector at (0,1,0) instead of using glRotate.
Julien Gouesse | Personal blog | Website