Hello Guest

[SOLVED] OpenGL Y axis angles?

  • 7 Replies
  • 9882 Views
*

Offline matanui159

  • *
  • 30
  • KABOOM
[SOLVED] OpenGL Y axis angles?
« on: March 19, 2014, 00:40:13 »
I am making a game engine and a found this problem with the y axis:
  • if i position something at -200 on the z pane it should is in front of the camera
  • if i position something at 200 on the x pane and:
  • - rotate it -90 it should be in front of the camera
  • - rotate it 90 it should be behind the camera

This is not the case.
-90 is behind
90 is in front

At the moment i am just inverting the angle when you try to rotate on the y axis
I have not found this problem with any other axis

Why is this happening?
How do i fix it?

p.s. this is my first time starting a topic on this forum
THX  :)
« Last Edit: March 29, 2014, 01:07:58 by matanui159 »
ALGORITHM
A word used by programmers when they do not want to explain what they did.

WEE :)

*

Offline matanui159

  • *
  • 30
  • KABOOM
Re: OpenGL Y axis angles?
« Reply #1 on: March 19, 2014, 11:03:58 »
Is anyone going to answer this?
Sorry if I'm being impatient...
I just need this fixed
ALGORITHM
A word used by programmers when they do not want to explain what they did.

WEE :)

*

Offline abcdef

  • ****
  • 336
Re: OpenGL Y axis angles?
« Reply #2 on: March 19, 2014, 15:15:21 »
Hi

I'd be patient, people are from all different regions of the world and this is forum is typically a lwjgl forum. (opengl.org has its own forums)

To answer your question you are seeing expected behavior. You can use your eyes to replicate the very problem. If you rotate your head clockwise, objects will appear to your eyes to have rotated anti/counter clockwise. If you move your head forwards towards an object, your eye effectely sees that object come closer to you. Your monitor are your eyes to opengl. Your monitor doesn't move so the effect you see is like the examples I described above

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: OpenGL Y axis angles?
« Reply #3 on: March 19, 2014, 20:15:35 »
You haven't said how you are rotating things so I'm going to assume you are using the glRotate() function. Now this is from that functions documentation:

Quote
This rotation follows the right-hand rule, so if the vector x y z points toward the user, the rotation will be counterclockwise.

In short, this happens because of maths. I'm not a mathematician so I can't explain it any further than via the right hand rule. I could throw some examples at you but I doubt it would help. Sorry if I seem blunt.

If you want a solution that doesn't involve negating the y-angle, then negate the vector you pass to the function. Ie.

Code: [Select]
//Instead of
glRotatef(yAngle, 0, 1, 0);

//Use
glRotatef(yAngle, 0, -1, 0);

I don't particularly see that this solution is better than the one you already have but it's up to you.
 

*

Offline matanui159

  • *
  • 30
  • KABOOM
Re: OpenGL Y axis angles?
« Reply #4 on: March 19, 2014, 21:49:36 »
Hi

I'd be patient, people are from all different regions of the world and this is forum is typically a lwjgl forum. (opengl.org has its own forums)

To answer your question you are seeing expected behavior. You can use your eyes to replicate the very problem. If you rotate your head clockwise, objects will appear to your eyes to have rotated anti/counter clockwise. If you move your head forwards towards an object, your eye effectely sees that object come closer to you. Your monitor are your eyes to opengl. Your monitor doesn't move so the effect you see is like the examples I described above

Thx for your help, but I'm rotating the objects around the player, not rotating the player



You haven't said how you are rotating things so I'm going to assume you are using the glRotate() function. Now this is from that functions documentation:

Quote
This rotation follows the right-hand rule, so if the vector x y z points toward the user, the rotation will be counterclockwise.

In short, this happens because of maths. I'm not a mathematician so I can't explain it any further than via the right hand rule. I could throw some examples at you but I doubt it would help. Sorry if I seem blunt.

If you want a solution that doesn't involve negating the y-angle, then negate the vector you pass to the function. Ie.

Code: [Select]
//Instead of
glRotatef(yAngle, 0, 1, 0);

//Use
glRotatef(yAngle, 0, -1, 0);

I don't particularly see that this solution is better than the one you already have but it's up to you.
 

This could probably help, if I knew what it meant...
Thx for your help anyway, I'll have a look at it and play around a bit as well  :)
ALGORITHM
A word used by programmers when they do not want to explain what they did.

WEE :)

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: OpenGL Y axis angles?
« Reply #5 on: March 19, 2014, 21:57:17 »
Yeah I think most of what I said you have to just accept or get a degree in pure mathematics or something (Like I said, I don't have a degree in pure maths so I can't really be sure you'll even understand then).

If it's anything but the maths you don't get then be a little more specific and I'll try to elaborate as best I can.

*

Offline matanui159

  • *
  • 30
  • KABOOM
Re: OpenGL Y axis angles?
« Reply #6 on: March 19, 2014, 22:40:19 »
I'll try to just accept it then...
Btw what did you mean by 'right hand rule'?
ALGORITHM
A word used by programmers when they do not want to explain what they did.

WEE :)

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: OpenGL Y axis angles?
« Reply #7 on: March 22, 2014, 11:56:05 »
http://en.wikipedia.org/wiki/Right-hand_rule#Direction_associated_with_a_rotation. This explains it (kind of). It's a bit of a weird thing as far as I'm concerned. Also I couldn't find anything explaining it specifically concerning rotation matrices, only showing principles of physics. Still, it's all about the cross product anyway at it's core.