2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_LIGHT
|
|
|
|
#define OSG_LIGHT 1
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/StateAttribute>
|
2002-04-12 01:15:07 +08:00
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Light state class which encapsulates OpenGL glLight() functionality. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Light : public StateAttribute
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
Light();
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2007-12-08 21:29:31 +08:00
|
|
|
Light(unsigned int lightnum);
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-01-29 22:04:06 +08:00
|
|
|
Light(const Light& light,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
StateAttribute(light,copyop),
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
_lightnum(light._lightnum),
|
|
|
|
_ambient(light._ambient),
|
|
|
|
_diffuse(light._diffuse),
|
|
|
|
_specular(light._specular),
|
|
|
|
_position(light._position),
|
|
|
|
_direction(light._direction),
|
|
|
|
_constant_attenuation(light._constant_attenuation),
|
|
|
|
_linear_attenuation(light._linear_attenuation),
|
|
|
|
_quadratic_attenuation(light._quadratic_attenuation),
|
|
|
|
_spot_exponent(light._spot_exponent),
|
|
|
|
_spot_cutoff(light._spot_cutoff) {}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2007-12-08 21:29:31 +08:00
|
|
|
virtual osg::Object* cloneType() const { return new Light(_lightnum); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Light(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Light *>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "Light"; }
|
|
|
|
virtual Type getType() const { return LIGHT; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
2001-09-22 10:42:08 +08:00
|
|
|
virtual int compare(const StateAttribute& sa) const
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2001-09-22 10:42:08 +08:00
|
|
|
// check the types are equal and then create the rhs variable
|
|
|
|
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
|
|
|
COMPARE_StateAttribute_Types(Light,sa)
|
|
|
|
|
|
|
|
// compare each paramter in turn against the rhs.
|
|
|
|
COMPARE_StateAttribute_Parameter(_lightnum)
|
|
|
|
COMPARE_StateAttribute_Parameter(_ambient)
|
|
|
|
COMPARE_StateAttribute_Parameter(_diffuse)
|
|
|
|
COMPARE_StateAttribute_Parameter(_specular)
|
|
|
|
COMPARE_StateAttribute_Parameter(_position)
|
|
|
|
COMPARE_StateAttribute_Parameter(_direction)
|
|
|
|
COMPARE_StateAttribute_Parameter(_constant_attenuation)
|
|
|
|
COMPARE_StateAttribute_Parameter(_linear_attenuation)
|
|
|
|
COMPARE_StateAttribute_Parameter(_quadratic_attenuation)
|
|
|
|
COMPARE_StateAttribute_Parameter(_spot_exponent)
|
|
|
|
COMPARE_StateAttribute_Parameter(_spot_cutoff)
|
|
|
|
|
|
|
|
return 0; // passed all the above comparison macro's, must be equal.
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-03-07 22:38:43 +08:00
|
|
|
virtual unsigned int getMember() const { return _lightnum; }
|
2004-10-13 19:15:50 +08:00
|
|
|
|
2007-03-06 01:34:36 +08:00
|
|
|
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
|
2001-12-25 05:34:40 +08:00
|
|
|
{
|
2004-03-03 23:38:22 +08:00
|
|
|
usage.usesMode(GL_LIGHT0+_lightnum);
|
|
|
|
return true;
|
2001-12-25 05:34:40 +08:00
|
|
|
}
|
2004-10-13 19:15:50 +08:00
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set which OpenGL light to operate on. */
|
2007-12-08 21:29:31 +08:00
|
|
|
void setLightNum(int num);
|
2001-12-25 05:34:40 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get which OpenGL light this osg::Light operates on. */
|
2002-09-02 20:31:35 +08:00
|
|
|
int getLightNum() const { return _lightnum; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the ambient component of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setAmbient( const Vec4& ambient ) { _ambient = ambient; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the ambient component of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Vec4& getAmbient() const { return _ambient; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the diffuse component of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setDiffuse( const Vec4& diffuse ) { _diffuse = diffuse; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the diffuse component of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Vec4& getDiffuse() const { return _diffuse; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the specular component of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setSpecular( const Vec4& specular ) { _specular = specular; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the specular component of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Vec4& getSpecular() const { return _specular; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
/** Set the position of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setPosition( const Vec4& position ) { _position = position; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
/** Get the position of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Vec4& getPosition() const { return _position; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
/** Set the direction of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setDirection( const Vec3& direction ) { _direction = direction; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
/** Get the direction of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Vec3& getDirection() const { return _direction; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the constant attenuation of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setConstantAttenuation( float constant_attenuation ) { _constant_attenuation = constant_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the constant attenuation of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline float getConstantAttenuation() const { return _constant_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the linear attenuation of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setLinearAttenuation ( float linear_attenuation ) { _linear_attenuation = linear_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the linear attenuation of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline float getLinearAttenuation () const { return _linear_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the quadratic attenuation of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setQuadraticAttenuation ( float quadratic_attenuation ) { _quadratic_attenuation = quadratic_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the quadratic attenuation of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline float getQuadraticAttenuation() const { return _quadratic_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the spot exponent of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setSpotExponent( float spot_exponent ) { _spot_exponent = spot_exponent; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the spot exponent of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline float getSpotExponent() const { return _spot_exponent; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set the spot cutoff of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline void setSpotCutoff( float spot_cutoff ) { _spot_cutoff = spot_cutoff; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the spot cutoff of the light. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline float getSpotCutoff() const { return _spot_cutoff; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Capture the lighting settings of the current OpenGL state
|
|
|
|
* and store them in this object.
|
|
|
|
*/
|
2001-01-11 00:32:10 +08:00
|
|
|
void captureLightState();
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Apply the light's state to the OpenGL state machine. */
|
2001-12-25 05:34:40 +08:00
|
|
|
virtual void apply(State& state) const;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected :
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual ~Light();
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Initialize the light's settings with some decent defaults. */
|
2001-09-20 05:08:56 +08:00
|
|
|
void init();
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
int _lightnum; // OpenGL light number
|
2001-12-25 05:34:40 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
Vec4 _ambient; // r, g, b, w
|
|
|
|
Vec4 _diffuse; // r, g, b, w
|
|
|
|
Vec4 _specular; // r, g, b, w
|
|
|
|
Vec4 _position; // x, y, z, w
|
|
|
|
Vec3 _direction; // x, y, z
|
|
|
|
float _constant_attenuation; // constant
|
|
|
|
float _linear_attenuation; // linear
|
|
|
|
float _quadratic_attenuation; // quadratic
|
|
|
|
float _spot_exponent; // exponent
|
|
|
|
float _spot_cutoff; // spread
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|