Show
Ignore:
Timestamp:
12/09/09 19:45:46 (4 years ago)
Author:
cedricpinson
Message:

From Cedric Pinson,
Add check in RigTransformSoftware? if bones are null
Indent TimelineAnimationManager?
Add check for NaN in UpdateCallback?.cpp
Fix TimelineAnimationManager? clear target (a refactore of Timeline is require for futur)
Fix Computation of bounding box for RigGeometry?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgAnimation/RigGeometry.cpp

    r10693 r10877  
    2020using namespace osgAnimation; 
    2121 
     22// The idea is to compute a bounding box with a factor x of the first step we compute the bounding box 
     23class RigComputeBoundingBoxCallback : public osg::Drawable::ComputeBoundingBoxCallback 
     24{ 
     25public: 
     26    RigComputeBoundingBoxCallback(double factor = 2.0) : _computed(false), _factor(factor) {} 
     27    void reset() { _computed = false; } 
     28    virtual osg::BoundingBox computeBound(const osg::Drawable& drawable) const 
     29    { 
     30        const osgAnimation::RigGeometry& rig = dynamic_cast<const osgAnimation::RigGeometry&>(drawable); 
     31 
     32        // if a valid inital bounding box is set we use it without asking more 
     33        if (rig.getInitialBound().valid()) 
     34            return rig.getInitialBound(); 
     35 
     36        if (_computed) 
     37            return _boundingBox; 
     38 
     39        // if the computing of bb is invalid (like no geometry inside) 
     40        // then dont tag the bounding box as computed 
     41        osg::BoundingBox bb = rig.computeBound(); 
     42        if (!bb.valid()) 
     43            return bb; 
     44 
     45 
     46        _boundingBox.expandBy(bb); 
     47        osg::Vec3 center = _boundingBox.center(); 
     48        osg::Vec3 vec = (_boundingBox._max-center)*_factor; 
     49        _boundingBox.expandBy(center + vec); 
     50        _boundingBox.expandBy(center - vec); 
     51        _computed = true; 
     52//        osg::notify(osg::NOTICE) << "build the bounding box for RigGeometry " << rig.getName() << " " << _boundingBox._min << " " << _boundingBox._max << std::endl; 
     53        return _boundingBox; 
     54    } 
     55protected: 
     56    mutable bool _computed; 
     57    double _factor; 
     58    mutable osg::BoundingBox _boundingBox; 
     59}; 
     60 
    2261RigGeometry::RigGeometry() 
    2362{ 
     
    3069 
    3170    // disable the computation of boundingbox for the rig mesh 
    32     setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 
     71    setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); 
    3372} 
    3473 
     
    4382 
    4483    // disable the computation of boundingbox for the rig mesh 
    45     setComputeBoundingBoxCallback(new ComputeBoundingBoxCallback); 
     84    setComputeBoundingBoxCallback(new RigComputeBoundingBoxCallback); 
    4685} 
    4786