LightSourceNode.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6743 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 11:03:10 +0200 (Mi, 05. Aug 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS LightSourceNode
00049 //
00050 //=============================================================================
00051 
00052 #ifndef ACG_LIGHTSOURCE_NODE_HH
00053 #define ACG_LIGHTSOURCE_NODE_HH
00054 
00055 
00056 //== INCLUDES =================================================================
00057 
00058 #include "BaseNode.hh"
00059 #include "../GL/gl.hh"
00060 #include <string>
00061 #include <vector>
00062 
00063 
00064 //== NAMESPACES ===============================================================
00065 
00066 namespace ACG {
00067 namespace SceneGraph {
00068   
00069 
00070 //== CLASS DEFINITION =========================================================
00071 
00072   
00084 class ACGDLLEXPORT LightSourceNode : public BaseNode
00085 {
00086 
00088   struct LightSource
00089   {
00090     //default Constructor
00091     LightSource()
00092     {
00093       // set OpenGL defaults
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 } // namespace SceneGraph
00208 } // namespace ACG
00209 //=============================================================================
00210 #endif // ACG_LIGHTSOURCE_NODE_HH defined
00211 //=============================================================================
00212 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .