Hi,
Finally i have made the groundwork of my rocket animation, i used a spehere 
until i find a rocket model :D and still, there is something that didnt get 
clear!
Note: some codes below are taken from the osgparticleeffects example.

Code:

osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float 
radius,double looptime)
{
    // set up the animation path
    osg::AnimationPath* animationPath = new osg::AnimationPath;
    animationPath->setLoopMode(osg::AnimationPath::LOOP);

    int numSamples = 40;
    float yaw = 0.0f;
    float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f);
    float roll = osg::inDegrees(30.0f);

    double time=0.0f;
    double time_delta = looptime/(double)numSamples;
    for(int i=0;i<numSamples;++i)
    {
        osg::Vec3 
position(center+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f));
        osg::Quat 
rotation(osg::Quat(roll,osg::Vec3(0.0,1.0,0.0))*osg::Quat(-(yaw+osg::inDegrees(90.0f)),osg::Vec3(0.0,0.0,1.0)));

        
animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));

        yaw += yaw_delta;
        time += time_delta;

    }
    return animationPath;
}

int main(int argc, char *argv[])
{
    osgViewer::Viewer viewer;
    osg::Group * root = new osg::Group;
    osg::Geode *rocketModel = new osg::Geode;
    osg::Sphere *rocket = new osg::Sphere;
    /////////////////////////////////CREATE 
SPHERE//////////////////////////////////////////////////
    //    rocket->setCenter(osg::Vec3f(0,0,0));
    rocket->setRadius(1.1f);
    osg::ShapeDrawable* rocketDrawable = new osg::ShapeDrawable(rocket);
    rocketModel->addDrawable(rocketDrawable);

    //////////////////////////////////ANIMATION 
LOOP//////////////////////////////////////////////
    float animationLength = 10.0f;
    float radius = 10;
    osg::Vec3f center(0,0,0);

    osg::AnimationPath* animationPath = 
createAnimationPath(center,radius,animationLength);

    const osg::BoundingSphere& bs = rocketModel->getBound();
    float size = radius/bs.radius()*0.15f;

    osg::MatrixTransform* positioned = new osg::MatrixTransform;
    positioned->getOrCreateStateSet()->setMode(GL_NORMALIZE, 
osg::StateAttribute::ON);
    positioned->setDataVariance(osg::Object::STATIC);
    positioned->setMatrix(osg::Matrix::translate(-bs.center())*
                          osg::Matrix::scale(size,size,size)*
                          
osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,1.0f));

    osg::PositionAttitudeTransform* rocketPath = new 
osg::PositionAttitudeTransform;
    rocketPath->setDataVariance(osg::Object::DYNAMIC);
    rocketPath->getOrCreateStateSet()->setMode(GL_NORMALIZE, 
osg::StateAttribute::ON);
    rocketPath->setUpdateCallback(new 
osg::AnimationPathCallback(animationPath,0.0,0.5));

    /////////////////////////////////SMOKE 
TRAIL////////////////////////////////////////////////////
    osg::Vec3 position = rocket->getCenter()+ 
osg::Vec3f(rocket->getRadius()/2,rocket->getRadius()/2,rocket->getRadius()/2);
    float scale = 1000.0f * ((float)rand() / (float)RAND_MAX);
    float intensity = 11.0f;

    osgParticle::FireEffect* fire = new osgParticle::FireEffect(position, 
scale, intensity);
    osgParticle::ParticleEffect* smoke = new 
osgParticle::SmokeTrailEffect(position, scale, intensity);

    smoke->setUseLocalParticleSystem(false);
    fire->setUseLocalParticleSystem(false);

    
/////////////////////////////FINAL//////////////////////////////////////////////////////////////

    rocketModel->addDrawable(fire->getParticleSystem());
    rocketModel->addDrawable(smoke->getParticleSystem());

    positioned->addChild(rocketModel);

    rocketPath->addChild(positioned);
    rocketPath->addChild(fire);
    rocketPath->addChild(smoke);

    root->addChild(rocketPath);

    viewer.setSceneData(root);

    return  viewer.run();
}


there is no problem with this, the fire and smoke effect follows the surface of 
sphere growing up direction.
[Image: http://forum.openscenegraph.org/files/untitled_185.png ]
here is my questions:
1) if i take the line 

Code:
rocketModel->addDrawable(rocketDrawable);


under the final section the fire and smoke trail effect's direction changes to 
down. is this a bug from osg?

2) why we had to add fire and smoke effects twice? shouldnt it enough to add 
these particle systems to rocket model and see "vuola! it moves with it!"? (i 
achieved to goal after several tries)
3) i also tried to wind these effects like in the example, i setwind with 
osg::Vec3 combinations but didn't work.?
4) i see very bad smoke effect unlike the example, i've tired optimiesed but 
didnt work.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45565#45565




Attachments: 
http://forum.openscenegraph.org//files/untitled_455.png


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to