[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Trent Gamblin wrote:
On Mon, April 26, 2010 4:11 pm, Elias Pschernig said:
What are the drawbacks of removing parallelogram_map completely?
That function is the greatest evil in all of Allegro... but it works and is
decently fast... But IMO if it can be rewritten more clearly that would be
great.
But anyhow, I can easily keep the current 2D transforms as they are
and create a 3D transform addon or something. I think it would work,
but the core would depend on it anyway I guess, since as I said, the
2D transformation API produced incorrect results (for whatever reason)
when I first tried using it for the iPhone landscape transformation. I
know that involves an orthographic projection which is a 3D thing,
but even when I temporarily removed it for testing, the comparison to
the OpenGL matrix was off, and all of the other transforms are 2D.
glOrtho just happens to be one 3D transformation that plays nicely with
2D transformations (it has many zeroes in it). Regardless of that,
sticking strictly with 2D functions gives me identical results for both
OGL and the 2D transformations. See the attached code for an example.
-SiegeLord
Trent :{)>
------------------------------------------------------------------------------
#include <allegro5/allegro5.h>
#include <allegro5/allegro_opengl.h>
#include <stdio.h>
#include <math.h>
void print_matrix(float* matrix)
{
for(int y = 0; y < 4; y++)
{
for(int x = 0; x < 4; x++)
printf("%f ", matrix[y * 4 + x]);
printf("\n");
}
}
int main()
{
al_init();
al_set_new_display_flags(ALLEGRO_OPENGL);
ALLEGRO_DISPLAY* disp = al_create_display(100, 100);
float tr[16];
ALLEGRO_TRANSFORM T1;
float top = 5;
float bottom = 100;
float left = 6;
float right = 56;
float near = -10;
float far = - 100;
al_identity_transform(&T1);
// glOrtho equivalent
al_scale_transform(&T1, 2.0f / (right - left), 2.0f / (top - bottom));
al_translate_transform(&T1, -(right + left) / (right - left), -(top + bottom) / (top - bottom));
// These two are optional for 2D only glOrtho (far/near planes don't matter)
// but they are here so that the deviation code below works
T1.m[2][2] = -2.0f / (far - near);
T1.m[3][2] = -(far + near) / (far - near);
// Some random transformations
al_rotate_transform(&T1, ALLEGRO_PI / 4);
al_translate_transform(&T1, 20, 200);
al_rotate_transform(&T1, ALLEGRO_PI / 3);
al_scale_transform(&T1, 3.0f, 5.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(3, 5, 1);
glRotatef(60, 0, 0, 1);
glTranslatef(20, 200, 0);
glRotatef(45, 0, 0, 1);
glOrtho(left, right, bottom, top, near, far);
glGetFloatv(GL_MODELVIEW_MATRIX, tr);
printf("\nOpenGL: \n\n");
print_matrix(tr);
printf("\nA5: \n\n");
print_matrix(T1.m[0]);
float max_dev = 0;
for(int ii = 0; ii < 16; ii++)
{
float cand_dev = fabs(T1.m[0][ii] - tr[ii]);
if(cand_dev > max_dev)
max_dev = cand_dev;
}
printf("\nMax Deviation: %f\n", max_dev);
return 0;
}