hoffhoff
06-08-2006 20:39:54
Hello,
I have ogrenewt working fine, the movement of the player and so on. Now I´m trying to start with materials and the collision callbacks. For now, all I want to do is to close the program (exit(0)) when two objects collides.
So, my contact callback is like this:
then I created another class to hold all the materials informations:
Ok. Then, in the main code:
I have ogrenewt working fine, the movement of the player and so on. Now I´m trying to start with materials and the collision callbacks. For now, all I want to do is to close the program (exit(0)) when two objects collides.
So, my contact callback is like this:
#include "CContactCallback.h"
CContactCallback::CContactCallback(int ID) : OgreNewt::ContactCallback()
{
}
CContactCallback::~CContactCallback(void)
{
}
int CContactCallback::userProcess()
{
exit(0);
return 1;
}
then I created another class to hold all the materials informations:
//.h:
#include "CContactCallback.h"
#define MAT_DEFAULT 0
#define MAT_WOOD 1
#define MAT_METAL 2
#define MAT_GRASS 3
#define MAT_HUMAN 4
#define TOTAL_MATERIALS 5 // Useful while working with defines.
class CMatCollision
{
private:
OgreNewt::World* myWorld;
const OgreNewt::MaterialID *mat_vector[TOTAL_MATERIALS], *matdefault;
OgreNewt::MaterialPair* mat_pair_human_metal;
CContactCallback *cont;
public:
CMatCollision(OgreNewt::World* nworld);
~CMatCollision(void);
void CreateMaterials();
const OgreNewt::MaterialID* getMaterialID(int matnum);
void startPairs();
};
//.cpp
#include "CMatCollision.h"
CMatCollision::CMatCollision(OgreNewt::World* nworld)
{
myWorld = nworld;
CreateMaterials();
}
CMatCollision::~CMatCollision(void)
{
}
void CMatCollision::CreateMaterials()
{
int i;
for (i=0; i < TOTAL_MATERIALS; i++)
{
mat_vector[i] = new OgreNewt::MaterialID( myWorld);
}
matdefault = myWorld->getDefaultMaterialID();
}
const OgreNewt::MaterialID* CMatCollision::getMaterialID(int matnum)
{
return mat_vector[matnum];
}
void CMatCollision::startPairs()
{
cont = new CContactCallback(1);
mat_pair_human_metal = new OgreNewt::MaterialPair( myWorld, mat_vector[MAT_HUMAN], mat_vector[MAT_METAL] );
mat_pair_default_default->setContactCallback(cont);
mat_pair_human_metal->setDefaultElasticity(1000000);
mat_pair_human_metal->setContactCallback(cont);
}
Ok. Then, in the main code: