# PolyColly issues

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been trying till I'm blue in the face to learn how to calculate the contact points between two polygons. I know the theory, but I want an example to play with, so I used Olivier's newest Polygon.zip tutorial. I was unable to get it to work properly within my own code. So, I figured I would simply clone the tutorial in C#. Well, I did that, the only difference being I use the Graphics object rather than OpenGL, and the interface isn't like his executable.But it does not seem to behave properly, I've checked the code, many times, and as far as I can possible tell it should be correct, exactly like Oliii's tutorial source. A Win32 Executable can be downloaded here, as well as the source (PolygonPointofContact.zip). I'll apologize ahead of time for the lack of comments, if this wasn't the 7th time I've rewritten it, it would certainly be well commented. I need help with this for sure, I'm going mad trying to find the error I've made.

##### Share on other sites

I'm having a look right now.

##### Share on other sites
lol, ok you had a typo

  public static Vector operator *(Vector v1, float s)        {            return new Vector(v1.X * s, v1.X * s);        }

should be

  public static Vector operator *(Vector v1, float s)        {            return new Vector(v1.X * s, v1.Y * s);        }

##### Share on other sites
for the swept test, you missed a trick as well

public bool Swept(Vector axis, float d0, float d1, float v, ref CollisionInfo info)....

            if(t0 > t1)            {                float temp = t0;                t0 = t1;                t1 = temp;                n0 = -axis;                n1 = axis;            }

(you need to swap the normals at the collision points as well).

##### Share on other sites
there was an assert as well on the sort function.

    private static int CompareContacts(ContactPair c0, ContactPair c1)        {            if (c0.DistanceSquared == 0)                return -1;                        return (c0.DistanceSquared > c1.DistanceSquared) ? 1 : (c0.DistanceSquared < c1.DistanceSquared)? -1: 0;        }

I had to remove the first two lines.

    private static int CompareContacts(ContactPair c0, ContactPair c1)        {            return (c0.DistanceSquared > c1.DistanceSquared) ? 1 : (c0.DistanceSquared < c1.DistanceSquared)? -1: 0;        }

Probably some consistency checks...

##### Share on other sites
Horray! The man himself!! I can't tell you how thankful I am, lol. The code was so simple, that's why I ended up driving myself crazy. Maybe I won't push it so far in the future :D.

The vector float multiplication and normal swaps we're the two bug's i'd been missing. The assert in the CompareContacts was mostly a debug point, it shouldn't have been there. After those fixes, everything worked.

:) thanks again, your a lifesaver.

you're welcome

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×