Show
Ignore:
Timestamp:
04/09/09 16:25:14 (5 years ago)
Author:
robert
Message:

From Ravi Mathur, "OK I have been away for a looong time, but still occasionally watching from a distance, and saw the bug people have reported about the DepthPartitionNode? not handling scaled models properly.

I believe this is now fixed ... I have attached the new DistanceAccumulator?.cpp, along with a modified example file that uses a PositionAttitudeTransform? to draw the Earth's orbit around the Sun."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgdepthpartition/osgdepthpartition.cpp

    r6941 r10001  
    3939    osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable; 
    4040    osg::Sphere* earth_sphere = new osg::Sphere; 
     41    earth_sphere->setName("EarthSphere"); 
    4142    earth_sphere->setRadius(r_earth); 
    4243    earth_sd->setShape(earth_sphere); 
    4344    earth_sd->setColor(osg::Vec4(0, 0, 1.0, 1.0)); 
    4445 
    45     osg::Geode* earth = new osg::Geode; 
    46     earth->setName("earth"); 
    47     earth->addDrawable(earth_sd); 
    48  
     46    osg::Geode* earth_geode = new osg::Geode; 
     47    earth_geode->setName("EarthGeode"); 
     48    earth_geode->addDrawable(earth_sd); 
     49     
    4950    // Create the Sun, in yellow 
    5051    osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable; 
    5152    osg::Sphere* sun_sphere = new osg::Sphere; 
     53    sun_sphere->setName("SunSphere"); 
    5254    sun_sphere->setRadius(r_sun); 
    5355    sun_sd->setShape(sun_sphere); 
     
    5557 
    5658    osg::Geode* sun_geode = new osg::Geode; 
    57     sun_geode->setName("sun"); 
     59    sun_geode->setName("SunGeode"); 
    5860    sun_geode->addDrawable(sun_sd); 
    5961 
     
    6163    osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform; 
    6264    pat->setPosition(osg::Vec3d(0.0, AU, 0.0)); 
     65    pat->addChild(sun_geode); 
     66     
     67    osg::Geometry * unitCircle = new osg::Geometry(); 
     68    { 
     69      osg::Vec4Array * colours = new osg::Vec4Array(1); 
     70      (*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0); 
     71      unitCircle->setColorArray(colours); 
     72      unitCircle->setColorBinding(osg::Geometry::BIND_OVERALL); 
     73      const unsigned int n_points = 1024; 
     74      osg::Vec3Array * coords = new osg::Vec3Array(n_points); 
     75      const double dx = 2.0*M_PI/n_points; 
     76      double s,c; 
     77      for (unsigned int j=0; j<n_points; ++j) { 
     78    s = sin(dx*j); 
     79    c = cos(dx*j); 
     80    (*coords)[j].set(osg::Vec3d(c,s,0.0)); 
     81      } 
     82      unitCircle->setVertexArray(coords); 
     83      unitCircle->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 
     84      unitCircle->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,n_points)); 
     85    } 
    6386 
     87    osg::Geometry *axes = new osg::Geometry; 
     88    { 
     89      osg::Vec4Array *colours = new osg::Vec4Array(1); 
     90      (*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0); 
     91      axes->setColorArray(colours); 
     92      axes->setColorBinding(osg::Geometry::BIND_OVERALL); 
     93      osg::Vec3Array *coords = new osg::Vec3Array(6); 
     94      (*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0)); 
     95      (*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0)); 
     96      (*coords)[2].set(osg::Vec3d(0.0, 0.0, 0.0)); 
     97      (*coords)[3].set(osg::Vec3d(0.0, 0.5, 0.0)); 
     98      (*coords)[4].set(osg::Vec3d(0.0, 0.0, 0.0)); 
     99      (*coords)[5].set(osg::Vec3d(0.0, 0.0, 0.5)); 
     100      axes->setVertexArray(coords); 
     101      axes->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 
     102      axes->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); 
     103    } 
     104     
     105    // Earth orbit 
     106    osg::Geode * earthOrbitGeode = new osg::Geode; 
     107    earthOrbitGeode->addDrawable(unitCircle); 
     108    earthOrbitGeode->addDrawable(axes); 
     109    earthOrbitGeode->setName("EarthOrbitGeode"); 
     110     
     111    osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform; 
     112    earthOrbitPAT->setScale(osg::Vec3d(AU,AU,AU)); 
     113    earthOrbitPAT->setPosition(osg::Vec3d(0.0, AU, 0.0)); 
     114    earthOrbitPAT->addChild(earthOrbitGeode); 
     115    earthOrbitPAT->setName("EarthOrbitPAT"); 
     116     
    64117    osg::Group* scene = new osg::Group; 
    65     scene->addChild(earth); 
     118    scene->setName("SceneGroup"); 
     119    scene->addChild(earth_geode); 
    66120    scene->addChild(pat); 
    67     pat->addChild(sun_geode); 
    68  
     121    scene->addChild(earthOrbitPAT); 
     122     
    69123    return scene; 
    70124} 
     
    103157    if (needToSetHomePosition) 
    104158    { 
    105         viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); 
     159      viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); 
    106160    } 
    107161