Setting position of Node and Body

TrackGuy

23-08-2006 09:31:51

Hello,

I just want to find out what the most elegant solution for the following question is:

Entity* cylinder = mSceneMgr->createEntity ( "Cylinder", "cylinder.mesh" );
cylinder->setNormaliseNormals ( true );
cylinder->setMaterialName ( materialname );

SceneNode* cylindernode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
cylindernode->attachObject ( cylinder );
cylindernode->scale ( height, radius, radius );

// Does this setposition make sence?
cylindernode->setposition ( pos );

OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Cylinder ( m_World, radius, height );
OgreNewt::Body* bod = new OgreNewt::Body ( m_World, col );
delete col;

Real mass = radius * 2 * 3.14 * height;
Vector3 inertia = OgreNewt::MomentOfInertia::CalcCylinderSolid ( mass, radius, height );

bod->attachToNode ( cylindernode );
bod->setMassMatrix ( mass, inertia );
bod->setStandardForceCallback();

// or is it better to do it (only?) here?
bod->setPositionOrientation ( pos, Quaternion::IDENTITY );


The code works with possettings for both (node and body) and with possetting only for the body. But I am not sure if it is good to set both because I could imagine that there are maybe some offset problems arising ...

Hansel

23-08-2006 09:56:58

When you use setPositionOrientation your body gets the asigned position and the node too (because it's attached to the body). You can use setPositionOrientation to set the position of the "object" in the world the first time you initialise it or, also, if you want to move it to an exact point. Otherwise, if you want to simply move your object over the world you have to use addTorque and SetVelocity (specially this one) ;)