LightSourceNode.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef ACG_LIGHTSOURCE_NODE_HH
00053 #define ACG_LIGHTSOURCE_NODE_HH
00054
00055
00056
00057
00058 #include "BaseNode.hh"
00059 #include "../GL/gl.hh"
00060 #include <string>
00061 #include <vector>
00062
00063
00064
00065
00066 namespace ACG {
00067 namespace SceneGraph {
00068
00069
00070
00071
00072
00084 class ACGDLLEXPORT LightSourceNode : public BaseNode
00085 {
00086
00088 struct LightSource
00089 {
00090
00091 LightSource()
00092 {
00093
00094 enabled = false;
00095 fixedPosition = false;
00096
00097 ambientColor = Vec4f(0.1,0.1,0.1,1);
00098 diffuseColor = Vec4f(1,1,1,1);
00099 specularColor = Vec4f(1,1,1,1);
00100 position = Vec4f(0,0,1,0);
00101 realPosition = Vec4f(0,0,1,0);
00102 spotDirection = Vec3f(0,0,-1);
00103 spotExponent = 0;
00104 spotCutoff = 180;
00105
00106 constantAttenuation = 1;
00107 linearAttenuation = 0;
00108 quadraticAttenuation = 0;
00109 }
00110
00111 bool enabled;
00112 bool fixedPosition;
00113 Vec4f ambientColor;
00114 Vec4f diffuseColor;
00115 Vec4f specularColor;
00116 Vec4f position;
00117 Vec4f realPosition;
00118 Vec3f spotDirection;
00119 float spotExponent;
00120 float spotCutoff;
00121 float constantAttenuation;
00122 float linearAttenuation;
00123 float quadraticAttenuation;
00124 };
00125
00126
00127 public:
00128
00130 LightSourceNode( BaseNode* _parent = 0,
00131 const std::string& _name = "<LightSourceNode>");
00132
00134 virtual ~LightSourceNode() {}
00135
00136
00137 ACG_CLASSNAME(LightSourceNode);
00138
00140 void enter(GLState& _state, unsigned int _drawmode);
00142 void leave(GLState& _state, unsigned int _drawmode);
00143
00145 void enable(GLenum _nr)
00146 { lights_[gl2index(_nr)].enabled = true; }
00147
00149 void disable(GLenum _nr)
00150 { lights_[gl2index(_nr)].enabled = false; }
00151
00153 void set_position(GLenum _nr, Vec4f _pos)
00154 { lights_[gl2index(_nr)].position = _pos; }
00155
00157 void set_position(GLenum _nr, Vec3f _pos)
00158 { set_position(_nr, Vec4f(_pos[0], _pos[1], _pos[2], 1)); }
00159
00161 void set_direction(GLenum _nr, Vec3f _pos)
00162 { set_position(_nr, Vec4f(_pos[0], _pos[1], _pos[2], 0)); }
00163
00165 void set_ambient_color( GLenum _nr, Vec4f _color)
00166 { lights_[gl2index(_nr)].ambientColor = _color; }
00167
00169 void set_diffuse_color( GLenum _nr, Vec4f _color)
00170 { lights_[gl2index(_nr)].diffuseColor = _color; }
00171
00173 void set_specular_color( GLenum _nr, Vec4f _color)
00174 { lights_[gl2index(_nr)].specularColor = _color; }
00175
00177 void fixed_position(GLenum _nr, bool _state)
00178 { lights_[gl2index(_nr)].fixedPosition = _state; }
00179
00180 private:
00181
00183 int gl2index( GLenum _nr)
00184 { return( _nr - GL_LIGHT0); }
00185
00187 GLenum index2gl( int _nr)
00188 { return( _nr + GL_LIGHT0); }
00189
00191 void set_parameters(GLenum _index, LightSource& _light);
00192
00194 void get_parameters(GLenum _index, LightSource& _light);
00195
00196 private:
00197
00199 std::vector<LightSource> lights_;
00200
00202 std::vector<LightSource> lightsSave_;
00203 };
00204
00205
00206
00207 }
00208 }
00209
00210 #endif // ACG_LIGHTSOURCE_NODE_HH defined
00211
00212