3D Version of "al_transform_coordinates()"?
RPG Hacker

Hey there!

I was looking a lot into the transformation system of Allegro 5.1 lately (especially the 3D transformations). I thought it would be fun to use this system to make some kind of pseudo 3D game, comparable to those on the SNES (like Mario Kart or maybe the overworld in some RPGs). However, this could be quite difficult since you would have to combine a lot of different transformations and stuff (basically, levels would have to be rotated by 90° degrees, whereas sprites would have to be standing upright). The only thing I could successfully do so far was to draw a 2D image, rotate it by 90° around the X-axis and move the camera around. I thought that a 3D version of al_transform_coordinates() could be really useful for this (to place sprites on the map correctly). So does someone know how to make such a function easily? Or alternatively: Does someone know a good way to combine different transformations for this kind of 3D view? Also, is there an easy way to tile some graphic "infinitely" using these transformations to fill the area that lies outside of your image, or do you have to do that manually? Just think about how Mario Kart filled the space outside the map with grass or animated water.

EDIT:
Wait... I'm not sure if my question made any sense. Want I really need is THIS: A version of al_transform_coordinates() that calculates world space coordinates instead of screen space coordinates, so that I can calculate a sprite's distance from the camera to scale it correctly. Getting its screen space coordinates could then be useful to actually draw it.

EDIT:
Looks like al_transform_coordinates() already delivers the world space coordinates, but only the X- and Y-coordinates. Anyways, I looked into the source code of Allegro 5.1 and it turned out to be quite easy to get a 3D version of that function:

1void transform_coordinates_3d(const ALLEGRO_TRANSFORM *trans, float *x, float *y, float *z) 2{ 3 float t; 4 5 t = *x; 6 7 *x = t * trans->m[0][0] + *y * trans->m[1][0] + trans->m[3][0]; 8 *y = t * trans->m[0][1] + *y * trans->m[1][1] + trans->m[3][1]; 9 *z = t * trans->m[0][2] + *y * trans->m[1][2] + trans->m[3][2]; 10}

I just added the last line. Don't know if this is really correct, but so far it seems to be working.

Now I just hope I did the hot-linking to the docs correctly so that people will find this in the future...

Testing:
al_transform_coordinates(&trans, &x, &y);

EDIT:
Another small correction: This doesn't return the "World Space" coordinates, nor the "Screen Space" coordinates, but rather the coordinates in relation to the screen/camera. But in my case that is exactly what I want, anyways, since it makes Z-ordering and scaling a lot easier. I still need a good way to translate this to Screen Space to actually draw the sprites, though.