Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by StanMihai72 · Aug 22, 2016 at 06:25 PM · 2ddrawingpolygon

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.

Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Aug 22, 2016 at 06:31 PM 0
Share

How about casting a ray to the mouse position and checking if it hit the collider of the $$anonymous$$?

avatar image StanMihai72 Cherno · Aug 23, 2016 at 08:00 AM 0
Share

That would only detect if the mouse is on the outline of the $$anonymous$$, which is not the desired effect.

avatar image _Yash_ · Aug 23, 2016 at 09:23 AM 0
Share

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.

avatar image StanMihai72 _Yash_ · Aug 23, 2016 at 11:10 AM 0
Share

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.

avatar image Bunny83 · Aug 23, 2016 at 11:26 AM 0
Share

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 ^^.

avatar image StanMihai72 Bunny83 · Aug 23, 2016 at 11:32 AM 0
Share

$$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?

avatar image Bunny83 StanMihai72 · Aug 23, 2016 at 11:39 AM 0
Share

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.

Show more comments
avatar image mj321 · Aug 23, 2016 at 11:28 AM 2
Share

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.

avatar image StanMihai72 mj321 · Aug 23, 2016 at 11:42 AM 0
Share

Very interesting idea. I'm gonna look into the implementation side of it, but it seems decent and do-able.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges