0
\$\begingroup\$

This is a follow-up post to this post: How can I check if a player-drawn line follows a path?. I'm having difficulty implementing the said feature and I believe it's because of a lack of math background.

In particular, the later components of the explanation are a bit confusing to me.

The direction of the projected vector might not actually be important. If you just sum >together the lengths of the projected vectors and compare them to the total length of >the line segment, that will tell you what fraction of it is covered. (Except in odd >cases—see §Limitations below).

In my mind this means

  1. breaking down a character into line segments, converting them to 2d vectors
  2. breaking down a user draw character into line segments, converting them to 2d vectors
  3. mapping each user drawn line segment (now 2d vectors) to the closest character line segments
  4. using projection for each one of those mapped line segments
  5. summing up the projections and comparing it to the total length of all 2d vectors of the character

Is my assumption of what the writer is talking about correct? Or am I misinterpreting what is meant by the last bit.

enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Suggest you research OCR. Even without scanning in from a page, this is not a trivial problem with firmly established boundaries allowing for a simple solution. These days you will likely be using a third party module to do this, probably one based on deep learning techniques. An example. Games that achieved this in the past (e.g. Arx Fatalis) have probably use a sizeable portion of their development or CPU budget to do so. \$\endgroup\$
    – Engineer
    Commented Sep 14, 2021 at 15:25
  • \$\begingroup\$ Ok, thank you. I'll look into that. What would be the simple solution you are referring to? \$\endgroup\$
    – Paul
    Commented Sep 14, 2021 at 17:07
  • 1
    \$\begingroup\$ I'm saying there is no simple solution. \$\endgroup\$
    – Engineer
    Commented Sep 14, 2021 at 19:58
  • \$\begingroup\$ Ahh, got it. Thank you for the clarification \$\endgroup\$
    – Paul
    Commented Sep 14, 2021 at 20:02
  • \$\begingroup\$ I believe the old Harry Potter PC games used some kind of a mask and then checked coverage. \$\endgroup\$ Commented Sep 15, 2021 at 8:10

1 Answer 1

0
\$\begingroup\$

Keep It Simple.


We can simplify the problem by focusing in only one segment. Once we solved it for one segment, we do that for a set of segments. We can define a coordinate system for the segment that makes it easier to check the distance from the input.

However, we still need to deal with how much of the segment has been painted. We could define a set of ranges (at the start only one range) that represent the segment. Then, on each input motion figure out what range of the segment it covers and substract it from the set (note: a range minus another range might result in two, one or zero ranges) until we have the empty set…

But keep it simple. It is easier to divide the segment into smaller segments, and only worry if each one of then got an input position near or not.

Well, we could instead define a series of points, and then check distance to those points. That way we can avoid the coordinate system I was talking about earlier…

Hmm… It would be good to put those points in a quad tree, so it is easier to find which point is near the input. S you don't have to to check distance to all them. Or better yet, put them on a grid. Then, you can just go to the grid based on the input position and see if there is a point there.

Well, that is a bitmap. You could have two low resolution monochrome bitmaps. One is how the character should look, and on the other you paint. Then you iterate over the pixels and see if all the pixels of the former are painted on the latter.

Except, if you only care if you painted all the pixels, you don't need to iterate over all the pixels to check. You can just keep count.


Have two low resolution monochrome bitmaps. The bitmap A is how the character should look. And you will paint on the bitmap B. Neither is what you show to the user. You also need the count of how many pixels are painted in A.

Take the input position, map it to the coordinates of the bitmaps, read from B. If it is painted in B, there is nothing to do. If it isn't, then paint it, then read from A. If it is painted in A, then decrease the count. Once the count reaches zero, the user is done.


Of course, don't loose track of the fact this method presuposes the character should have a given size, shape, position and orientation.

\$\endgroup\$
0

You must log in to answer this question.

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