- Home /
determine how much space is left on screen
Hello, I'm new to Unity development and I would like some help if it is possible!
I want to make an iphone drawing application like that described here
http://www.flashperfection.com/tutorials/Mouse-Drawing-in-AS3-96618.html
where the user can draw the screen with a brush (their finger). I need a way to determine that all the surface has been drawn. Any ideas on how to accomplish that? Is there a way in Unity to calculate how many pixels have been drawn?
Thanks in advance!
Answer by Wolfram · Aug 23, 2010 at 02:56 PM
Does is have to be pixel-precise? If so, I guess you'd have to count pixels one way or another. For example, instead of just drawing on the screen, also "draw" into a 2D array mask. You can stop if every entry of that array has been set (if you scan linearly for entries that haven't been set yet, note you can bail out at the first unset entry you find, and don't need to process the complete array everytime).
It is very likely that there are GPU/Shader functions to help you with that (i.e., determining whether all pixels of a mask have been set/reset), but I haven't looked into that.
If your result doesn't need to be pixel-precise, you can use an analytical method - but since that would have to be determined over all circles drawn so far, it is likely to be more expensive. Start with the surface area of your display, width*height in pixels. If you draw a circle, subtract its area from that value (take care of clipping near the borders by re-adding the area of the clipped circle segments). If you now move the mouse/finger (and maybe change the radius), you can compute the area difference between two consecutive frames by computing the area of the resulting crescent between these two circles. However, you would need to clip any new circle that is to be drawn against all other circles that have been drawn already, to determine the overlap and only subtract the area that's actually "new". This last step makes the analytical method probably not feasible.