root/OpenSceneGraph/trunk/src/osg/LightSource.cpp @ 13041

Revision 13041, 2.2 kB (checked in by robert, 3 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#include <osg/LightSource>
14
15using namespace osg;
16
17LightSource::LightSource():
18    _value(StateAttribute::ON),
19    _referenceFrame(RELATIVE_RF)
20{
21    // switch off culling of light source nodes by default.
22    setCullingActive(false);
23    setStateSet(new StateSet);
24    _light = new Light;
25}
26
27
28LightSource::~LightSource()
29{
30    // ref_ptr<> automactially decrements the reference count of attached lights.
31}
32
33void LightSource::setReferenceFrame(ReferenceFrame rf)
34{
35    _referenceFrame = rf;
36}
37
38void LightSource::setLight(Light* light)
39{
40    _light = light;
41    setLocalStateSetModes(_value);
42}
43
44// Set the GLModes on StateSet associated with the ClipPlanes.
45void LightSource::setStateSetModes(StateSet& stateset,StateAttribute::GLModeValue value) const
46{
47    if (_light.valid())
48    {
49        stateset.setAssociatedModes(_light.get(),value);
50    }
51}
52
53void LightSource::setLocalStateSetModes(StateAttribute::GLModeValue value)
54{
55    if (!_stateset) setStateSet(new StateSet);
56
57    _stateset->clear();
58    setStateSetModes(*_stateset,value);
59}
60
61BoundingSphere LightSource::computeBound() const
62{
63    BoundingSphere bsphere(Group::computeBound());
64
65    if (_light.valid() && _referenceFrame==RELATIVE_RF)
66    {
67        const Vec4& pos = _light->getPosition();
68        if (pos[3]!=0.0f)
69        {
70            float div = 1.0f/pos[3];
71            bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div));
72        }
73    }
74
75    return bsphere;
76}
77
78void LightSource::setThreadSafeRefUnref(bool threadSafe)
79{
80    Group::setThreadSafeRefUnref(threadSafe);
81
82    if (_light.valid()) _light->setThreadSafeRefUnref(threadSafe);
83}
Note: See TracBrowser for help on using the browser.