Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » "Handedness"

This thread is locked; no one can reply to it. rss feed Print
"Handedness"
roger levy
Member #2,513
July 2002

I've noticed a quirk in my 3D explorations where when I rotate a point around the Y axis, the Z coordinate comes out the reverse of what I expected/desired, so I have to multiply it by -1 to get models moving and abstract points rotating correctly.

Is Allegro 5 left-handed or right-handed? Is this a consequence of right-handedness? Do I want left-handedness in order not to have to negate Z all the time? As I understand it Z goes into the screen in the negative direction with right-handedness, but normal rotation algorithms (including al_rotate_transform_3d with a 0,1,0 axis) rotate things counter clockwise with Z coming out positive with an input of 90 degrees. (And yet it appears that my models are rotating correctly in world space...)

Sorry if I'm not making sense, 3D programming is a challenge but I want to really get the fundamentals nailed down in my brain once and for all.

Elias
Member #358
May 2000

As I understand it Z goes into the screen in the negative direction with right-handedness

That depends on the "projection transform" you set. By default the Y axis is reversed, i.e. it goes down. With a 3D camera it is more customary to have Y go up. So basically, assuming X points right, you can have a right-hand system when Y goes up and Z towards the viewer, or if Y goes down ad Z goes into the screen.

Quote:

al_rotate_transform_3d with a 0,1,0 axis) rotate things counter clockwise with Z coming out positive with an input of 90 degrees.

You mean, if you rotate the vector (0, 0, 1) around the axis (0, 1, 0) by 90 degree, the resulting vector will be (1, 0, 0)? Then yes, that is correct.

Basically, look at what you pass to al_use_projection_transform and to al_use_transform. That will decide if your camera is "right hand" or "left hand" - Allegro's transformations are just a different name for "matrices", there is nothing special done there to work better with one system compared to another, it's all up to you.

--
"Either help out or stop whining" - Evert

roger levy
Member #2,513
July 2002

So if I set the near and far of my projection transform to -1 and -1000, Z will increase going into the screen? And what about al_use_transform, what should I be doing there if I want to use a left-handed system?

Elias
Member #358
May 2000

I think so, but there could be something that special cases the perspective transform to not allow a negative near value. You can always look at the source code and see the exact matrix it creates. Both transforms are multiplied together before being sent to the shader, so just saying - if you call al_use_transform with a transform that flips the z axis that will change the handedness.

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

roger levy
Member #2,513
July 2002

I think I've got what I was after. To make your coordinate system left-handed, you just have to: (in your perspective transform setup)

Ramen (Forth):

p 1 1 -1 3af al_scale_transform_3d

Psuedocode:

al_scale_transform_3d( p, 1, 1, -1 )

After al_identity_transform and before al_perspective_transform.

Of course, this had the effect of requiring modification to the modelview transformations, and rotation-related code, but the net result was less code, so I think I accomplished my goal.

On a side note, in the example I copied from, this is done before the al_perspective_transform:

al_translate_transform_3d( p, 0, 0, -1 )

Not sure if that's necessary? What is it supposed to do?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: