Showing posts with label experiments. Show all posts
Showing posts with label experiments. Show all posts

Monday, December 14, 2009

Precision Collision Detection

I was playing around with Corey O'Neil's collision detection engine and while it is very good for working with most simple shapes; I was missing a crucial piece of information when it came to working with more irregular shapes.

What I'm referring to here is the 'normal of collision'.
With Corey's kit, we can acquire an 'angle of collision'; this angle is useful if working with circles because the angle of collision in this case is equivalent to the angle made by the collision normal.
In some more complex cases, however, the angle of collision doesn't give us the necessary information to determine the 'bounce angle'.

It's a bit difficult to explain, so I'll just show you.
Here is corey's kit (the red line shows the angle of collision):

^ The number of milliseconds it takes to calculate the collision is shown in the white textbox.

Basically, with Corey's kit, we can only get a precise angle of collision between two shapes if one of those shapes is a circle.

Here is my version:

Notice that now we can get an accurate bounce angle from the normal of collision.
Also, check out the improvement in speed from Corey's kit!
I'm considering releasing my code publicly, but I'll have to do a bit of code commenting first ;p

I followed Skinner's concept of using BitmapData to perform the collision testing and used a great deal of bitmap processing and vector math to evaluate the normal of collision. I still have to do a bit of tweaking to optimize performance. But so far it gets the job done.

Saturday, November 28, 2009

Back to Flash

I've been doing some work in Flash using ActionScript 3.
I've started planning for a whole series of online games that will revolve around a common theme.

So far, I've created some engines including a flexible application page-manager and a pretty cool soft-body physics library that allows soft-body objects to react to physical 'force fields'.

Here's a link (Press any key to reset)

The math used there is fairly heavy. It uses many physical concepts surrounding motion, mass, elasticity (Hooke's law) and linear algebra. It's somewhat physically accurate except for air resistance (I cheated a bit there)... Physicists hate air resistance anyway so who cares.

As you might notice, the body is in a zero-gravity environment with so-called 'air resistance'.
The body is made up of special points of a given mass which react to force vectors, the body itself reacts to 'force beams' which vary in magnitude, area of effect and dissipation effects (distance from source and distance from center of beam).

Obviously there are missing physical elements such as dissipation of force via contact but on the whole it's a nice addition to my portfolio.