|
help: how to use al_calculate_arc() |
Pho75_
Member #12,377
November 2010
|
Hi all, Thanks. 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
|
https://liballeg.org/a5docs/5.2.6/primitives.html#al_calculate_arc There are two sets of points with thickness > 0. The outer points and the inner points. Draw your triangle between the two. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Pho75_
Member #12,377
November 2010
|
Ok, I figured it out. 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
|
I didn't see it the first time, but yes, the outer and inner points are interleaved. That's probably what caused the confusion. Thank you for the example. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|