- Home /
How to find out how much of a Polygon is filled?
I've got this polygon in the shape of the letter M. Part of my mini-game is a scene where you've got to learn how to write. Basically you have to follow the letter pattern and draw an M inside the polygon. The problem is finding out how much of the polygon was filled, or just deciding if the player has reached the end. Any tips on how to do that? Mind you, it has to be done for all the letters of the alphabet in the future, so a solution that doesn't involve me manually placing triggers would be ideal.
How about casting a ray to the mouse position and checking if it hit the collider of the $$anonymous$$?
That would only detect if the mouse is on the outline of the $$anonymous$$, which is not the desired effect.
have some points on letter $$anonymous$$ such that if covered them all, $$anonymous$$ is considered complete. Now you can just check the distance b/w those points and finger while drawing. When you hit a point remove it from check list and increment a counter. you can show progress by counter/totalPoints.
That is the immediate and direct approach that came to my $$anonymous$$d. However, I have to do this with all the letters of the alphabet, and I'd rather not manually place said points on each and every letter.
Well, some more information would help:
How is your polygon defined? As a point loop?
How do you actually "draw"? In other words what exactly get's "filled"? Do you draw onto a texture?
Is overdraw allowed? If the user just "fills" the entire area the polygon will also be "filled".
You should define some clear rules you want to apply to your case. If you haven't thought of that yet, now is the time ^^.
$$anonymous$$y polygon is defined as an array of all the points for$$anonymous$$g the polygon collider.
The letter outline is placed over a background with a texture on it. Whenever it gets filled, a shape gets "carved" out basically. In more detail, it applies a transparent see-through mask on the texture.
What do you mean by overdraw?
So you're actually painting alpha values into the texture? It would be interesting what's the exact relation between the pixels and your worldspace points that defines your character outline. Can you post your "drawing" code in your question?
By overdraw i mean when you draw outside the shape. Just imagine the user scratches from left to right repeatedly until the whole rectangular area is filled. In that case the polygon (which is inside that rectangle) will also be filled.
I'm a Unity beginner, so i can't tell you how to do it, but here's what i'd try:
Render the Letter into a texture once with a separate camera, e.g. in red on a white background. You can access the bitmap with Texture2D.GetPixels(). Count the red and white pixels and store these numbers.
When the user "draws", you draw a filled circle in black at the correct position into the bitmap. By counting the red, white and black pixels you can deter$$anonymous$$e how much of the letter the user covered and also how much he "painted" outside the letter area.
Very interesting idea. I'm gonna look into the implementation side of it, but it seems decent and do-able.
Your answer
Follow this Question
Related Questions
Draw 2D polygon 1 Answer
Link particles to make a 2D polygon 0 Answers
Recommended sprite drawing resolution 1 Answer
How to make a 2d hand drawn map?,What should I use to make a 2d drawn map? 0 Answers
2D Polygon Convex Decomposition Code 1 Answer