| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osgShadow/ShadowTechnique> |
|---|
| 15 | #include <osgShadow/ShadowedScene> |
|---|
| 16 | #include <osg/Notify> |
|---|
| 17 | #include <osg/io_utils> |
|---|
| 18 | |
|---|
| 19 | using namespace osgShadow; |
|---|
| 20 | |
|---|
| 21 | ShadowTechnique::CameraCullCallback::CameraCullCallback(ShadowTechnique* st): |
|---|
| 22 | _shadowTechnique(st) |
|---|
| 23 | { |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | void ShadowTechnique::CameraCullCallback::operator()(osg::Node*, osg::NodeVisitor* nv) |
|---|
| 27 | { |
|---|
| 28 | if (_shadowTechnique->getShadowedScene()) |
|---|
| 29 | { |
|---|
| 30 | _shadowTechnique->getShadowedScene()->osg::Group::traverse(*nv); |
|---|
| 31 | } |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | ShadowTechnique::ShadowTechnique(): |
|---|
| 35 | _shadowedScene(0), |
|---|
| 36 | _dirty(true) |
|---|
| 37 | { |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | ShadowTechnique::ShadowTechnique(const ShadowTechnique& copy, const osg::CopyOp& copyop): |
|---|
| 41 | osg::Object(copy,copyop), |
|---|
| 42 | _shadowedScene(0), |
|---|
| 43 | _dirty(true) |
|---|
| 44 | { |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | ShadowTechnique::~ShadowTechnique() |
|---|
| 48 | { |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | void ShadowTechnique::init() |
|---|
| 52 | { |
|---|
| 53 | OSG_NOTICE<<className()<<"::init() not implemened yet"<<std::endl; |
|---|
| 54 | |
|---|
| 55 | _dirty = false; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void ShadowTechnique::update(osg::NodeVisitor& nv) |
|---|
| 59 | { |
|---|
| 60 | OSG_NOTICE<<className()<<"::update(osg::NodeVisitor&) not implemened yet."<<std::endl; |
|---|
| 61 | _shadowedScene->osg::Group::traverse(nv); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void ShadowTechnique::cull(osgUtil::CullVisitor& cv) |
|---|
| 65 | { |
|---|
| 66 | OSG_NOTICE<<className()<<"::cull(osgUtl::CullVisitor&) not implemened yet."<<std::endl; |
|---|
| 67 | _shadowedScene->osg::Group::traverse(cv); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void ShadowTechnique::cleanSceneGraph() |
|---|
| 71 | { |
|---|
| 72 | OSG_NOTICE<<className()<<"::cleanSceneGraph()) not implemened yet."<<std::endl; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | void ShadowTechnique::traverse(osg::NodeVisitor& nv) |
|---|
| 76 | { |
|---|
| 77 | if (!_shadowedScene) return; |
|---|
| 78 | |
|---|
| 79 | if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) |
|---|
| 80 | { |
|---|
| 81 | if (_dirty) init(); |
|---|
| 82 | |
|---|
| 83 | update(nv); |
|---|
| 84 | } |
|---|
| 85 | else if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR) |
|---|
| 86 | { |
|---|
| 87 | osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv); |
|---|
| 88 | if (cv) cull(*cv); |
|---|
| 89 | else _shadowedScene->osg::Group::traverse(nv); |
|---|
| 90 | } |
|---|
| 91 | else |
|---|
| 92 | { |
|---|
| 93 | _shadowedScene->osg::Group::traverse(nv); |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | osg::Vec3 ShadowTechnique::computeOrthogonalVector(const osg::Vec3& direction) const |
|---|
| 98 | { |
|---|
| 99 | float length = direction.length(); |
|---|
| 100 | osg::Vec3 orthogonalVector = direction ^ osg::Vec3(0.0f, 1.0f, 0.0f); |
|---|
| 101 | if (orthogonalVector.normalize()<length*0.5f) |
|---|
| 102 | { |
|---|
| 103 | orthogonalVector = direction ^ osg::Vec3(0.0f, 0.0f, 1.0f); |
|---|
| 104 | orthogonalVector.normalize(); |
|---|
| 105 | } |
|---|
| 106 | return orthogonalVector; |
|---|
| 107 | } |
|---|