Change the light in LightSource from a generic osg::StateAttribute to
a osg::Light.
This commit is contained in:
parent
4ba3f7cad3
commit
2ce192f0ae
@ -30,7 +30,7 @@ class SG_EXPORT LightSource : public Group
|
||||
LightSource(const LightSource& ls, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Group(ls,copyop),
|
||||
_value(ls._value),
|
||||
_light(dynamic_cast<osg::StateAttribute*>(copyop(ls._light.get()))) {}
|
||||
_light(dynamic_cast<osg::Light*>(copyop(ls._light.get()))) {}
|
||||
|
||||
META_Node(osg, LightSource);
|
||||
|
||||
@ -55,13 +55,13 @@ class SG_EXPORT LightSource : public Group
|
||||
ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
|
||||
|
||||
/** Set the attached light.*/
|
||||
void setLight(StateAttribute* light);
|
||||
void setLight(Light* light);
|
||||
|
||||
/** Get the attached light.*/
|
||||
inline StateAttribute* getLight() { return _light.get(); }
|
||||
inline Light* getLight() { return _light.get(); }
|
||||
|
||||
/** Get the const attached light.*/
|
||||
inline const StateAttribute* getLight() const { return _light.get(); }
|
||||
inline const Light* getLight() const { return _light.get(); }
|
||||
|
||||
/** Set the GLModes on StateSet associated with the LightSource.*/
|
||||
void setStateSetModes(StateSet&,StateAttribute::GLModeValue) const;
|
||||
@ -76,7 +76,7 @@ class SG_EXPORT LightSource : public Group
|
||||
virtual bool computeBound() const;
|
||||
|
||||
StateAttribute::GLModeValue _value;
|
||||
ref_ptr<StateAttribute> _light;
|
||||
ref_ptr<Light> _light;
|
||||
|
||||
ReferenceFrame _referenceFrame;
|
||||
};
|
||||
|
@ -36,7 +36,7 @@ void LightSource::setReferenceFrame(ReferenceFrame rf)
|
||||
setCullingActive(_referenceFrame==RELATIVE_TO_PARENTS);
|
||||
}
|
||||
|
||||
void LightSource::setLight(StateAttribute* light)
|
||||
void LightSource::setLight(Light* light)
|
||||
{
|
||||
_light = light;
|
||||
setLocalStateSetModes(_value);
|
||||
@ -64,15 +64,11 @@ bool LightSource::computeBound() const
|
||||
|
||||
if (_light.valid() && _referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
const Light* light = dynamic_cast<const Light*>(_light.get());
|
||||
if (light)
|
||||
const Vec4& pos = _light->getPosition();
|
||||
if (pos[3]!=0.0f)
|
||||
{
|
||||
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));
|
||||
}
|
||||
float div = 1.0f/pos[3];
|
||||
_bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,8 @@ bool LightSource_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
}
|
||||
|
||||
StateAttribute* light=fr.readStateAttribute();
|
||||
osg::ref_ptr<StateAttribute> sa=fr.readStateAttribute();
|
||||
osg::Light* light = dynamic_cast<Light*>(sa.get());
|
||||
if (light)
|
||||
{
|
||||
lightsource.setLight(light);
|
||||
|
Loading…
Reference in New Issue
Block a user