Hi,
I've read the bits of the docs about transforms and looked at ex_transform.
I still don't really understand what they do and how they should be used.
Is there a tutorial about them anywhere?
Just to ask, are you interested in transforms that are applied to the display (like controlling a camera), or transforms to establish the position different objects in a scene? There's a bit of a difference between the two.
Also, 2d or 3d?
I'm just trying to learn how to use the function al_draw_prim so I started trying to understand the code in ex_prim.c . I wanted to understand this function :
What I actually want to do is draw some lines on a display's backbuffer with low level routines.
https://liballeg.org/a5docs/trunk/transformations.html#al_build_transform
al_build_transform(&MainTrans, ScreenW / 2, ScreenH / 2, 1, 1, Theta);
This call creates a transform matrix that does this :
1) Rotate by theta
2) Scale by 1,1
3) Translate by sw/2 , sh/2
It is equivalent to doing the same thing sequentially.
Most the time you want to precede rotation and scaling by a centering translation, unto the center of the object you are drawing. This way it isn't skewed by the scaling.
In the case of the function you are asking about, the model it is drawing is already centered on 0,0 so rotation and scaling are applied evenly to the whole figure.
I see. The screen is a coordinate system with pixel (0, 0) as it's origin. The translation shifts the origin to the center of the screen. The scaling makes things stay the same size and the rotation rotated everything around the center of the screen.
Thanks a lot.
Furthermore, https://liballeg.org/a5docs/trunk/transformations.html#al_use_transform sets the view matrix.
https://liballeg.org/a5docs/trunk/transformations.html#al_use_projection_transform sets the perspective transform - for 3D, and https://liballeg.org/a5docs/trunk/transformations.html#al_orthographic_transform for 2D flat perspective.
Thanks Edgar.
Can I also use al_draw_prim to draw lines and other geometrical objects with different translucencies?
Yes. In the ALLEGRO_VERTEX struct is a member called color or col or ... simply use al_map_rgba instead of al_map_rgb to create your vertex color.
I still struggle with Allegro transformations every time I need to use them. Given that Allegro is a multiplatform library, I wonder why it didn't adopt OpenGL style transformations.
kenmasters1976 - the only difference between them is the order they are applied. Allegro transformations are pre-multiplied, and OpenGL transformations are post-multiplied. All you do is reverse the order you apply them in.
Personally, I think OpenGL is backwards. :/
Thanks both of you.
I managed to work out how to draw with blending by experimentation. The potential of allegro is slowly dawning on me.
Personally, I think OpenGL is backwards. :/
I've read that before. However, I learned some basic OpenGL ever since Allegro 4 with AllegroGL so I guess I'm so used to OpenGL that I can't easily think of transformations the other way around. That said, I can use Allegro 5 transformations whenever I need them, they just don't seem intuitive to me since OpenGL is what I'm used to.
Generally, transformations follow this pattern :
0) Setup your view transform (your camera)
1) Translate the center of your object to the origin
2) Rotate
3) Scale
4) Untranslate back to the correct position of the center of your object
This prevents your object from stretching or skewing or spiraling off course.
kenmasters1976, what is that in OpenGL? Something like this??
glMatrixMode(GL_MODELVIEW); glIdentity(); glTranslate(cx,cy,cz); glScale(sx,sy,sz); glRotate(rx , ry , rz) glTranslate(-cx , -cy , -cz) glMultiply(CameraMatrix)
Doesn't this require you to know the camera matrix?