Spline and ball hit testing

Started by
1 comment, last by umbrae 16 years ago
Hello! I am working on a variant of break out and instead of using normal rectangles I'm using polygons. Hittesting the ball with the edges and the corners of the polygon is no problem. But I want some edges to be smooth. So I'm turning each "smooth corner" and the two connecting edges of it into the simplest form of spline, which is basically a two dimensional second order polynom. Does anyone know how to hittest this type of shape with a ball moving in a straight line?
Advertisement
Wrong forum - moving to Game Programming.
As long as you keep the curves more gentle than the (I'm presuming) circular ball there are a few short-cuts you can make. All you need is an inside / outside test, just move the curve 1 radius of the ball towards the ball then test if the centre of the ball is inside or outside the curve.

If you have the curve expressed as a simple equation just turn the equation into an inequality, pass the ball's centre into the equality and it should tell you inside / outside.

Otherwise the normal methods apply, the separating axis theorem (for convex), or a ray through the centre of the ball and through some part of the curve. Travel along the ray and count the number of times the ray crosses the curve. Using this you can work out if the ray is inside the curve or outside at the centre of the ball.

Another approach is rasterise the curve into a polygon. Then just use normal polygon collision methods which should be easy to look up. If you are rendering you will have to do this anyway.

I guess that last approach is to not use curves, or use curves for the editor but convert them in game.

[Edited by - Umbrae on April 22, 2008 7:45:58 AM]

This topic is closed to new replies.

Advertisement