AGXDynamics  2.35.0.3
LightSource.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXOSG_LIGHTSOURCE_H
18 #define AGXOSG_LIGHTSOURCE_H
19 
20 #include <agx/config.h>
21 #include <agx/Vec4.h>
22 #include <agxOSG/export.h>
23 
24 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
25 #include <osg/Light>
26 #include <osg/LightSource>
27 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
28 
29 
30 namespace agxOSG
31 {
33  {
34  public:
35 
36  LightSource( osg::LightSource *lightSource )
37  {
38  if (lightSource)
39  m_light = lightSource->getLight();
40  }
41 
43  int getLightNum() const { if (m_light) return m_light->getLightNum(); else return -1; }
44 
46  inline void setAmbient( const agx::Vec4f& ambient ) { if (m_light) m_light->setAmbient( AGX_VEC4_TO_OSG(ambient)); }
47 
49  inline agx::Vec4f getAmbient() const { if (m_light) return OSG_VEC4F_TO_AGX(m_light->getAmbient()); else return agx::Vec4f(); }
50 
52  inline void setDiffuse( const agx::Vec4f& diffuse ) { if (m_light) m_light->setDiffuse( AGX_VEC4_TO_OSG(diffuse)); }
53 
55  inline agx::Vec4f getDiffuse() const { if (m_light) return OSG_VEC4F_TO_AGX(m_light->getDiffuse()); else return agx::Vec4f(); }
56 
58  inline void setSpecular( const agx::Vec4f& specular ) { if (m_light) m_light->setSpecular( AGX_VEC4_TO_OSG(specular)); }
59 
61  inline agx::Vec4f getSpecular() const { if (m_light) return OSG_VEC4F_TO_AGX(m_light->getSpecular()); else return agx::Vec4f(); }
62 
64  inline void setPosition( const agx::Vec4& position ) { if (m_light) m_light->setPosition( AGX_VEC4_TO_OSG(position)); }
65 
67  inline agx::Vec4 getPosition() const { if (m_light) return OSG_VEC4_TO_AGX(m_light->getPosition()); else return agx::Vec4(); }
68 
70  inline void setDirection( const agx::Vec3& direction ) { if (m_light) m_light->setDirection(AGX_VEC3_TO_OSG(direction)); }
71 
73  inline agx::Vec3 getDirection() const { if (m_light) return OSG_VEC3_TO_AGX(m_light->getDirection()); else return agx::Vec3(); }
74 
76  inline void setConstantAttenuation( float constant_attenuation ) { if (m_light) m_light->setConstantAttenuation(constant_attenuation);}
77 
79  inline float getConstantAttenuation() const { if (m_light) return m_light->getConstantAttenuation(); else return 0; }
80 
82  inline void setLinearAttenuation ( float linear_attenuation ) { if (m_light) m_light->setLinearAttenuation( linear_attenuation ); }
83 
85  inline float getLinearAttenuation () const { if (m_light) return m_light->getLinearAttenuation(); else return 0; }
86 
88  inline void setQuadraticAttenuation ( float quadratic_attenuation ) { if (m_light) m_light->setQuadraticAttenuation(quadratic_attenuation); }
89 
91  inline float getQuadraticAttenuation() const { if (m_light) return m_light->getQuadraticAttenuation(); else return 0;}
92 
94  inline void setSpotExponent( float spot_exponent ) { if (m_light) m_light->setSpotExponent(spot_exponent); }
95 
97  inline float getSpotExponent() const { if (m_light) return m_light->getSpotExponent(); else return 0; }
98 
100  inline void setSpotCutoff( float spot_cutoff ) { if (m_light) m_light->setSpotCutoff(spot_cutoff); }
101 
103  inline float getSpotCutoff() const { if (m_light) return m_light->getSpotCutoff(); return 0; }
104 
106 
107  protected:
108  osg::ref_ptr<osg::Light> m_light;
109 
110  };
111 }
112 
113 #endif
agxOSG::LightSource::setDiffuse
void setDiffuse(const agx::Vec4f &diffuse)
Set the diffuse component of the light.
Definition: LightSource.h:52
agxOSG::LightSource::getDirection
agx::Vec3 getDirection() const
Get the direction of the light.
Definition: LightSource.h:73
agxOSG::LightSource::getSpotExponent
float getSpotExponent() const
Get the spot exponent of the light.
Definition: LightSource.h:97
agx::Vec4f
Vec4T< Real32 > Vec4f
Definition: Vec4.h:26
OSG_VEC3_TO_AGX
#define OSG_VEC3_TO_AGX(X)
OSG_VEC4F_TO_AGX
#define OSG_VEC4F_TO_AGX(X)
agxOSG::LightSource::getConstantAttenuation
float getConstantAttenuation() const
Get the constant attenuation of the light.
Definition: LightSource.h:79
agxOSG::LightSource::setSpotCutoff
void setSpotCutoff(float spot_cutoff)
Set the spot cutoff of the light.
Definition: LightSource.h:100
agx::Vec4
Vec4T< Real > Vec4
Definition: Vec4.h:25
AGX_VEC4_TO_OSG
#define AGX_VEC4_TO_OSG(X)
agx::Vec4T
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
agxOSG::LightSource::getAmbient
agx::Vec4f getAmbient() const
Get the ambient component of the light.
Definition: LightSource.h:49
agxOSG::LightSource::getQuadraticAttenuation
float getQuadraticAttenuation() const
Get the quadratic attenuation of the light.
Definition: LightSource.h:91
Vec4.h
agxOSG::LightSource::setDirection
void setDirection(const agx::Vec3 &direction)
Set the direction of the light.
Definition: LightSource.h:70
agxOSG::LightSource::getLinearAttenuation
float getLinearAttenuation() const
Get the linear attenuation of the light.
Definition: LightSource.h:85
agxOSG::LightSource::setConstantAttenuation
void setConstantAttenuation(float constant_attenuation)
Set the constant attenuation of the light.
Definition: LightSource.h:76
OSG_VEC4_TO_AGX
#define OSG_VEC4_TO_AGX(X)
agx::Vec3
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
PushDisableWarnings.h
agxOSG::LightSource::setAmbient
void setAmbient(const agx::Vec4f &ambient)
Set the ambient component of the light.
Definition: LightSource.h:46
agxOSG::LightSource::setPosition
void setPosition(const agx::Vec4 &position)
Set the position of the light.
Definition: LightSource.h:64
agxOSG::LightSource::getSpecular
agx::Vec4f getSpecular() const
Get the specular component of the light.
Definition: LightSource.h:61
AGX_VEC3_TO_OSG
#define AGX_VEC3_TO_OSG(X)
agxOSG::LightSource::setLinearAttenuation
void setLinearAttenuation(float linear_attenuation)
Set the linear attenuation of the light.
Definition: LightSource.h:82
agxOSG::LightSource::~LightSource
~LightSource()
Definition: LightSource.h:105
agxOSG::LightSource::getLightNum
int getLightNum() const
Get which OpenGL light this osg::Light operates on.
Definition: LightSource.h:43
agxOSG::LightSource::m_light
osg::ref_ptr< osg::Light > m_light
Definition: LightSource.h:108
agxOSG::LightSource::getDiffuse
agx::Vec4f getDiffuse() const
Get the diffuse component of the light.
Definition: LightSource.h:55
agxOSG::LightSource::setSpotExponent
void setSpotExponent(float spot_exponent)
Set the spot exponent of the light.
Definition: LightSource.h:94
agxOSG::LightSource::setSpecular
void setSpecular(const agx::Vec4f &specular)
Set the specular component of the light.
Definition: LightSource.h:58
agxOSG::LightSource::getSpotCutoff
float getSpotCutoff() const
Get the spot cutoff of the light.
Definition: LightSource.h:103
export.h
agx::Vec3T< Real >
agxOSG::LightSource
Definition: LightSource.h:32
agxOSG::LightSource::LightSource
LightSource(osg::LightSource *lightSource)
Definition: LightSource.h:36
agxOSG::LightSource::getPosition
agx::Vec4 getPosition() const
Get the position of the light.
Definition: LightSource.h:67
agxOSG::LightSource::setQuadraticAttenuation
void setQuadraticAttenuation(float quadratic_attenuation)
Set the quadratic attenuation of the light.
Definition: LightSource.h:88
AGXOSG_EXPORT
#define AGXOSG_EXPORT
PopDisableWarnings.h