FPS camera in Allegro 5
CrizerPL

So I'm trying to make a simple 3D game in Allegro5 and I'm stuck trying to make the camera class work.

Here's my loop:

#SelectExpand
1al_clear_to_color(al_map_rgb(0,0,0)); 2 3p = test.create_a5_perspective_transform(); 4c = test.create_a5_camera_transform(); 5 6al_use_projection_transform(&p); 7al_use_transform(&c); 8al_draw_prim(&test_hmap[0], NULL, NULL, 0, test_hmap.size(), ALLEGRO_PRIM_TRIANGLE_LIST); 9 10test.handle_mouse(); 11al_flip_display();

and here are the 2 functions:

#SelectExpand
1ALLEGRO_TRANSFORM LPG_CAMERA::create_a5_perspective_transform() 2{ 3 double pt_width = tan(h_fov/360.0*3.14159265358979)*lpg_default_near; 4 double pt_height= pt_width / double((double)al_get_display_width(lpg_a5_display)/(double)al_get_display_height(lpg_a5_display)); 5 al_identity_transform(&th_output); 6 al_perspective_transform(&th_output, 7 -pt_width, pt_width, lpg_default_near, 8 -pt_height, pt_height, lpg_render_distance); 9 return th_output; 10} 11ALLEGRO_TRANSFORM LPG_CAMERA::create_a5_camera_transform() 12{ 13 al_identity_transform(&th_output); 14 al_rotate_transform_3d(&th_output, -1.0, 0.0, 0.0, deg_to_rad(y_rot)); //pitch 15 al_rotate_transform_3d(&th_output, 0.0, -1.0, 0.0, deg_to_rad(x_rot)); //yaw 16 al_translate_transform_3d(&th_output, -x, -y, -z); 17 return th_output; 18}

The camera seems tilted and the FOV very limited (I attached the program to give you an idea), so I'm clearly doing something wrong here. I can't really see what's exactly causing the problem, though.
Does anyone know what's wrong?

EDIT: I'm an idiot, I looked at the documentation and realized I was passing arguments to al_perspective_transform in the wrong order :) Also, al_rotate_transform_3d() calls needed to be swapped. The camera is working perfectly now. I can't reply or delete this thread AFAIK, so I'm leaving it here

Thread #616711. Printed from Allegro.cc