Making a particle system track a bone?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
InfinityComplex
Halfling
Posts: 41
Joined: Mon Jul 04, 2005 11:24 pm

Making a particle system track a bone?

Post by InfinityComplex »

Is it possible to do this?

I tried,

Code: Select all

class Particles{
public:
       Particles( String name,String psys,Bone *attach){
             rSys = ParticleSystemManager::getSingleton().createSystem( name,psys );
             node = gsmgr->getRootSceneNode()->createChildSceneNode();
             node->attachObject( rSys ); 
             bone = attach; 
       };
       Particles( String name,String psys,SceneNode* parent=NULL){
             rSys = ParticleSystemManager::getSingleton().createSystem( name,psys );
             if(parent==NULL){
                 node = gsmgr->getRootSceneNode()->createChildSceneNode();
             }else{
                 node = parent->createChildSceneNode();
             };
             node->attachObject( rSys );        
                         
             
       };
       ~Particles(){
       };
       void update(){
            if(bone!=NULL){
               node->setOrientation( bone->getWorldOrientation() );
               node->setPosition( bone->getWorldPosition() );
            };
       };
       
       void AttachTo( SceneNode *aTo){
           //      aTo->attachObject( node );
       };
       void AttachSub( SceneNode *aSub){
       //      node->attachObject( aSub );
       };
private:
SceneNode *node;
ParticleSystem* rSys;
Bone *bone;
};
Which basically sets the node the particle system is attached to, to the world position of the bone and the orientation to the world orientation of the bone.

The result is although the particle system seems to rotate as the bone does, it doesn't match or appear to be in sync.
Also, the set position has no effect, it stays isolated at 0,0,0 where the bone starts.

The bone in question being joint10 of the robot mesh.

Any ideas?

Is it not possible to attach a scene node to a bone so the particle system it's self is updated by the engine instead of the manual code I'm using?
User avatar
Nek
Gnoblar
Posts: 21
Joined: Mon Aug 18, 2003 6:06 pm
Location: Houston, Tx
Contact:

Post by Nek »

Try attaching the particle system to the bone itself. That way, when the bone moves, particles move as well.

Code: Select all

Ogre::Entity * mEntityToAttachTo->attachObjectToBone(strUnmanagedBoneName, mEntity);
InfinityComplex
Halfling
Posts: 41
Joined: Mon Jul 04, 2005 11:24 pm

Post by InfinityComplex »

D'oh, didn't think to look for it in the entity class. Works now.
Thanks.
Post Reply