collision question

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
boredom

collision question

Post by boredom »

hi,

i'm trying to use some simple collision detection to figure out when the camera (not it's view target, the actual camera, as in it's bounding box) collides with a model. i don't want the camera to be affected, i just want the other model to disappear (it's for item pick-ups). i thought i had it working for the most part, but i soon found out i was using the getCollisionPoint function, which of course means i had to look at the item to pick it up. Should i use this function and cast multiple rays away from the camera? or use another function altogether?

thanks very much!
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

A simple way would be to bind a TestSceneNode (Cube) to the location of the camera then use it to generate collision events for the camera.

Since the vertices for the cube point the other way, nothing would be visibly rendered to the camera.
Crud, how do I do this again?
boredom

Post by boredom »

thank you for the reply!

and how would i generate collision events for the cube? i can't seem to find any functions that simply take into account 2 bounding boxes...
Cleves
Posts: 224
Joined: Mon Sep 08, 2003 6:40 pm

Post by Cleves »

mm..i wanted to know to how to attach events to a collition that has accured
cyberbobjr
Posts: 64
Joined: Mon Sep 08, 2003 8:21 am
Location: Paris, France

Post by cyberbobjr »

Hi,
I give you the solution i used for my game (in progress ;)) :
Make a linked list of all objects in your world. For example make a linked list of "ObjectWord"

the ObjectWorld contain :
mesh (for reuse)
node
position
internal data (ie : for weapon you can store range, ammo, etc.)
etc.

When a displacement of the camera raise, make a function which will check the distance between object and camera (irrlicht provide a function for that : vector3df = getDistance(vector3df pos)) for all the objects in your linked list....

In details, this is how i do that :

I've created a virtual base class (IEntity), and inside i have some pure virtual function like :
virtual onGet(IPlayer* player)=0;

After, i've created a derivated class based on IEntity : IWeapon
class IWeapon : public IEntity ...

I've implemented the virtual function onGet... :

Code: Select all

IWeapon::onGet(IPlayer *joueur)
{
if (joueur->addInventory(this))
{
world->removeNode(this);
};
};
Next, the linked list scan all object and check the distance between player's position and object's position :

Code: Select all

if player->getPos().getDistance(object->getPos())<10 then ObjectWorld->getEntity()->onGet(player);
etc.

With this solution you'll have a link between 'irrlicht node' and 'object in your world' and probably you gain speed : i think that getDistance is less CPU consumer that collision detection... Niko, i'm right ?

And sorry for my bad english, i you want code and UML datagramm, i'll can send you !
bye.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

I think cyberbobjrs approach is nice. Very fast at least. :)
boredom

Post by boredom »

thank you very much! it never occurred to me to just use distances...it works great!
Post Reply