|
Overlapping Circles |
Splizard
Member #15,703
August 2014
|
I am playing around with the primitives library and I am wondering if there is any way to draw circles of different colours without them overlapping each other..? like this: Is there a simple efficient way to go about this or should I stick to the same colour to give the illusion of not overlapping?
|
jmasterx
Member #11,410
October 2009
|
Maybe this could be done with the stencil buffer http://en.wikipedia.org/wiki/Stencil_buffer Or perhaps when drawing the second circle you can use clipping rect. Yeah, clipping rect can do this. Agui GUI API -> https://github.com/jmasterx/Agui |
Splizard
Member #15,703
August 2014
|
It would be nice if I could do it without explicitly calling OpenGL Thanks, but the clipping rectangle doesn't seem to work at any angle... al_set_clipping_rectangle(int x, int y, int width, int height) So I guess I would then need to rotate the coordinates to achieve this at different angles?
|
beoran
Member #12,636
March 2011
|
The way to do this could be to calculate the 2 arcs using al_calculate_line, and then close the line piece by using al_calculate_line, then finally use al_draw_prim to draw the resulting figure. https://www.allegro.cc/manual/5/al_calculate_arc You can also use Allegro's transformations to translate and rotate coordinates. |
Pho75_
Member #12,377
November 2010
|
i would convert the 2 circles into 2 arrays of raster lines so you can draw an entire circle by stepping through the array. for y= y1 to y2 NOTE: if you have an optimized draw_hline function, 1. 2. do a bounding box check on the y coordinate first. if (intersects) 3. draw each circle by looping through the raster lines. circle1: circle2: obviously, if both circles aren't on the same y coordinate u have to do This should work for circles of different sizes too, i think. this algorithm probably only works as long as 1 circle is not completely inside |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Splizard said: Thanks, but the clipping rectangle doesn't seem to work at any angle... al_set_clipping_rectangle(int x, int y, int width, int height) It works for me in this simple example : 1
2
3
4#include "allegro5/allegro.h"
5#include "allegro5/allegro_primitives.h"
6#include "allegro5/allegro_image.h"
7
8int main(int argc , char** argv) {
9
10
11 if (!al_init()) {return 1;}
12 if (!al_init_primitives_addon()) {return 2;}
13 if (!al_init_image_addon()) {return 3;}
14
15 al_set_new_display_flags(ALLEGRO_WINDOWED);
16 ALLEGRO_DISPLAY* display = al_create_display(300,200);
17
18 al_clear_to_color(al_map_rgb(0,0,0));
19
20 al_set_clipping_rectangle(0,0,150,200);
21 al_draw_filled_circle(100,100,100,al_map_rgb(0,255,0));
22 al_set_clipping_rectangle(150,0,150,200);
23 al_draw_filled_circle(200,100,100,al_map_rgb(0,0,255));
24
25 al_save_bitmap("primclip.png" , al_get_backbuffer(display));
26
27 al_flip_display();
28
29 al_rest(3.0);
30
31 return 0;
32}
{"name":"608871","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/f\/1f0a8f0ef5d0ec4a6895038594a8e6af.png","w":300,"h":200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/f\/1f0a8f0ef5d0ec4a6895038594a8e6af"} Though to get rotated 'molecules' you would need to use a subbitmap to draw your circles on horizontally and then use the transformation matrix to draw it rotated on screen. The clipping gets applied after the transformation as far as I know. 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 |
Gideon Weems
Member #3,925
October 2003
|
Splizard
Member #15,703
August 2014
|
@Edgar Reynaldo Out of the solutions above which would theoretically be the most speed efficient way?
|
Arthur Kalliokoski
Second in Command
February 2005
|
I'd think drawing actual lit 3D intersecting spheres would be easiest in the long run. They all watch too much MSNBC... they get ideas. |
|