Tremble, Ye Mortals

Posted by DesertFox on July 27, 2010, 9:47 p.m.

Tremble, ye mortals, for ye walk in the shadows of the gods, and your lives are but the footprints of their passing. I am your new god, and you shall bow before me as is my divine right!

In other news, I am officially a deific-level coder because I made something cool. 2D SAT-based collision detection and resolution of convex polygons and curved surfaces, with quadtree optimization, polygonal reduction, and inexpensive raycasting.

"Well, DF, that's quite a mouthful, but what does it all mean?" you might say…

Well, SAT means separating axis theorem, which states that with any two polygons can definitively said to not be colliding if their exists some axis along which the projection of the two polygons do not overlap. In layman's terms, if you can draw a straight line between the two polygons, they don't intersect. Simple, yes? Well, taking it one step further, it can also be definitively said that if the two polygons are both convex and not intersecting, then such a separating axis will be found perpendicular to one of the polygon's sides. In laymans terms, this means if the polygons are both convex and not touching, you can draw a straight line between the two that is parallel to one of the polygon's edges.

So why in hell would this be useful? Well, it not only tells you if the objects are colliding, it tells you very quickly, it tells you what axes to check, and it tells you not only *if* they are colliding, but also by how much and what angle. Which means one very simple thing. Realistic bounce, friction, and collisions. There are no "walls" or "floor" or "ceiling" or "slope" objects with special code to make them work. Just polygons - a wall is a ceiling is a floor is a slope, depending on the gravity vector. And curved surfaces - cant forget those. And its fast. All that blather about quadtrees and polygon reduction is just codespeak for making it run even faster.

Oh, also, delicious raycasting. It is very delicious raycasting, and quite fast, too. Allow me to show you an image of my raycasting test.

Oh look, an image!

Oh, cool, a green… shape? Wrong. All that green isn't some light pattern-shadow I pre-generated then drew. Its rays. Several thousand of them. They are recalculated every update, and redrawn every frame. It looks like one big shape, because the rays are so tightly packed together that there aren't any pixel gaps. And it does this on the fly at a steady 60fps, every frame, following my mouse.

And that little blue ball? Its sitting there because it wants to. Yeah. It fell into that little gap, and it stays there because it likes it there.

So what is this? Its basically a physics engine that I made from scratch. An accurate one. It only lacks one thing - rotational kinematics - and I know how to do that, so I just might.

Comments

Castypher 14 years, 2 months ago

Raycasting is extremely useful for dynamic shadows. As far as gameplay mechanics go though, I completely forgot. This was something I took note of long ago, and never found a use for.

DesertFox 14 years, 2 months ago

Kilin - one word. Lasers. Lots and lots of lasers. Lasers that change length, lasers that rotate, lasers that bounce, lasers that sweep. Lots and lots of lasers.

Also, hit detected from guns for bullets - and I mean real bullets and not stupid tiny spheres that move at like 12 pixels a frame. AI as well - cheap raycasting means that an enemy can more accurately determine whether or not it can see you. In fact lots of things :D

@Cyrus - oh yes…. Cameltry would be easy :D

blackhole 14 years, 2 months ago

I would be tempted to use this, but sadly I am already using box2D.

Kaz 14 years, 2 months ago

Neato! Very impressive. At least by my standards.

Ferret 14 years, 2 months ago

That is really cool DF, I remember you talking about it, but it kinda went over my head as something I should just read on my own. Btw I think you gave me a link to a pdf about it or something, do you still have it?

Castypher 14 years, 2 months ago

THIS

IS

CAKETOWN

blackhole 14 years, 2 months ago

NO

CAKETOWN IS A LIE.

Mordi 14 years, 2 months ago

Awesome

eagly 14 years, 2 months ago

COMMENT