Allegro.cc Forums » Programming Questions » 3D with Allegro 5

 This thread is locked; no one can reply to it.
 3D with Allegro 5
 Edgar Reynaldo Member #8,592 May 2007 Hi all, I've been given an assignment to find the shortest path on a graph of 3D vertices using Djikstra's algorithm or similar. That's not the part I want help with - I want to draw a 3D model of the graph with lines on the edges and dots on the vertices. I have the graph info in a file and I will read it in and have the vertex data available to pass to Allegro. Question - what do I use and where do I start? I'm totally new to 3D graphics and don't know yet the basics of how to get a 3D image on screen with Allegro 5. I can use al_draw_prim with ALLEGRO_PRIM_POINT_LIST and ALLEGRO_PRIM_LINE_LIST but how do I set up the 3D perspective to draw it with?Let's assume the world is centered on 0.0,0.0,0.0 and we're looking at it from a given distance away in any direction. We have an angle on the xy plane and an angle on the yz plane. How do I turn those into the proper perspective and use it with Allegro 5. How do I turn that into something I can use with al_perspective_transform? And what are left,top,n(ear),right,bottom, and f(ar)? After I figure out that part it's just a matter of translation and rotation I would think, right? Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 SiegeLord Member #7,827 October 2006 Elias recently added an ex_camera example (adapted from Allegro 4) that you could look at. There's a reasonable discussion about the perspective transform parameters here. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Edgar Reynaldo Member #8,592 May 2007 Okay, I'm starting to understand what stuff means, but how do I get the values for r,l,t,b,n, and f from a 3D angle? Do I have to calculate the pyramidal frustum myself? Finally, we found all entries of GL_PROJECTION matrix. The complete projection matrix is; {"name":"gl_projectionmatrix01.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/1\/81ee78b0ef2b14c60ec8ba79bf2fff86.png","w":470,"h":230,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/1\/81ee78b0ef2b14c60ec8ba79bf2fff86"} Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 SiegeLord Member #7,827 October 2006 Those have nothing to do with the orientation where you are looking at. Your actual code would look something like this:ALLEGRO_TRANSFORM t; al_identity_transform(&t); al_perspective_transform(&t, ...); al_use_projection_transform(&t); al_build_camera_transform(&t, /* this is where your angles will come in */); al_use_transform(&t);  "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]
 Edgar Reynaldo Member #8,592 May 2007 SiegeLord said: Those have nothing to do with the orientation where you are looking at. Your actual code would look something like this: Oh! Okay! So what do near and far have to do with it then? Dont' they sort of determine the distance from the camera to the clipping planes?And why are there two transformations in use now? I dont' get the differnce between al_use_projection_transform and al_use_transform.In your code example you don't call al_identity_transform on the transform before calling al_build_camera_transform and after using al_use_projection_transform. Is that on purpose?Editl,r,t, and b are all determined by the horizontal and vertical field of view, correct? Ie - the interior angles of the frustum, right? Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 Elias Member #358 May 2000 Edgar Reynaldo said:And why are there two transformations in use now? They are applied one after the other. But the projection transform depends on the screen size so there's good reasons to keep them separate.Quote:In your code example you don't call al_identity_transform on the transform before calling al_build_camera_transform and after using al_use_projection_transform. Is that on purpose? al_perspective_transform modifies the transform you pass, al_build_camera_transform overwrites it, so in one case you need to initialize first in the other not.Quote:l,r,t, and b are all determined by the horizontal and vertical field of view, correct? Ie - the interior angles of the frustum, right? Yes. Or rather, the quotient of the near plane to those four decides the horizontal/vertical field of view. So you can first choose your clipping distance and then set those four according to your fov. (Or the other way around, both ways work.) --"Either help out or stop whining" - Evert
 Edgar Reynaldo Member #8,592 May 2007 Do I need to position my camera farther away because of the near clipping plane? What if the z value of near was like 10 or 100? Do I need to move my camera back by that same amount to bring objects on the near clipping plane into view? Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 Elias Member #358 May 2000 Yes, anything behind (closer to the camera than) the near clipping plane will not be visible. --"Either help out or stop whining" - Evert
 Edgar Reynaldo Member #8,592 May 2007 Okay, so I don't get yet how the perspective transform is supposed to be composed. Am I supposed to set l,r,t,b,n,and f as if I was looking directly down the negative z axis in the left hand side of the graphic I posted above? Ie - what would happen if l and r and t and b aren't symettric? What if they don't equal their negated counterpart? Does that skew the perspective or what does it do? I suppose I should just play around with it a bit but I like to ask questions. Also, I was discussing on IRC earlier about whether I should render 3D points and lines as 3D spheres or cubes and rectangular prisms or right cylinders. Is there a good way to go about triangulating those 3D shapes if it turns out that the points and lines dont' look right with al_draw_prim? I mean, how does allegro decide how thick to draw a 2D line in 3D space? Or a 1D point in 3D space? Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so
 Mark Oates Member #1,146 March 2001 Hey Edgar, post screenshots of your progres? I'm interested to see how it all comes together for you