Manipulating a meshNode that's been created within a class

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
Whirled Peas
Posts: 47
Joined: Mon Jan 10, 2011 8:01 pm
Location: SoCal

Manipulating a meshNode that's been created within a class

Post by Whirled Peas »

I am once again before you, oh wise elders of the Irrlicht forum, requesting help once more on another situation that has gotten me stumped.

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);


They both set up all the constructor parameters and whatnot. The SetPos() function was originally set up to take a vector3df as a parameter when it got called, but I was wondering if the issue involved the variables I was using so I just had the function use a set of predetermined coordinates.

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.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

My guess is that either gravity is 0, or you forgot to update physics
Working on game: Marrbles (Currently stopped).
Whirled Peas
Posts: 47
Joined: Mon Jan 10, 2011 8:01 pm
Location: SoCal

Post by Whirled Peas »

Gravity is set to 0, -10, 0 and all those lines of code have been entered before the physics simulation begins. Is it possible that setPosition won't work because the physics simulation overrides all other transforms?



EDIT:

Okay, so while I haven't found an exact solution to the problem, you did get me thinking about the physics simulation as is related to the cause. I had never considered that the simulation would override functions like setPosition(), although I probably should have. Anyway, I went into the class constructor and moved the initial setPosition() function call so that it came after creating the rigid body, and it turns out that it doesn't work. So, now I realize that it is related to the physics engine, not Irrlicht itself.

Thanks serengeor, although you didn't technically give me the solution you definetly pointed me in the right direction. Thanks a ton.
Last edited by Whirled Peas on Tue Mar 08, 2011 8:35 pm, edited 1 time in total.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Whirled Peas wrote:Gravity is set to 0, -10, 0 and all those lines of code have been entered before the physics simulation begins. Is it possible that setPosition won't work because the physics simulation overrides all other transforms?
Your set position function should set position of the physics body not the other way around, just to avoid any possible problems. And do the same for rotations, tough rotations are a bit trickier if you want to do them in game loop.

And again, do you call physics update function in your game loop?
Working on game: Marrbles (Currently stopped).
Whirled Peas
Posts: 47
Joined: Mon Jan 10, 2011 8:01 pm
Location: SoCal

Post by Whirled Peas »

serengeor wrote:
Whirled Peas wrote:Gravity is set to 0, -10, 0 and all those lines of code have been entered before the physics simulation begins. Is it possible that setPosition won't work because the physics simulation overrides all other transforms?
Your set position function should set position of the physics body not the other way around, just to avoid any possible problems. And do the same for rotations, tough rotations are a bit trickier if you want to do them in game loop.

And again, do you call physics update function in your game loop?

By update, do you mean a call to stepSimulation, or to updateCollisionObjects?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post by serengeor »

Yeah step simulation.

Maybe you have something in the game loop that prevents nodes from moving. I'm out of ideas now :roll:
Working on game: Marrbles (Currently stopped).
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

do you have your physics engine interacting with the graphicsNode position through an animator? or are you just doing manually?
Whirled Peas
Posts: 47
Joined: Mon Jan 10, 2011 8:01 pm
Location: SoCal

Post by Whirled Peas »

ChaiRuiPeng wrote:do you have your physics engine interacting with the graphicsNode position through an animator? or are you just doing manually?
I'm just using the physics engine to run the simulations, no animators as of yet. I actually want to run just about all transformations through the physics engine with little to no direct node manipulation, although I was hoping to implement a sort of 'teleportation' type of effect, which of course would require the ability to manually set the position coordinates of an object.

At this point, I'm pretty sure that the issue is the fact that Bullet overrides any direct transformation controls that Irrlicht has(although maybe not animators), anyway, I'm looking to see if I can just accomplish my goal by working through Bullet, since that seems to be the source of my 'trouble'.
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

Whirled Peas wrote: I'm just using the physics engine to run the simulations, no animators as of yet. I actually want to run just about all transformations through the physics engine with little to no direct node manipulation, although I was hoping to implement a sort of 'teleportation' type of effect, which of course would require the ability to manually set the position coordinates of an object.

At this point, I'm pretty sure that the issue is the fact that Bullet overrides any direct transformation controls that Irrlicht has(although maybe not animators), anyway, I'm looking to see if I can just accomplish my goal by working through Bullet, since that seems to be the source of my 'trouble'.
no i dont think you understand. i say animator i mean the internal way irrlicht handles mainupulating node positions.
i have seen a common way for bullet integration with irrlicht is to create custom animator class which acts as buffer between bullet and irrlicht.
Whirled Peas
Posts: 47
Joined: Mon Jan 10, 2011 8:01 pm
Location: SoCal

Post by Whirled Peas »

ChaiRuiPeng wrote: no i dont think you understand. i say animator i mean the internal way irrlicht handles mainupulating node positions.
i have seen a common way for bullet integration with irrlicht is to create custom animator class which acts as buffer between bullet and irrlicht.
I understand that, and while I do know that that is the way in which bullet integration into Irrlicht is often accomplished, it is not guaranteed that that is the way it is done with irrbullet. I got the impression that you were asking me if I personally used any animators to handle the physics simulation beyond whatever irrBullet does on its own when it is implemented, I did not. Whether or not this is how irrBullet handles it, I do not know. However, I have posted questions regarding this in the irrBullet thread over in 'Project Announcements'
Post Reply