![]() |
|
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. {"name":"611851","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/d\/dd515541d9190f8ac1c7788c01a47690.png","w":800,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/d\/dd515541d9190f8ac1c7788c01a47690"} You can clearly see in my program, that positive x goes left : {"name":"611852","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/8\/686905ed95760d4d392c2b05243133cf.png","w":902,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/8\/686905ed95760d4d392c2b05243133cf"} 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. EDIT My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Mr-Hide
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). y | !____x / / z
|
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. {"name":"611853","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/5\/85b9d6bc3377848b1157f7e8e5720066.png","w":902,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/5\/85b9d6bc3377848b1157f7e8e5720066"} My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|