Show
Ignore:
Timestamp:
11/24/06 18:20:01 (8 years ago)
Author:
robert
Message:

Improved handling of bounding polytope

Files:
1 modified

Legend:

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

    r5749 r5750  
    2323     
    2424    osg::BoundingBox& getBoundingBox() { return _bb; } 
     25 
     26    void getPolytope(osg::Polytope& polytope, float margin=0.1) const 
     27    { 
     28        float delta = _bb.radius()*margin; 
     29        polytope.add( osg::Plane(0.0, 0.0, 1.0, -(_bb.zMin()-delta)) ); 
     30        polytope.add( osg::Plane(0.0, 0.0, -1.0, (_bb.zMax()+delta)) ); 
     31 
     32        polytope.add( osg::Plane(1.0, 0.0, 0.0, -(_bb.xMin()-delta)) ); 
     33        polytope.add( osg::Plane(-1.0, 0.0, 0.0, (_bb.xMax()+delta)) ); 
     34 
     35        polytope.add( osg::Plane(0.0, 1.0, 0.0, -(_bb.yMin()-delta)) ); 
     36        polytope.add( osg::Plane(0.0, -1.0, 0.0, (_bb.yMax()+delta)) ); 
     37    } 
    2538         
    2639    void apply(osg::Node& node) 
     
    138151    } 
    139152     
     153     
     154    osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
     155 
     156    osg::ref_ptr<osgShadow::OccluderGeometry> occluder = new osgShadow::OccluderGeometry; 
     157    occluder->computeOccluderGeometry(model.get()); 
     158 
    140159    ComputeBoundingBoxVisitor cbbv; 
    141160    model->accept(cbbv); 
    142     const osg::BoundingBox& bb = cbbv.getBoundingBox(); 
    143     osg::Plane basePlane(0.0, 0.0, 1.0, -bb.zMin() ); 
    144      
    145     osg::ref_ptr<osg::Geode> geode = new osg::Geode; 
    146  
    147     osg::ref_ptr<osgShadow::OccluderGeometry> occluder = new osgShadow::OccluderGeometry; 
    148     occluder->computeOccluderGeometry(model.get()); 
    149     occluder->getBoundingPolytope().add(basePlane); 
     161    cbbv.getPolytope(occluder->getBoundingPolytope(),0.001); 
     162    osg::BoundingBox bb = cbbv.getBoundingBox(); 
     163 
    150164    //geode->addDrawable(occluder.get()); 
    151165     
    152166    osg::ref_ptr<osgShadow::ShadowVolumeGeometry> shadowVolume = new osgShadow::ShadowVolumeGeometry; 
    153167 
    154 #if 0 
    155     occluder->comptueShadowVolumeGeometry(osg::Vec4(bb.xMin(), bb.yMin(), bb.zMax() + bb.radius() ,1.0f), *shadowVolume); 
     168#if 1 
     169//    occluder->comptueShadowVolumeGeometry(osg::Vec4(bb.xMin()+ bb.radius(), bb.yMin()+ bb.radius(), bb.zMax() + bb.radius()  ,1.0f), *shadowVolume); 
     170    occluder->comptueShadowVolumeGeometry(osg::Vec4(bb.center().x(), bb.center().y(), bb.zMax() + bb.radius()  ,1.0f), *shadowVolume); 
    156171#else 
    157     occluder->comptueShadowVolumeGeometry(osg::Vec4(0.5f,-.5f,-1.0f,0.0f), *shadowVolume); 
     172    occluder->comptueShadowVolumeGeometry(osg::Vec4(0.5f,.25f,0.2f,0.0f), *shadowVolume); 
    158173#endif 
    159174    geode->addDrawable(shadowVolume.get());