Issue rotating camera

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue rotating camera

MichaelMitchell
I am having trouble rotating my camera.
I move it based on two angles (in radians).
It can move left to right just fine.
When I look straight up it starts slowing down and will stop.
Also, when the camera has turned 90 degrees right or left, it will not look up or down, it will do an odd spinning thing.

Here is my code for adding the angles to the camera direction:

direction = new Vec3( FloatMatrix.multiplyMatrix( FloatMatrix.getAxisRotationMatrix( rot.y, UP ), new FloatMatrix( direction ) ) );
Vec3 toRotateAround = Vec3.cross( direction, UP );
direction = new Vec3( FloatMatrix.multiplyMatrix( FloatMatrix.getAxisRotationMatrix( -rot.x, toRotateAround ), new FloatMatrix( direction ) ) );


Also, my LookAt matrix for the camera:

Vec3 s = Vec3.cross( direction, up );
                s = s.getUnitVec3();
                Vec3 u = Vec3.cross( s, direction );
                float[] an = {
                                s.x, s.y, s.z, 0.0f,
                                u.x, u.y, u.z, 0.0f,
                                -direction.x, -direction.y, -direction.z, 0.0f,
                                0.0f, 0.0f, 0.0f, 1.0f
                };

If further clarification is needed, please ask.
Thank you for your time,
Michael Mitchell
Reply | Threaded
Open this post in threaded view
|

Re: Issue rotating camera

Sven Gothel
Administrator
On 05/10/2014 01:14 PM, MichaelMitchell [via jogamp] wrote:
> I am having trouble rotating my camera.
> I move it based on two angles (in radians).
> It can move left to right just fine.
> When I look straight up it starts slowing down and will stop.
> Also, when the camera has turned 90 degrees right or left, it will not look up
> or down, it will do an odd spinning thing.

Might be a case of 'Gimbal-Lock'

http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q34


Thats why we have com.jogamp.opengl.math.Quaternion,
see
<http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/com/jogamp/opengl/math/Quaternion.java;h=319cbad50f9f212a94eed69186b35a75385cab37;hb=HEAD>.

You may use your fav. IDE and check it's usage (call-tree).

Note: Latest fixed version will be part of release 2.2,
2.1.5 contains a buggy untested version.

~Sven



signature.asc (894 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Issue rotating camera

MichaelMitchell
I don't understand how it could be the rotation matrix.
I think it has to do setting the orientation of the camera.

I dunno, could you please elaborate more, I have read some sources and still don't know how this applies.