1 // Copyright (C) 2018  Fernando García Liñán <fernandogarcialinan@gmail.com>
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU Library General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
16 
17 #ifndef SG_LIGHT_HXX
18 #define SG_LIGHT_HXX
19 
20 #include <osgDB/ReaderWriter>
21 #include <osg/Group>
22 
23 #include <simgear/props/props.hxx>
24 
25 class SGLight : public osg::Node {
26 public:
27     enum Type {
28         POINT,
29         SPOT
30     };
31 
32     SGLight();
33 
SGLight(const SGLight & l,const osg::CopyOp & copyop=osg::CopyOp::SHALLOW_COPY)34     SGLight(const SGLight& l,
35             const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) :
36         osg::Node(l, copyop),
37         _type(l._type),
38         _range(l._range),
39         _ambient(l._ambient),
40         _diffuse(l._diffuse),
41         _specular(l._specular),
42         _constant_attenuation(l._constant_attenuation),
43         _linear_attenuation(l._linear_attenuation),
44         _quadratic_attenuation(l._quadratic_attenuation),
45         _spot_exponent(l._spot_exponent),
46         _spot_cutoff(l._spot_cutoff)
47         {}
48 
49     META_Node(simgear, SGLight);
50 
51     static osg::Node *appendLight(const SGPropertyNode *configNode,
52                                   SGPropertyNode *modelRoot,
53                                   const osgDB::Options *options);
54 
setType(Type type)55     void setType(Type type) { _type = type; }
getType() const56     Type getType() const { return _type; }
57 
setRange(float range)58     void setRange(float range) { _range = range; }
getRange() const59     float getRange() const { return _range; }
60 
setAmbient(const osg::Vec4 & ambient)61     void setAmbient(const osg::Vec4 &ambient) { _ambient = ambient; }
getAmbient() const62     const osg::Vec4 &getAmbient() const { return _ambient; }
63 
setDiffuse(const osg::Vec4 & diffuse)64     void setDiffuse(const osg::Vec4 &diffuse) { _diffuse = diffuse; }
getDiffuse() const65     const osg::Vec4 &getDiffuse() const { return _diffuse; }
66 
setSpecular(const osg::Vec4 & specular)67     void setSpecular(const osg::Vec4 &specular) { _specular = specular; }
getSpecular() const68     const osg::Vec4 &getSpecular() const { return _specular; }
69 
setConstantAttenuation(float constant_attenuation)70     void setConstantAttenuation(float constant_attenuation) { _constant_attenuation = constant_attenuation; }
getConstantAttenuation() const71     float getConstantAttenuation() const { return _constant_attenuation; }
72 
setLinearAttenuation(float linear_attenuation)73     void setLinearAttenuation(float linear_attenuation) { _linear_attenuation = linear_attenuation; }
getLinearAttenuation() const74     float getLinearAttenuation() const { return _linear_attenuation; }
75 
setQuadraticAttenuation(float quadratic_attenuation)76     void setQuadraticAttenuation(float quadratic_attenuation) { _quadratic_attenuation = quadratic_attenuation; }
getQuadraticAttenuation() const77     float getQuadraticAttenuation() const { return _quadratic_attenuation; }
78 
setSpotExponent(float spot_exponent)79     void setSpotExponent(float spot_exponent) { _spot_exponent = spot_exponent; }
getSpotExponent() const80     float getSpotExponent() const { return _spot_exponent; }
81 
setSpotCutoff(float spot_cutoff)82     void setSpotCutoff(float spot_cutoff) { _spot_cutoff = spot_cutoff; }
getSpotCutoff() const83     float getSpotCutoff() const { return _spot_cutoff; }
84 
85 protected:
86     virtual ~SGLight();
87 
88     Type _type;
89 
90     float _range;
91 
92     osg::Vec4 _ambient;
93     osg::Vec4 _diffuse;
94     osg::Vec4 _specular;
95 
96     float _constant_attenuation;
97     float _linear_attenuation;
98     float _quadratic_attenuation;
99     float _spot_exponent;
100     float _spot_cutoff;
101 };
102 
103 typedef std::vector<osg::ref_ptr<SGLight>> SGLightList;
104 
105 #endif /* SG_LIGHT_HXX */
106