5
\$\begingroup\$

In my RTS (In Unity) each unit or building has strategic circles in a similar fashion to SupCom. If you have multiple units or buildings selected it looks like the picture to the left. I want to make it look like the picture to the right, where anything inside the outer edges of their circles is no longer shown.

enter image description here

I draw these using vectrosity, mentioning this just in case vectrosity provides a way of doing this, or can be modified to do this.

The circles are essentially just an array of points with lines drawn in between them. How would I go about "merging" the circles inside of their overlapping area?

This is similar to: How to make unit selection circles merge?, however I am not interested in a shader solution.

Edit: To re-explain the above.:

I'm not seeing how the answers are applicable. I've read through the other thread before posting, which is why I posted it here to avoid this exact thing (being marked as a duplicate). I have an array of points with straight lines in-between them to create a circle-like effect. This is not a true circle, but a really granular polygon. I am interested in solutions that are achievable in C# within Unity, not with shaders or with rendering mechanics.

Edit2: Another picture based on one of Roberts suggestions enter image description here

This seems viable, though computationally expensive. If I have a circle made up of 250 points, and 50 circles all intertwined that's 615,500 checks in a worst-case scenario.

\$\endgroup\$
6
  • \$\begingroup\$ Voting to close. The question you linked is tagged 'shader' but the actual question (and the answers) are not specific to shaders. \$\endgroup\$ Mar 27, 2015 at 19:12
  • \$\begingroup\$ I'm not seeing how the answers are applicable. I've read through the other thread before posting, which is why I posted it here to avoid this exact thing. I have an array of points with straight lines in-between them to create a circle-like effect. This is not a true circle, but a really granular polygon. I am interested in solutions that are achievable in C# within Unity. \$\endgroup\$ Mar 27, 2015 at 19:18
  • \$\begingroup\$ You can do that with some stencil tricks. I'll post an example when I have time. In the meanwhile have a look here: docs.unity3d.com/Manual/SL-Stencil.html \$\endgroup\$
    – Heisenbug
    Mar 27, 2015 at 19:37
  • \$\begingroup\$ Sorry I read more carefully your question..I don't see any particular smart way of achieving that without shaders \$\endgroup\$
    – Heisenbug
    Mar 27, 2015 at 19:45
  • \$\begingroup\$ Sure, thanks Heisenbug. I'f I'm unable to find a non-shader solution I'll probably be forced to look into shaders for it. \$\endgroup\$ Mar 27, 2015 at 20:02

6 Answers 6

2
\$\begingroup\$

Draw each circle on some memory, then after all are drawn, set the inside of every circle to zeros, clearing any intersection lines.

clarification On some memory is meant to indicate separate texture Set to 0 is meant to indicate set to transparent.

setting inside transparent on second draw sequence is fill with transparent color with fillcircle of radius ( radius - linewidth) on second drawing

\$\endgroup\$
7
  • \$\begingroup\$ They are different methods, if they were all in the same answer section the +- feature would be ambiguous, and there is not enough detail in the question to deduce the answer wanted in one answer. \$\endgroup\$ Mar 27, 2015 at 18:56
  • \$\begingroup\$ I'd still need a way to identify what is the "inside" the intersections and what is "outside" any intersections. Which is one of the primary problems. I'm looking into your answer on distance to the radius. \$\endgroup\$ Mar 27, 2015 at 19:13
  • \$\begingroup\$ Other answers comment on that, distance to center, or you could do a line crossing check where after drawing, erase along lines that are inside based on how intersection points show change from outside and inside. although you would have to have a depth to know if any point was turned on twice (intersection) \$\endgroup\$ Mar 27, 2015 at 19:18
  • \$\begingroup\$ "I'd still need a way to identify what is the "inside" the intersections and what is "outside" any intersections" - That's exactly what this answer gives you. To explain it simpler: Draw filled-in red circles, then draw filled-in white circles with slightly smaller radii at the same points. \$\endgroup\$ Mar 27, 2015 at 19:23
  • \$\begingroup\$ I see what you mean now. Though, I would still need to "know" what is inside another circle. I can't fill them all in since there are other objects in the scene in and around the circles that would be covered as well. If I have two circles whose edges intersect, by what process do I identify from the array of points that make up each circle, which points within those arrays are within the circumference of the other circle with this method. The most promising one I see is checking a points distance compared to the circles radius. \$\endgroup\$ Mar 27, 2015 at 19:47
2
\$\begingroup\$

I know this thread is ancient, but I want to share information to anyone looking.

In Unity it's simple! You can merge the circles, using two objects. "A" circle sprite and "B" sprite mask. If you set A's to "Visible Outside Mask" then B will mask all instances of A. Creating nice merging.

( Ignore that I duplicated the prefab inside itself, it's just to demonstrate )

Picture of two circles merged via sprite masking

\$\endgroup\$
1
\$\begingroup\$

You probably could draw, and save 'intersection points' any point where two circles draw a point at same location. Then use that set, knowing that inside and outside changes when an intersection occurs. You would then only need to check any one point between two intersections to know the status of an entire arc between any two intersections.

Fewer checks with that.

in your drawing, you would only have to check one point inside, and one point outside,(for each circle) to know the status of the arcs. Each circle has two arcs, so two checks for each circle.

Circles with only one intersection point would have to be handled, but that would not be difficult. If odd number of intersections, you would know in one case two circles only share one point in common and could adjust algo for that. And that case should be rare.

\$\endgroup\$
1
\$\begingroup\$

If you don't care about the interior being painted in, there's a really simple solution. First, draw all circles in black. Next, draw all the circles again in white, with a smaller radius - basically subtract a border width from the radius. The result will be a constant thickness black border around a white area. You could maybe even use this black / white info in a stencil buffer to do more advanced rendering.

\$\endgroup\$
0
\$\begingroup\$

If any point is closer to the center of any circle then the radius of that circle clip it.

Although you would probably want to find the intersection points where any two distances equal to the radius of a circle, from any two different circle centers are equal, to get clean edges where intersection occurs.

basically any point inside another circle is clipped, and you can determine if in the circle by distance to radius, or any other method. Probably could, when first finding a point inside a circle, move it to the edge value, so that the edges of the many circles would be connected also.

\$\endgroup\$
-1
\$\begingroup\$

Or draw your circles as filled, then trace the edge that would work also.

tracing edges method would only be computationally a better method with a very large number of circles. Where edge trace is faster then second set of drawing.

\$\endgroup\$
2
  • \$\begingroup\$ If the circles were first drawn to a separate, transparent, render target, and DestAlpha = InvSource and SourceAlpha = InvDest? Discard Black and Transparent when drawing (sampling the circle buffer) to the backbuffer. \$\endgroup\$
    – Jon
    Mar 27, 2015 at 21:21
  • \$\begingroup\$ *drawn (filled) \$\endgroup\$
    – Jon
    Mar 27, 2015 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .