Predicting collisions

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
matthewbaynham
Posts: 1
Joined: Tue Oct 18, 2022 5:54 pm

Predicting collisions

Post by matthewbaynham »

I see that irrlicht has collision detection so that once there is a collision it is detected.

However my question is about predicting a collision before they happen.

So if I'm in a car and another car is heading straight for me irrlicht will be able to predict that the two cars are heading towards each other before they crash?

Also can irrlicht predict when the other car heading towards a 100 meter radius of me, but is not there yet?

Do you know of any tutorial for predicting collisions?

I see tutorial 7 is for collisions that have already happened, that's not the same as predicting.
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Predicting collisions

Post by CuteAlien »

This is stuff that needs to be coded, thought Irrlicht can help a bit. ISceneCollisionManager has for example collision functions which take rays as input. The usual trick to find collisions before they happen is to have rays which go a bit in front of the object and once the ray hits and your object is moving in the same direction you can expect a collision to happen soon (details depend on your system for movement). Another way Irrlicht can help you is that scenenodes calculate their transformation matrices - and matrices have functions to transform vectors. So you can easily calculate rays going in the same direction as a node.

Getting radius between 2 objects is trivial - it's simply the distance. If it's heading toward you is a bit math. First find the direction of your node. Same as before: get the transformation matrix of the node - then transform a vector by that. Works as long as the vector starts by looking in wherever on your model your "front" is (depends on the model, usually 0,0,1 or 1,0,0 or maybe some minus involved).
edit: If you are only interested in "front" direction (and not something like 15° to left/right) you can also get the direction directly from the node's transformation matrix itself. It's one of the row's of the inner 3x3 matrix (usually matrix indices 0,1,2 or 8,9,10).
Then get the direction between two cars - simply subtract positions. And to check if 2 vectors go in the same direction you can use the vector dot product (it's >0 for same, 0 for perpendicular and <0 for different directions).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply