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/Vec3>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <osg/Vec4>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/StateAttribute>
|
|
|
|
#include <osg/StateSet>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** Light state class which encapsulates OpenGL glLight() functionality.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
class SG_EXPORT Light : public StateAttribute
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
Light();
|
|
|
|
|
|
|
|
/** return a shallow copy of a node, with Object* return type.*/
|
|
|
|
virtual Object* clone() const { return new Light(); }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** return true if this and obj are of the same kind of object.*/
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Light*>(obj)!=NULL; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** return the name of the node's class type.*/
|
|
|
|
virtual const char* className() const { return "Light"; }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const Type getType() const { return LIGHTING; }
|
|
|
|
|
|
|
|
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
|
|
|
{
|
|
|
|
ds.setMode((GLMode)(GL_LIGHT0+_lightnum),value);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn the light on.
|
|
|
|
* Calling this method doesn't directly affect OpenGL's lighting mode.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void on() { _on = true; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn the light off.
|
|
|
|
* Calling this method doesn't directly affect OpenGL's lighting mode.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void off() { _on = false; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Apply the light's state to the OpenGL state machine. */
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual void apply(State& state) const;
|
2001-01-11 00:32:10 +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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
/** Set the constant attenuation of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setConstantAttenuation( const float constant_attenuation ) { _constant_attenuation = constant_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Get the constant attenuation of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const float getConstantAttenuation() const { return _constant_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Set the linear attenuation of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setLinearAttenuation ( const float linear_attenuation ) { _linear_attenuation = linear_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Get the linear attenuation of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const float getLinearAttenuation () const { return _linear_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Set the quadratic attenuation of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setQuadraticAttenuation ( const float quadratic_attenuation ) { _quadratic_attenuation = quadratic_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Get the quadratic attenuation of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const float getQuadraticAttenuation() const { return _quadratic_attenuation; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Set the spot exponent of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setSpotExponent( const float spot_exponent ) { _spot_exponent = spot_exponent; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Get the spot exponent of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const float getSpotExponent() const { return _spot_exponent; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Set the spot cutoff of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setSpotCutoff( const float spot_cutoff ) { _spot_cutoff = spot_cutoff; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** Get the spot cutoff of the light. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const float getSpotCutoff() const { return _spot_cutoff; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Capture the lighting settings of the current OpenGL state
|
|
|
|
* and store them in this object.
|
|
|
|
*/
|
|
|
|
void captureLightState();
|
|
|
|
|
|
|
|
protected :
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual ~Light();
|
2001-01-11 00:32:10 +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
|
|
|
|
bool _on; // on/off state
|
|
|
|
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
|
|
|
|
|
|
|
|
static int _currentLightNum; // current max. OpenGL light number
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|