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():
|
|
|
|
_value(StateAttribute::ON)
|
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-09-02 20:31:35 +08:00
|
|
|
_stateset = osgNew StateSet;
|
2002-05-04 00:47:16 +08:00
|
|
|
_light = osgNew Light;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LightSource::~LightSource()
|
|
|
|
{
|
|
|
|
// ref_ptr<> automactially decrements the reference count of attached lights.
|
|
|
|
}
|
|
|
|
|
2002-05-04 00:47:16 +08:00
|
|
|
|
2002-06-19 16:34:19 +08:00
|
|
|
void LightSource::setLight(StateAttribute* 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-09-02 20:31:35 +08:00
|
|
|
if (!_stateset) _stateset = osgNew StateSet;
|
|
|
|
_stateset->setAllToInherit();
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (_light.valid())
|
|
|
|
{
|
|
|
|
const Light* light = dynamic_cast<const Light*>(_light.get());
|
|
|
|
if (light)
|
|
|
|
{
|
|
|
|
const Vec4& pos = light->getPosition();
|
|
|
|
if (pos[3]!=0.0f)
|
|
|
|
{
|
|
|
|
float div = 1.0f/pos[3];
|
|
|
|
_bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|