Defining Rectangles on the fly
Hi everyone,
I asked this question a while back: http://answers.unity3d.com/questions/479616/box-mechanic-is-it-possible-to-know-when-the-box-i.html but it still bugs me to not be 100% certain of it.
So I'd like to pick your brain about a couple of possibilities for this type of mechanic to work:
Qix/Volfied system -- filling an area "drawn" by the user then calculating that area's size -> does anyone have any good examples for this type of mechanic
Dynamic Rectangles -- i'm not sure if it's possible but it would mean defining a Rect after each instantiation (or replacing one)
Any other ideas would be appreciated. Let me know if I can provide more info.
Thanks!
Answer by Statement · Oct 10, 2015 at 01:03 PM
Qix appear to do more than just simple rectangle shapes as demonstrated in this clip. However it is feasible to define the shape as a composite of several rectangles. Care has to be taken to generate multiple rectangles for certain cases where the area becomes concave etc.
Img: A few possible rectangulariations for some sample area. More solutions are possible.
I don't have a ready algorithm for you and there are more solutions that could be generated than described in the example above. But to start somewhere, think of starting at two adjacent corners, then extending a rect inward from those two corners until you hit an edge. That would be one rect. Now you can adjust the hull by removing the area you just created. This can in turn modify the existing hull or spawn separate, isolated hulls. It depends on the shape you are rectangularizing.
Consider the first example in the image above. If you started with the top corners, you'd create the green tall rect. The hull should then have been modified to an L shape.
Img: After figuring out one rect, the hull is modified and the process starts again.
Img: In some cases you could end up dividing the hull in two or more hulls, like in this simple case.
Another representation could be generating triangles using ear clipping algorithm.
With either representation (a collection of rects vs a collection of triangles) you can then render or calculate the area. Just sum the area of all rects or triangles to get the total area. To draw the area it sounds like you want to perform two actions. Drawing the fill and the border. The border can be found by traversing the hull of your collection of primitives if you want to draw it as a mesh etc.
Not sure what you mean by dynamic rectangles. You can certainly change the fields of a Rect after it's been instantiated.
Thanks a lot for the detailed reply!
I'm aware that QiX allows for more complex shapes, but my concept will only allow rectangles to be created.
Also, one of the (concept) problems I'm facing is how to consider which direction is "inward" since you aren't bound by a the border as in QiX.
I think something that could fit even better would be to consider my level a rectangle from the start and then slice/divide it based on the instantiated fences - can this be achieved in a similar manner?
I don't really understand what you exactly are trying to achieve, but of course you can start with a rect, then subtract rects from that rect, spawning multiple, smaller, rects.
@Statement, the closest example of the standard gameplay would be this game I found:
http://www.best-flash-games.net/kids-games/clone-a-doodle-doo.html
Basically: what's the best option vs what's the fastest option for achieving this? (knowing when the AI is captured/surrounded by "walls" in a defined area)