root/OpenSceneGraph/trunk/src/osgShadow/ShadowTechnique.cpp @ 13041

Revision 13041, 2.9 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgShadow/ShadowTechnique>
15#include <osgShadow/ShadowedScene>
16#include <osg/Notify>
17#include <osg/io_utils>
18
19using namespace osgShadow;
20
21ShadowTechnique::CameraCullCallback::CameraCullCallback(ShadowTechnique* st):
22    _shadowTechnique(st)
23{
24}
25
26void ShadowTechnique::CameraCullCallback::operator()(osg::Node*, osg::NodeVisitor* nv)
27{
28    if (_shadowTechnique->getShadowedScene())
29    {
30        _shadowTechnique->getShadowedScene()->osg::Group::traverse(*nv);
31    }
32}
33
34ShadowTechnique::ShadowTechnique():
35    _shadowedScene(0),
36    _dirty(true)
37{
38}
39
40ShadowTechnique::ShadowTechnique(const ShadowTechnique& copy, const osg::CopyOp& copyop):
41    osg::Object(copy,copyop),
42    _shadowedScene(0),
43    _dirty(true)
44{
45}
46
47ShadowTechnique::~ShadowTechnique()
48{
49}
50
51void ShadowTechnique::init()
52{
53    OSG_NOTICE<<className()<<"::init() not implemened yet"<<std::endl;
54
55    _dirty = false;
56}
57
58void 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
64void 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
70void ShadowTechnique::cleanSceneGraph()
71{
72    OSG_NOTICE<<className()<<"::cleanSceneGraph()) not implemened yet."<<std::endl;
73}
74
75void 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
97osg::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}
Note: See TracBrowser for help on using the browser.