Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is OpenGL coordinate system left-handed or right-handed?

I am trying to understand the OpenGL coordinate system. However, some tutorials say the default coordinate system is left handed (see http://www.c-sharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx) and others say it is right handed (see http://www.falloutsoftware.com/tutorials/gl/gl0.htm). Which is correct? I understand that we can transform one to the other by mirroring but I would like to know the default coordinates.

like image 258
341008 Avatar asked Nov 08 '10 13:11

341008


People also ask

Is coordinate system right hand?

Coordinates are usually right-handed. For right-handed coordinates the right thumb points along the z axis in the positive direction and the curl of the fingers represents a motion from the first or x axis to the second or y axis. When viewed from the top or z axis the system is counter-clockwise.

How does OpenGL coordinate system work?

OpenGL works in the following way: You start of a local coordinate system (of arbitrary units). This coordinate system is transformed to so called eye space coordinates by the model-view matrix (it is called model-view matrix, because it combines model and view transformations).

Is DirectX left or right-handed?

DirectX uses a left-handed system where the +Z part of the world coordinate extends into the screen, away from the viewer.

What are left-handed and right-handed coordinate system?

In this case, right-handedness is defined as any positive axis (x, y, or z) pointing toward the viewer. Left-handedness is defined as any positive axis (x, y, or z) pointing away from the viewer.


1 Answers

There is some confusion here.

enter image description here

OpenGL is right handed in object space and world space.

But in window space (aka screen space) we are suddenly left handed.

How did this happen?

The way we get from right-handed to left-handed is a negative z scaling entry in the glOrtho or glFrustum projection matrices. Scaling z by -1 (while leaving x and y as they were) has the effect of changing the handedness of the coordinate system.

For glFrustum,

enter image description hereenter image description here

far and near are supposed to be positive, with far > near. Say far=1000 and near=1. Then C= -( 1001 ) / ( 999 ) = -1.002.

See here for more details and diagrams.

From an orthographic perspective, glOrtho generates a matrix like this:

enter image description here

Here, left, right, bottom and top are just the coordinates for left vertical, right vertical, bottom horizontal, top horizontal clipping planes (resp).

The near and far planes, however, are specified differently. The near parameter is defined as

  • Near: The distance to the nearer depth clipping plane. This distance is negative if the plane is to be behind the viewer.

and far:

  • zFar The distance to the farther depth clipping plane. This distance is negative if the plane is to be behind the viewer.

Here we have a typical canonical view volume

canonical

Because the z multiplier is (-2/(far-near)), the minus sign effectively scales z by -1. This means that "z" is turned left handed during the viewing transformation, unbeknownst to most people as they simply work in OpenGL as a "right handed" coordinate system.

So, if you call

glOrthof(-1, 1, -1, 1, 10, -10) ; // near=10, FAR=-10, 

Then the NEAR PLANE is 10 units ahead of you. Where are you? Why, at the origin, with the x-axis to your right, the y-axis on top of your head, and your nose pointing down the negative z-axis (that's the default "By default, the camera is situated at the origin, points down the negative z-axis, and has an up-vector of (0, 1, 0)."). So the near plane is at z=-10. The far plane is 10 units behind you, at z=+10.

like image 124
bobobobo Avatar answered Sep 18 '22 15:09

bobobobo