From 2ce192f0aea0548d1cd7d15efe09d6f0224ae7cf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 2 Jul 2004 14:46:24 +0000 Subject: [PATCH] Change the light in LightSource from a generic osg::StateAttribute to a osg::Light. --- include/osg/LightSource | 10 +++++----- src/osg/LightSource.cpp | 14 +++++--------- src/osgPlugins/osg/LightSource.cpp | 3 ++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/osg/LightSource b/include/osg/LightSource index 0977c182d..80fd69de3 100644 --- a/include/osg/LightSource +++ b/include/osg/LightSource @@ -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(copyop(ls._light.get()))) {} + _light(dynamic_cast(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 _light; + ref_ptr _light; ReferenceFrame _referenceFrame; }; diff --git a/src/osg/LightSource.cpp b/src/osg/LightSource.cpp index 31d203e4d..3c215c9af 100644 --- a/src/osg/LightSource.cpp +++ b/src/osg/LightSource.cpp @@ -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(_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)); } } diff --git a/src/osgPlugins/osg/LightSource.cpp b/src/osgPlugins/osg/LightSource.cpp index fb7499cb8..1622fa47a 100644 --- a/src/osgPlugins/osg/LightSource.cpp +++ b/src/osgPlugins/osg/LightSource.cpp @@ -40,7 +40,8 @@ bool LightSource_readLocalData(Object& obj, Input& fr) } } - StateAttribute* light=fr.readStateAttribute(); + osg::ref_ptr sa=fr.readStateAttribute(); + osg::Light* light = dynamic_cast(sa.get()); if (light) { lightsource.setLight(light);