Discussion:
3D coordinate system with Z=Up - rotation directions and starting axis ?
Add Reply
R.Wieser
2025-01-26 07:13:47 UTC
Reply
Permalink
Hello all,

I've used OpenGL to create a basic 3D coordinate system (which works) with
Z=Up, X=to the right and Y=into the screen.

The thing is that I've picked rotation directions and starting axis for
those rotations in a "I need it to work, and this does" way. :-|

Now I'm at a point where I want to make it conform to a/the standard, and
have done a few websearches for 3D coodinate systems and their specifics.

Alas, although I've been able to find pictures of the Y=Up and Z=Up
coordinate systems and even a Z=up, rotation=anti-clockwise description
(right-hand rule), I could not find anything more - which suprises me to be
honest. :-|



What I'm looking for, for both the Y=up and Z=Up coordinate systems :

rotation directions for all three axis/planes, as well as starting axis*.

* Although I've found that for Z=Up the rotation direction is
counter-clockwise I do not know at with axis it starts: +X ? +Y ?
Perhaps -X or -Y ?. No idea. :-(

Regards,
Rudy Wieser
Paul
2025-01-26 10:36:36 UTC
Reply
Permalink
Post by R.Wieser
Hello all,
I've used OpenGL to create a basic 3D coordinate system (which works) with
Z=Up, X=to the right and Y=into the screen.
The thing is that I've picked rotation directions and starting axis for
those rotations in a "I need it to work, and this does" way. :-|
Now I'm at a point where I want to make it conform to a/the standard, and
have done a few websearches for 3D coodinate systems and their specifics.
Alas, although I've been able to find pictures of the Y=Up and Z=Up
coordinate systems and even a Z=up, rotation=anti-clockwise description
(right-hand rule), I could not find anything more - which suprises me to be
honest. :-|
rotation directions for all three axis/planes, as well as starting axis*.
* Although I've found that for Z=Up the rotation direction is
counter-clockwise I do not know at with axis it starts: +X ? +Y ?
Perhaps -X or -Y ?. No idea. :-(
Regards,
Rudy Wieser
https://www3.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html

3. Vertices, Primitives, Fragment and Pixels

3.1 3D Graphics Coordinate Systems

OpenGL adopts the Right-Hand Coordinate System (RHS). In the RHS, the x-axis
is pointing right, y-axis is pointing up, and z-axis is pointing out of the screen.

With your right-hand fingers curving from the x-axis towards the y-axis,
the thumb is pointing at the z-axis. RHS is counter-clockwise (CCW).
The 3D Cartesian Coordinates is a RHS.

Some graphics software (such as Microsoft Direct3D) use Left-hand System (LHS),
where the z-axis is inverted. LHS is clockwise (CW).

In this article, we shall adopt the RHS and CCW used in OpenGL.

*******

Try it their way and see if it works ?

Loading Image...

Paul
R.Wieser
2025-01-26 12:17:31 UTC
Reply
Permalink
Paul,
Post by Paul
Post by R.Wieser
rotation directions for all three axis/planes, as well as starting axis*.
...
Post by Paul
https://www3.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html
Have you noticed that that doesn't talk about even just the angle origin of
the Up-axis, let alone the Horizontal and perpendicular-to-the-screen ones ?
:-(

I've just spend yesterday evening and the better part of this morning (upto
now) going thru webpage-after-webpage, and have only been able to find an
indirect reference to what the origin of the Up-axis rotation angle
(probably) is (the +X axis).
Post by Paul
Try it their way and see if it works ?
How ? Their "3D Graphics Coordinate Systems" chapter is two short
paragraphs with a picture of how they set up their axis, but nothing else.
:-| (I did search the OpenGL webpage for both "angle" as well as "rotation"
and found nothing relevant to my question)

That was why I had to pick my own angle directions and origins thereof.
Camera movement works fine with them.

And yes, that Y=Up was what I implemented first and on what I based my Z=Up
version, after which I noticed that the data I extracted from a game doesn't
match up with it angle wise.

Hence my question. Any idea ?

Regards,
Rudy Wieser
Paul
2025-01-26 20:20:49 UTC
Reply
Permalink
Post by R.Wieser
Paul,
Post by Paul
Post by R.Wieser
rotation directions for all three axis/planes, as well as starting axis*.
...
Post by Paul
https://www3.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html
Have you noticed that that doesn't talk about even just the angle origin of
the Up-axis, let alone the Horizontal and perpendicular-to-the-screen ones ?
:-(
I've just spend yesterday evening and the better part of this morning (upto
now) going thru webpage-after-webpage, and have only been able to find an
indirect reference to what the origin of the Up-axis rotation angle
(probably) is (the +X axis).
Post by Paul
Try it their way and see if it works ?
How ? Their "3D Graphics Coordinate Systems" chapter is two short
paragraphs with a picture of how they set up their axis, but nothing else.
:-| (I did search the OpenGL webpage for both "angle" as well as "rotation"
and found nothing relevant to my question)
That was why I had to pick my own angle directions and origins thereof.
Camera movement works fine with them.
And yes, that Y=Up was what I implemented first and on what I based my Z=Up
version, after which I noticed that the data I extracted from a game doesn't
match up with it angle wise.
Hence my question. Any idea ?
Regards,
Rudy Wieser
I would investigate my environment graphically.

Here, someone is experimenting with his impression of what spherical
coordinates would be. He defines a theta, a phi, a radius R. The math is
wrong, because one trip around the sphere is 2*PI and the routines do not
use degrees the way he is attempting to do it. Instead of 0..360 degrees,
his loops should investigate 0..2PI for the spherical coordinates.
We would set the r=1 for the purposes of plotting points on the unit sphere.

https://stackoverflow.com/questions/61302642/using-spherical-coordinates-in-opengl

float x = r * sin(theta) * cos(phi);
float y = r * sin(theta) * sin(phi);
float z = r * cos(theta);

Part of the fun of your first attempts at three-space, is setting the Viewpoint.
what you see in the frame won't make much sense, unless the view point is
in a good spot. You could for example, select 45 degrees, 45 degrees, radius anywhere
from 2..10 units, and then "watch" as you draw elements on the unit sphere.

Paul
R.Wieser
2025-01-27 05:57:58 UTC
Reply
Permalink
Paul
Post by Paul
I would investigate my environment graphically.
:-) Thats how got in this mess. The (classic) OpenGL projection causes
you to look over the perpendicular-to-the-screen axis (-Z for Y=Up, +Y for
Z=Up), so I assumed that was the origin of the horizontal rotation. And
for some reason I implemented it going clockwise.
Post by Paul
Part of the fun of your first attempts at three-space, is setting the
Viewpoint.what you see in the frame won't make much sense, unless
the view point is in a good spot.
Indeed. That is why I start with drawing 3 long boxes in red, green and
blue representing the X, Y and Z axis at the origin as a visual reference,
and put the camera a bit "back" and "up"
Post by Paul
and then "watch" as you draw elements on the unit sphere.
Yep, done that. Translating works and so do rotations. The problem with
that is that all that stuff is symetrical, giving zero hints to what the
rotation directions or their origins should be. I just got it to work with
my "starts at -Z (into the monitor) and rotates clockwise" implementation.

I currently have added, to my Z=Up version, a 90 degree rotation to the
projection matrix (and updated the camera movement code accordingly) so that
I initially look over the +X axis, and changed the horizontal rotation to
start at that axis and go counter-clockwise. Lets see if that works
better. Still will have to make guesses for the other two though.


Funny how something basic like this (angle directions and origins in a 3D
coordinate system) is not described anywhere. :-(

By the way, the
http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm
website where I got some of my info from didn't quite help with this picture
Loading Image...
where the "heading" angle starts from the +Z axis. :-|

Also this one : http://www.euclideanspace.com/maths/standards/index.htm .
Almost averything seems to be there - but for what I'm looking for ...

Regards,
Rudy Wieser
R.Wieser
2025-01-29 11:18:38 UTC
Reply
Permalink
Post by R.Wieser
Now I'm at a point where I want to make it conform to a/the standard,
and have done a few websearches for 3D coodinate systems and their
specifics.
The reason for this is that a game I'm tinkering with seems to have its
objects (cars, boats, NPCs) (with +Z=Up) aligned with the +Y (into the
screen) axis when its rotation is Zero (identity matrix). And that means
that when I want to calculate something "in front" of such an object
troubles arise, as the standard sin/cos expect the angle to start at the +X,
not at +Y axis.

I've tried to create a projection (by applying an glRotate of 90 degrees
over the Up axis) that looks over the +X axis, but that just moves the
"angle is off by 90 degrees" problem from one point to another other. :-(

So, maybe the question is : how do I set up a projection which allows the
objects, at rotation Zero, to be looking over the +X axis.

Regards,
Rudy Wieser

Loading...