- Online Community Forums » Programming Questions » Coordinate systems and allegro transformations

Credits go to Mr-Hide for helping out!
This thread is locked; no one can reply to it. rss feed Print
Coordinate systems and allegro transformations
Edgar Reynaldo
Major Reynaldo
May 2007

Can someone help me understand what is going on with my 3D. I'm trying to use a left handed coordinate system like this :

RGB is XYZ of a Left Handed coordinate system. What I get is the purple vector instead, with left and right completely reversed.


You can clearly see in my program, that positive x goes left :


I'm using al_build_camera_transform to setup my camera.

1Camera::Camera() : 2 info(START), 3 hfov(90.0), 4 aspect(4.0/3.0), 5 ortho(false) 6{} 7 8 9void Camera::Setup3D(bool orthographic) { 10 ortho = orthographic; 11 ALLEGRO_TRANSFORM proj; 12 ALLEGRO_TRANSFORM cam; 13 14 const double near = 1.0; 15 const double w = near*tan(hfov/2.0); 16 const double l = -w; 17 const double r = w; 18 const double top = w/aspect; 19 const double bot = -w/aspect; 20 const double far = 2000.0; 21 22 23 al_identity_transform(&proj); 24 if (!ortho) { 25 al_perspective_transform(&proj , l , top , near , r , bot , far); 26 } 27 else { 28 al_orthographic_transform(&proj , -500,500,0,500,-500,1000); 29 } 30 al_use_projection_transform(&proj); 31 32 Vec3 eye = info.pos; 33 Vec3 look = info.pos + info.orient.Fw(); 34 Vec3 up = info.orient.Up(); 35 36 al_identity_transform(&cam); 37 al_build_camera_transform(&cam , eye.x , eye.y , eye.z , look.x , look.y , look.z , up.x , up.y , up.z); 38/// al_scale_transform_3d(&cam , 1.0 , 1.0 , 1.0); 39 al_use_transform(&cam); 40}

Also, I have a question, should I apply the rotation scale translation transformation before or after the camera transform? Right now I apply it before, but that seems wrong. I use al_compose_transform to add the camera to my transform before rendering.

I understand there are 8 possible combinations of axes, but how do I specify my specific XYZ configuration to OpenGL? Do I need to use gluLookAt()? What does al_build_camera_transform do? Is it inverting my coordinates?

I've tried multiple things to "fix" this, but none of them work. I've applied negative scale transforms to x and z and nothing works. Half the time my things are inside out.

Oh and one more thing, which way does al_rotate_transform rotate? Ie if the vector is pointing forward, is positive clockwise?

I also realize that left handed and right handed are essentially the same, only with axes switched. So maybe my XYZ is not left handed either? I am getting confused, and I'm tired of the left side being on the right and the right side being on the left.

Also, bonus points if anyone can figure out why characters in my font are disappearing. I know it's something to do with OpenGL but I can't figure it out.

Member #14,103
March 2012

OpenGL uses a Right-handed coordinate system (and so does Direct3D nowadays), the camera is at (0,0,0) and points towards negative Z (positive X goes right and positive Y goes up).


Edgar Reynaldo
Major Reynaldo
May 2007

Okay, here are the fixes I got from elias on IRC on #allegro :

1. Call glGetError() before calling allegro font drawing routines, because they will skip glyphs if there is an error.

2. Flip l and r in al_perspective_transform so r is negative and l is positive, or greater than r. This flips the x axis so it does what I want.

Thank you Mr-Hide for the explanation.

My model is fixed now and ready to save as an .obj file and edit it in blender.


Go to: