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!
collision question
-
boredom
-
cyberbobjr
- Posts: 64
- Joined: Mon Sep 08, 2003 8:21 am
- Location: Paris, France
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... :
Next, the linked list scan all object and check the distance between player's position and object's position :
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.
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);
};
};
Code: Select all
if player->getPos().getDistance(object->getPos())<10 then ObjectWorld->getEntity()->onGet(player);
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.