PolyColly issues

Started by
5 comments, last by oliii 14 years, 11 months ago
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.
Advertisement
you could have asked before going mad :)

I'm having a look right now.


Everything is better with Metal.

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);        }


Everything is better with Metal.

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

Everything is better with Metal.

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

Everything is better with Metal.

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

Everything is better with Metal.

This topic is closed to new replies.

Advertisement