Re: [AD] al_compose_transform respecting 3d transforms |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2011-02-23, Trent Gamblin <trent@xxxxxxxxxx> wrote:
> 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)
Remember not to delete the header.
> + 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];
> + }
> + }
> + }
> }
You'll also want to update al_invert_transform, at least.
As far as performance goes, I did a quick and dirty benchmark. This is
the time for 10 million calls to al_compose_transform calls on a Core 2
1.83 GHz.
Old code:
Time: 0.173985 s; 1.73985e-08 per call
New code:
Time: 1.21529 s; 1.21529e-07 per call
So there is a significant penalty in relative time, but in absolute
terms probably fine (at least on a desktop machine).
Peter