Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » help: how to use al_calculate_arc()

This thread is locked; no one can reply to it. rss feed Print
help: how to use al_calculate_arc()
Pho75_
Member #12,377
November 2010

Hi all,
I'm trying to figure out how to use al_calculate_arc() to
get an array of points that I can manually draw
but I don't understand from the documentation how to use the output.
It's not drawing correctly.
What am I doing wrong?

Thanks.

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_primitives.h> 3 4int main() 5{ 6 al_init(); 7 al_init_primitives_addon(); 8 al_set_new_display_flags(ALLEGRO_RESIZABLE); 9 al_create_display(1280, 720); 10 al_clear_to_color(al_map_rgb(0,0,0)); 11 12 { 13 const int num_points = 16; 14 float points[num_points*2][2]; 15 16 // calculate circle points 17 // al_calculate_arc(&points[0][0], 2 * sizeof(float), 0, 0, 100, 100, 0, ALLEGRO_PI / 2, 2, num_points); 18 al_calculate_arc(&points[0][0], 2 * sizeof(float), 100, 100, 100, 100, 0, ALLEGRO_PI * 2, 2, num_points); 19 20 // BROKEN 21 for (int i=0; i+3 <= num_points; i++) 22 { 23// al_draw_filled_polygon(&points[i][0], 4, al_map_rgb(255,255,255)); 24 al_draw_filled_triangle( 25 points[i*3][0], points[i*3][1], 26 points[i*3+1][0], points[i*3+1][1], 27 points[i*3+2][0], points[i*3+2][1], 28 al_map_rgb(255,255,255)); 29 } 30 31// BROKEN 32// for (int i=0; i+4 <= num_points; i+=2) 33// { 34// al_draw_filled_polygon(&points[i][0], 4, al_map_rgb(255,255,255)); 35// } 36 } 37 38 al_flip_display(); 39 40 getchar(); 41 42 return 0; 43}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Pho75_
Member #12,377
November 2010

Ok, I figured it out.
Thanks for the help.
Here is the code so maybe it will help someone else.

#SelectExpand
1#include <iostream> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_primitives.h> 4 5int main() 6{ 7 al_init(); 8 al_init_primitives_addon(); 9 al_set_new_display_flags(ALLEGRO_RESIZABLE); 10 al_create_display(1280, 720); 11 al_clear_to_color(al_map_rgb(0,0,0)); 12 13 { 14 const int num_points = 16; 15 float points[num_points*2][2]; 16 al_calculate_arc(&points[0][0], 2 * sizeof(float), 100, 100, 100, 100, 0, ALLEGRO_PI * 2, 2, num_points); 17 18 for (int i=0; i+4 <= num_points*2; i+=2) 19 { 20 al_draw_filled_triangle( 21 points[i][0], points[i][1], 22 points[i+1][0], points[i+1][1], 23 points[i+2][0], points[i+2][1], 24 al_map_rgb(255,255,255)); 25 al_draw_filled_triangle( 26 points[i+2][0], points[i+2][1], 27 points[i+3][0], points[i+3][1], 28 points[i+1][0], points[i+1][1], 29 al_map_rgb(255,255,255)); 30 } 31 } 32 33 al_flip_display(); 34 35 getchar(); 36 37 return 0; 38}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: