I do _not_ really have THE IDEA how to solve that problem. So what do we have? We have a triangle (we collided with),a MetaTriangleSelector and a lot of ISceneNodes (we could have collided with).
So, what do we need to know MORE? Well, it is probably quite useful to know what TYPE of node collided with what TYPE of node. (sorry, bad english) But in fact if you fire a rocket on a wall, the wall keeps on staying but if you hit a little rabbit... you can imagine
.
So one way of doing something like handling the collision detection is:
Derive a ICollSceneNode from ISceneNode and add a virtual method called somthing like
Code: Select all
virtual const ICollSceneNode* ICollSceneNode::OnCollision( const irr::ITriangle& _tri, const ICollSceneNode* _node) const;
and a method returning the type of an object. Something like:
Code: Select all
// we need an attribute to safe the typeinfo
class ICollISceneNode : public ISceneNode
{
...
const irr::s32 TypeID;
...
};
// here is the method
const irr::s32 ICollSceneNode::getTypeId() const { return TypeID; };
If you now build a new interface for an object (maybe a little rabbit
), do it like that.
Code: Select all
IKillableRabbit : public ICollSceneNode
{
//... like in the ISceneNode tutorial you have to overload some abstract functions
// pseudo code in a header, dopple bad :-(
const ICollSceneNode* OnCollision( const irr::ITriangle& _tri, const ICollSceneNode* _node) const
{
if( _tri in TriangleSelector)
{
switch( _node->getTypeID())
// ... case
case TheCruelRocket: // blow the rabbit
// ...so far so good
return this;
}
} // IKillableRabbit
const IKillableRabbit::TypeID = KillAbleRabbitID; // so we have a hardcoded id of each rabbit
// somewhere of your probject should be a enumaration of all objects
enum ECollObj
{
KillABleRabbitID = 1,
TheWall = 2
}
So how does it the collision look like. Well, Irrlicht tells you that a collision has happend, your code _on top_. Now, we go through each object in a list of ICollSceneNodes, everyone needs to have a its TriangleSelector attached to it if it can collide. If the triangle we collided with is one of the objects triangles in the selector... we react, see switch and return a pointer to the object so we can handle the collision.
Code: Select all
void yourfunction()
{
//collision has happened
// loop through all ICollSceneNodes
for(..)
{
if ( ICollisionNode* _coll = node->OnCollision( triout, this))
{
// here we go...
switch (_coll->getTypeID)
case KillableRabbitID:
// blow, reflect do whatever you like
}
}
}
PS: sorry, about the rabbit