Jump to content
  • Advertisement
  • entries
  • comments
  • views

Getting there slowly

Sign in to follow this  


Getting there.

I've been re-working through the tutorials on SAT and polygon collision response, but actually writing my own code based on the tutorials rather than copy-paste-fiddle-about like last time.

Much happier with the results. I don't pretend to fully understand it all, but I certainly understand it better than last time.

And, more importantly, I've managed to derive my own circle-circle and circle-polygon collision detection and response SAT stuff.

So unlike the previous demos I was releasing, a circle can be represented by a point and a radius now, rather than a many sided polygon.

Obviously the circle-polygon SAT is now more efficient, since (and I could have this wrong, but it works on screen) the only axes I need test are the normals of the polygon, plus one axis running parallel to the centre of the circle and either the centre of or one of the vertices of the polygon.

I can't really visualise why that works, but the tests I've run all detect correct collisions or the lack of, and the push vector (which I then normalise to use to reflect the angle with Vel=Vel-(2*Vel dot Normal)*Normal ) always seems to be correct.

And, hopefully even more obviously, circle-circle tests are far, far faster since there is no actual SAT involved, just a simple distance-between-centres < radius+radius to find an intersection, then just the subtraction of the distance from the sum of the radii, to get the push distance, then centre-centre to get the push direction, normalised then multiplied by the push distance to get the push vector.


Certainly all progress.

[EDIT] Nope - the circle/polygon tests are failing under some strange circumstances. Back to the drawing board. Bugger.

[EDIT] Got it working after many hours of messing about.

Just a daft GDI based app that bounces the white ball about off the random shapes. All seems to be okay.

DEMO here if you want to test it. Click the mouse to make the ball move towards where you click.

Scrap all that about the circle-polygon stuff above though. I'm now just testing the normals to the axes of the polygon, and projecting the circle onto the axis by first normalising the axis, then calculating the min and max for the circle like:


Seems to work.

[EDIT] Not quite. Actually also seem to need to test along each axis that is defined by the centre of the circle and each vertex of the polygon. Demo not updated but that seems to be perfect now.
Sign in to follow this  


Recommended Comments

Very cool! Great work! (Though if you want to be technical [and I'm sure you don't, but I'm going to say it anyway because I'm kinda bored], you ARE using a much-simplified version of the separating axis test for circle/circle collisions, it's just that you only need to test along one axis, which is the axis on which both circle centers lie).

Also (in response to your last post), good to see that you finally have a job that you like! It makes all the difference :) Congratulations!

Share this comment

Link to comment
Makes sense I guess. I suppose it is a bit like the way a simple AABB intersection test is a highly specialised form of SAT.

My demo has been running all day while at work, and the ball hasn't got stuck anywhere, so I'm happy it's working.

Next up, some specialisations for finding if a point is inside a polygon. Obviously point in circle is very trivial, but I figure point in polygon can be done just like circle in polygon, but just projecting the point onto each test axis rather than either side of the circle.

Then we've reached a good milestone and have to start dreaming up a game to actually use all this cool stuff [smile].

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!