Does this Character code look right to you?

dbrock

21-12-2007 01:10:31

Does this seem like the proper way to be setting up a character?

Ogre::Entity *charEntity = mSceneMgr->createEntity( "Entity", "Donkey.mesh" );
Ogre::SceneNode *charNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Entity" );
charNode->attachObject( charEntity );
charNode->setScale( Ogre::Vector3(1, 1, 1) );
charNode->showBoundingBox( true );

Ogre::AxisAlignedBox charAAB = charNode->getAttachedObject( "Entity" )->getBoundingBox();
Ogre::Vector3 min = ( charAAB.getMinimum() * charNode->getScale() );
Ogre::Vector3 max = ( charAAB.getMaximum() * charNode->getScale() );
Ogre::Vector3 center = ( charAAB.getCenter() * charNode->getScale() );
Ogre::Vector3 size( fabs( max.x - min.x), fabs( max.y - min.y), fabs( max.z - min.z ) );

NxOgre::CharacterParams characterParams;
characterParams.setToDefault();
characterParams.mDimensions.set( NxVec3( size.x, size.y, size.z ) );
characterParams.mType = NxOgre::CharacterParams::CT_Box;

mCharacter = mPhysScene->createCharacter(
"Player_Donkey",
NxOgre::Pose( Ogre::Vector3( 430, 230, 984 ), Ogre::Quaternion::IDENTITY ),
characterParams
);


It seems like a waste because I have to create an entity and a node to get the dimensions of my mesh to create the character, then use mCharacter->attachMesh( "donkey.mesh" ) to create the visible character, which is a 2nd entity to be created, along with mCharacter->createNode().

Does it also matter in which order you call createNode and attachMesh?

betajaen

21-12-2007 09:17:58

Why not create the node, then get the node and attach your entity. Instead of using attachMesh?

dbrock

21-12-2007 22:27:33

Touché. But then I seem to have trouble with the animations, it's saying the mesh doesn't contain any.

Ogre::Entity *charEntity = mSceneMgr->createEntity( "Donkey_Entity", "Donkey.mesh" );

// Character node
mCharacter->createNode();
mCharacter->getNode()->attachObject( charEntity );
mCharacter->getNode()->setScale( Ogre::Vector3(1, 1, 1) );

// Animation setup
Ogre::AnimationState *animation = ( ( Ogre::Entity* ) mCharacter->getNode()->getAttachedObject( "Donkey_Entity" ) )->getAnimationState("Action_Run");
animation->setEnabled( true );
animation->setLoop( true );


Edit: Fixed. =)