2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/LightSource>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2002-07-21 09:29:11 +08:00
|
|
|
LightSource::LightSource():
|
2003-01-17 00:37:24 +08:00
|
|
|
_value(StateAttribute::ON),
|
2004-10-25 04:04:00 +08:00
|
|
|
_referenceFrame(RELATIVE_RF)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-04-11 05:51:34 +08:00
|
|
|
// switch off culling of light source nodes by default.
|
|
|
|
setCullingActive(false);
|
2002-12-16 21:40:58 +08:00
|
|
|
_stateset = new StateSet;
|
|
|
|
_light = new Light;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LightSource::~LightSource()
|
|
|
|
{
|
|
|
|
// ref_ptr<> automactially decrements the reference count of attached lights.
|
|
|
|
}
|
|
|
|
|
2003-01-17 00:37:24 +08:00
|
|
|
void LightSource::setReferenceFrame(ReferenceFrame rf)
|
|
|
|
{
|
|
|
|
_referenceFrame = rf;
|
2004-10-25 04:04:00 +08:00
|
|
|
setCullingActive(_referenceFrame==RELATIVE_RF);
|
2003-01-17 00:37:24 +08:00
|
|
|
}
|
2002-05-04 00:47:16 +08:00
|
|
|
|
2004-07-02 22:46:24 +08:00
|
|
|
void LightSource::setLight(Light* light)
|
2002-05-04 00:47:16 +08:00
|
|
|
{
|
|
|
|
_light = light;
|
|
|
|
setLocalStateSetModes(_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the GLModes on StateSet associated with the ClipPlanes.
|
2002-09-02 20:31:35 +08:00
|
|
|
void LightSource::setStateSetModes(StateSet& stateset,StateAttribute::GLModeValue value) const
|
2002-05-04 00:47:16 +08:00
|
|
|
{
|
|
|
|
if (_light.valid())
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
stateset.setAssociatedModes(_light.get(),value);
|
2002-05-04 00:47:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void LightSource::setLocalStateSetModes(StateAttribute::GLModeValue value)
|
2002-05-04 00:47:16 +08:00
|
|
|
{
|
2002-12-16 21:40:58 +08:00
|
|
|
if (!_stateset) _stateset = new StateSet;
|
2004-10-07 17:40:03 +08:00
|
|
|
_stateset->clear();
|
2002-09-02 20:31:35 +08:00
|
|
|
setStateSetModes(*_stateset,value);
|
2002-05-04 00:47:16 +08:00
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool LightSource::computeBound() const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-07-18 18:55:04 +08:00
|
|
|
Group::computeBound();
|
|
|
|
|
2004-10-25 04:04:00 +08:00
|
|
|
if (_light.valid() && _referenceFrame==RELATIVE_RF)
|
2002-07-18 18:55:04 +08:00
|
|
|
{
|
2004-07-02 22:46:24 +08:00
|
|
|
const Vec4& pos = _light->getPosition();
|
|
|
|
if (pos[3]!=0.0f)
|
2002-07-18 18:55:04 +08:00
|
|
|
{
|
2004-07-02 22:46:24 +08:00
|
|
|
float div = 1.0f/pos[3];
|
|
|
|
_bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div));
|
2002-07-18 18:55:04 +08:00
|
|
|
}
|
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
_bsphere_computed = true;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
return true;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|