Light
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* 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.
*/
#ifndef OSG_LIGHT
#define OSG_LIGHT 1
#include <osg/StateAttribute>
#include <osg/Vec3>
#include <osg/Vec4>
#ifndef GL_LIGHT0
#define GL_LIGHT0 0x4000
#define GL_LIGHT1 0x4001
#define GL_LIGHT2 0x4002
#define GL_LIGHT3 0x4003
#define GL_LIGHT4 0x4004
#define GL_LIGHT5 0x4005
#define GL_LIGHT6 0x4006
#define GL_LIGHT7 0x4007
#endif
#ifndef GL_LIGHTING
#define GL_LIGHTING 0x0B50
#endif
namespace osg {
class OSG_EXPORT Light : public StateAttribute
{
public :
Light();
Light(unsigned int lightnum);
Light(const Light& light,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(light,copyop),
_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) {}
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; }
virtual int compare(const StateAttribute& sa) const
{
// check the types are equal and then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(Light,sa)
// compare each parameter 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 macros, must be equal.
}
virtual unsigned int getMember() const { return _lightnum; }
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_LIGHT0+_lightnum);
return true;
}
void setLightNum(int num);
int getLightNum() const { return _lightnum; }
inline void setAmbient( const Vec4& ambient ) { _ambient = ambient; }
inline const Vec4& getAmbient() const { return _ambient; }
inline void setDiffuse( const Vec4& diffuse ) { _diffuse = diffuse; }
inline const Vec4& getDiffuse() const { return _diffuse; }
inline void setSpecular( const Vec4& specular ) { _specular = specular; }
inline const Vec4& getSpecular() const { return _specular; }
inline void setPosition( const Vec4& position ) { _position = position; }
inline const Vec4& getPosition() const { return _position; }
inline void setDirection( const Vec3& direction ) { _direction = direction; }
inline const Vec3& getDirection() const { return _direction; }
inline void setConstantAttenuation( float constant_attenuation ) { _constant_attenuation = constant_attenuation; }
inline float getConstantAttenuation() const { return _constant_attenuation; }
inline void setLinearAttenuation ( float linear_attenuation ) { _linear_attenuation = linear_attenuation; }
inline float getLinearAttenuation () const { return _linear_attenuation; }
inline void setQuadraticAttenuation ( float quadratic_attenuation ) { _quadratic_attenuation = quadratic_attenuation; }
inline float getQuadraticAttenuation() const { return _quadratic_attenuation; }
inline void setSpotExponent( float spot_exponent ) { _spot_exponent = spot_exponent; }
inline float getSpotExponent() const { return _spot_exponent; }
inline void setSpotCutoff( float spot_cutoff ) { _spot_cutoff = spot_cutoff; }
inline float getSpotCutoff() const { return _spot_cutoff; }
void captureLightState();
virtual void apply(State& state) const;
protected :
virtual ~Light();
void init();
int _lightnum; // OpenGL light number
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
};
}
#endif
GL_LIGHT0
#define GL_LIGHT0
Definition Light:22
StateAttribute
COMPARE_StateAttribute_Parameter
#define COMPARE_StateAttribute_Parameter(parameter)
Definition StateAttribute:69
COMPARE_StateAttribute_Types
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
Definition StateAttribute:57
Vec3
Vec4
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Light::~Light
virtual ~Light()
osg::Light::setAmbient
void setAmbient(const Vec4 &ambient)
Definition Light:109
osg::Light::getAmbient
const Vec4 & getAmbient() const
Definition Light:112
osg::Light::_position
Vec4 _position
Definition Light:188
osg::Light::getSpotExponent
float getSpotExponent() const
Definition Light:160
osg::Light::_spot_cutoff
float _spot_cutoff
Definition Light:194
osg::Light::setLinearAttenuation
void setLinearAttenuation(float linear_attenuation)
Definition Light:145
osg::Light::setSpotCutoff
void setSpotCutoff(float spot_cutoff)
Definition Light:163
osg::Light::_linear_attenuation
float _linear_attenuation
Definition Light:191
osg::Light::compare
virtual int compare(const StateAttribute &sa) const
Definition Light:70
osg::Light::cloneType
virtual osg::Object * cloneType() const
Definition Light:62
osg::Light::_direction
Vec3 _direction
Definition Light:189
osg::Light::getDiffuse
const Vec4 & getDiffuse() const
Definition Light:118
osg::Light::_quadratic_attenuation
float _quadratic_attenuation
Definition Light:192
osg::Light::getDirection
const Vec3 & getDirection() const
Definition Light:136
osg::Light::className
virtual const char * className() const
Definition Light:66
osg::Light::getSpotCutoff
float getSpotCutoff() const
Definition Light:166
osg::Light::setSpotExponent
void setSpotExponent(float spot_exponent)
Definition Light:157
osg::Light::getQuadraticAttenuation
float getQuadraticAttenuation() const
Definition Light:154
osg::Light::init
void init()
osg::Light::_constant_attenuation
float _constant_attenuation
Definition Light:190
osg::Light::setDirection
void setDirection(const Vec3 &direction)
Definition Light:133
osg::Light::_lightnum
int _lightnum
Definition Light:183
osg::Light::getConstantAttenuation
float getConstantAttenuation() const
Definition Light:142
osg::Light::getType
virtual Type getType() const
Definition Light:67
osg::Light::Light
Light(unsigned int lightnum)
osg::Light::setQuadraticAttenuation
void setQuadraticAttenuation(float quadratic_attenuation)
Definition Light:151
osg::Light::_ambient
Vec4 _ambient
Definition Light:185
osg::Light::apply
virtual void apply(State &state) const
osg::Light::getModeUsage
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition Light:94
osg::Light::getLightNum
int getLightNum() const
Definition Light:106
osg::Light::getMember
virtual unsigned int getMember() const
Definition Light:92
osg::Light::libraryName
virtual const char * libraryName() const
Definition Light:65
osg::Light::clone
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Definition Light:63
osg::Light::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Light:64
osg::Light::setLightNum
void setLightNum(int num)
osg::Light::captureLightState
void captureLightState()
osg::Light::_spot_exponent
float _spot_exponent
Definition Light:193
osg::Light::setSpecular
void setSpecular(const Vec4 &specular)
Definition Light:121
osg::Light::Light
Light()
osg::Light::getPosition
const Vec4 & getPosition() const
Definition Light:130
osg::Light::getSpecular
const Vec4 & getSpecular() const
Definition Light:124
osg::Light::getLinearAttenuation
float getLinearAttenuation() const
Definition Light:148
osg::Light::Light
Light(const Light &light, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition Light:48
osg::Light::setPosition
void setPosition(const Vec4 &position)
Definition Light:127
osg::Light::_specular
Vec4 _specular
Definition Light:187
osg::Light::setDiffuse
void setDiffuse(const Vec4 &diffuse)
Definition Light:115
osg::Light::_diffuse
Vec4 _diffuse
Definition Light:186
osg::Light::setConstantAttenuation
void setConstantAttenuation(float constant_attenuation)
Definition Light:139
osg::Object
Definition Object:61
osg::StateAttribute::StateAttribute
StateAttribute()
osg::StateAttribute::Type
Type
Definition StateAttribute:124
osg::StateAttribute::LIGHT
@ LIGHT
Definition StateAttribute:137
osg::State
Definition State:80
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Vec4
Vec4f Vec4
Definition Vec4:21
NULL
#define NULL
Definition osg/Export:55
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
osg::StateAttribute::ModeUsage
Definition StateAttribute:308
osg::StateAttribute::ModeUsage::usesMode
virtual void usesMode(GLMode mode)=0