[AD] al_compose_transform respecting 3d transforms |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: "Coordination of admins/developers of the game programming libraryAllegro" <alleg-developers@xxxxxxxxxx>
- Subject: [AD] al_compose_transform respecting 3d transforms
- From: "Trent Gamblin" <trent@xxxxxxxxxx>
- Date: Wed, 23 Feb 2011 08:20:50 -0700
While Paul has said he believes 3d transformations belong in an addon (and I
agree, for the most part), al_compose_transform should be doing a full 3d
respecting multiply. This is because the user may use transformation
functions of their own (I'm using some transform functions taken from Mesa).
The current implementation will not work. Here's a patch, which I propose to
make al_compose_transform do a full matrix multiply. This allows me to use
the bitmap drawing functions with my own 3d transforms. There may be some
trick somebody knows to avoid the temporary matrix.
Index: transformations.c
===================================================================
--- transformations.c (revision 14511)
+++ transformations.c (working copy)
@@ -263,34 +263,21 @@
*y = t * trans->m[0][1] + *y * trans->m[1][1] + trans->m[3][1];
}
-/* Function: al_compose_transform
- */
void al_compose_transform(ALLEGRO_TRANSFORM *trans, const ALLEGRO_TRANSFORM
*other)
{
- float t;
- ASSERT(other);
- ASSERT(trans);
-
- /*
- First column
- */
- t = trans->m[0][0];
- trans->m[0][0] = other->m[0][0] * t + other->m[1][0] * trans->m[0][1];
- trans->m[0][1] = other->m[0][1] * t + other->m[1][1] * trans->m[0][1];
-
- /*
- Second column
- */
- t = trans->m[1][0];
- trans->m[1][0] = other->m[0][0] * t + other->m[1][0] * trans->m[1][1];
- trans->m[1][1] = other->m[0][1] * t + other->m[1][1] * trans->m[1][1];
-
- /*
- Fourth column
- */
- t = trans->m[3][0];
- trans->m[3][0] = other->m[0][0] * t + other->m[1][0] * trans->m[3][1] +
other->m[3][0];
- trans->m[3][1] = other->m[0][1] * t + other->m[1][1] * trans->m[3][1] +
other->m[3][1];
+ ALLEGRO_TRANSFORM tmp;
+ int x, y, i;
+
+ al_copy_transform(&tmp, trans);
+
+ for (y = 0; y < 4; y++) {
+ for (x = 0; x < 4; x++) {
+ trans->m[x][y] = 0;
+ for (i = 0; i < 4; i++) {
+ trans->m[x][y] += other->m[i][y] * tmp.m[x][i];
+ }
+ }
+ }
}
bool _al_transform_is_translation(const ALLEGRO_TRANSFORM* trans,