adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-devel] Would you believe it - Vector collision demo available


From: Alexandre Courbot
Subject: [Adonthell-devel] Would you believe it - Vector collision demo available!
Date: Thu, 12 Sep 2002 21:01:49 +0200

Hi guys!

No, your eyes aren't fooling you - I got this vector collision test
finished! And it is available for you to check!

First make sure to update your 0.4 branch, as I did a few changes, the
most noticeable being that input events can be given Python functions as
callbacks. As I did this first implem entirely in Python (because it's a
language of choice for programming on the Zaurus during my train travel
;)), it was necessary.

So, update your CVS copy, and compile it pytest. Then copy
src/gfx/gfx.py and src/input/input.py into src/, as well as
test_intersec.py that is attached to this mail. Then run "./pytest
test_intersec.py" from src/. You can move the first polygon with the
arrow keys, escape to quit. I pay a beer to the one who manage to make
it enter inside the second one! (with a screenshot as a proof! ;))

You can easily change the shape of the objects. Just edit
test_intersec.py, search for the string "#####", and you'll find the
definition of the objects. They are defined by their points, add/remove
some, change them as you with. In every correct case, the demo should
remain consistent. By "correct" I mean the lines of a single object must
*never* intersect with each other.

While moving, the red lines are the velocity vectors and the blue lines
the sides of the object that the objects might collide with regarding
the direction they are heading to. If a velocity line if obj1 collides
with a blue side of obj2 (or the contrary), then a collision occurred.
The collision function let us know the exact point of the intersection
(rounded to the external point), so obj1 can be placed accurately.
Getting the external point (and not the internal one, otherwise the
object pass through the other one) was quite problematic, but the
solution is quite simple: whenever the velocity vector of obj1 has a
negative coordinate, invert all the points, and if a collision occurred
invert the collision point as well! Fast and efficient. As the rest, I
hope. All the calculations are done using integers (big ones, to keep a
good precision), and there is only a division I wasn't able to get rid
of. There are also *plenty* of useless statements and objects transferts
for debugging purpose that are not used anymore (just commented out the
line that printed them ;)), it's written in Python, and it looks pretty
fast (at least, much faster than my first implem that was using floats
and ate all the CPU on my Athlon 850!). At least, this program is the
proof that you can even write pig code in Python! :)

The next step is to make the objects slide when you insist on moving
them after a collision. Once this is done, I'll write the C++ implem,
and this will be a very good start for the new mapengine. I'm very glad
it works, I don't remember who triggered this idea during the meeting
(considering the weirdness, probably one of the gfx guys ;)) but it is
excellent and I can now say that our new map engine will successfully
use it!

Have fun guys!
Alex.
-- 
http://www.gnurou.org

Attachment: test_intersec.py
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]