I have created a class which loads a mesh model, loads its texture, creates a mesh node for it, then sets it up for physics simulation. This all works fine, however when I try to manipulate the meshNode(in this case by changing its position) nothing seems to happen. Now, it doesn't cause any runtime errors or compilation errors, but it also doesn't seem to work either.
Here is the class itself:
Code: Select all
class GaimMesh {
public:
//we create the needed public variables for use within the class
IAnimatedMesh* Mesh;
IAnimatedMeshSceneNode* MeshNode;
IGImpactMeshShape* thing;
IRigidBody *body;
//set up the constructor function
GaimMesh (ISceneManager*, IVideoDriver*, IrrlichtDevice*, irrBulletWorld*, std::string, std::string, int, vector3df);
//set up the set position function
void SetPos ();
//vector3df GetPos();
};
//this is the constructor for the 'player mesh' class
//this is where the guts of the class is located
GaimMesh::GaimMesh (ISceneManager* manager, IVideoDriver* drvr, IrrlichtDevice* dvice, irrBulletWorld* w0rld, std::string MPath, std::string TPath, int mass, vector3df blah) {
//first load the .b3d mesh, the path and name of which will be specified when an instance of the class is created
Mesh = manager->getMesh(MPath.c_str());
//create a SceneNode for the mesh
MeshNode = manager->addAnimatedMeshSceneNode(Mesh);
MeshNode->setPosition(vector3df(blah));
//set the texture and rendering options for the mesh
MeshNode->setMaterialFlag(EMF_LIGHTING, false);
MeshNode->setMaterialTexture(0, drvr->getTexture(TPath.c_str()));
//finally create the needed bullet physics mesh shape and rigid body in order to use the mesh for simulation purposes
thing = new IGImpactMeshShape(MeshNode, dvice->getSceneManager()->getMesh(MPath.c_str()), mass);
body = w0rld->addRigidBody(thing);
};
void GaimMesh::SetPos () {
MeshNode->setPosition(vector3df(0, -30, 0));
};
and here are the two different instances of the class:
Code: Select all
GaimMesh PMesh (smgr, driver, device, world, "c:/gamemedia/b3dtest.b3d", "c:/gamemedia/UV.jpg", 5.0, vector3df(0, 0, 0));
GaimMesh GMesh (smgr, driver, device, world, "c:/gamemedia/terrmesh3.b3d", "c:/gamemedia/grassy9.jpg", 0.0, vector3df(0, -20, 0));
PMesh.SetPos();
PMesh.MeshNode->setPosition(vector3df(0, -30, 0));
//IRigidBody *Gbody = world->addRigidBody(Gthing);
cam->setParent(PMesh.MeshNode);
As you can see when first created, the PMesh instance is placed right above the GMesh instance so that when the game starts, the PMesh will fall on top of GMesh. However, the call to SetPos() is supposed to place PMesh underneath GMesh, thus causing it to merely fall for as long as the simulation runs. Unfortunately, this change in position never happens and when I start the game PMesh is still above GMesh.
As far as I recall, since the variable MeshNode is still in public, I should not only be able to do stuff to it in other parts of the class itself, but all over the program as well. And I know that I have some kind of access to the MeshNode variable because I can set objects as children from the main program. I'm guessing that the problem is something simple and fundamental that I just missed, so I am hoping that some extra sets of eyes will be able to see what the problem is.
As always, thanks in advance.