Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/graphics/light.h @ 4736

Last change on this file since 4736 was 4736, checked in by bensch, 19 years ago

orxonox/trunk: cleaned up LightManager, this was quite messy….

File size: 4.2 KB
Line 
1/*!
2    \file light.h
3    \brief Handles Lights.
4
5    A Light is one of the more important things in a 3D-environment,
6    without it one sees nothing :)
7    It is here for diffuse-, specular- and Bump-Mappings.
8*/
9
10#ifndef _LIGHT_H
11#define _LIGHT_H
12
13#include "p_node.h"
14#include "glincl.h"
15
16//! The maximum number of Lights this OpenGL-implementation supports.
17#define NUMBEROFLIGHTS GL_MAX_LIGHTS
18
19
20// FORWARD DEFINITIONS //
21class Vector;
22class TiXmlElement;
23
24//! A class that handles Lights. The LightManager operates on this.
25class Light : public PNode
26{
27 public:
28  Light(const TiXmlElement* root = NULL);
29  virtual ~Light(void);
30
31  void init();
32  void loadParams(const TiXmlElement* root);
33
34  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
35  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
36  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
37  void setSpotDirection(const Vector& direction);
38  void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); };
39  void setSpotCutoff(GLfloat cutoff);
40
41  /** \returns the lightNumber*/
42  int getLightNumber(void) const {return this->lightNumber;}
43
44  virtual void draw() const;
45
46  void debug(void) const;
47
48  // attributes
49 private:
50  int              lightNumber;               //!< The number of this Light.
51  GLfloat          diffuseColor[4];           //!< The Diffuse Color this Light emmits.
52  GLfloat          specularColor[4];          //!< The specular Color of this Light.
53  float            constantAttenuation;       //!< The Factor of the the Constant Attenuation.
54  float            linearAttenuation;         //!< The Factor of the the Linear Attenuation.
55  float            quadraticAttenuation;      //!< The Factor of the the Quadratic Attenuation.
56  GLfloat          spotDirection[4];          //!< The direction of the Spot Light.
57  GLfloat          spotCutoff;                //!< The cutoff Angle of the Light Source
58};
59
60
61
62//! A class that handles Lights
63/**
64   A Light is a source that emits light rays (photons)
65
66   <b>Usage:</b>\n
67   First you have to get the Light Manager up and running by using LightManager::getInstance().
68   This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n
69   Then you will create a new light using:
70   \li new Light();
71
72   now you can operate on the light as follows:
73   \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
74   \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
75   \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
76   \li void setSpotDirection(Vector direction);
77   \li void setSpotCutoff(GLfloat cutoff);
78   \li all PNode stuff also works
79
80   To redraw the light use
81   \li void draw() const;
82
83   and to delete one just use
84   \li void deleteLight(void);
85
86   for some nice output just use:
87   \li void debug(void) const;
88
89   You can also operate on the single Lights themselves, by first retreaving them with
90   \li Light* getLight(int LightNumber) const;
91   \n
92   and then using the same functions on this to change settings.
93*/
94class LightManager : public BaseObject
95{
96  friend class Light;
97
98 public:
99  virtual ~LightManager(void);
100  /** \returns a Pointer to the only object of this Class */
101  inline static LightManager* getInstance(void) { if (!singletonRef) singletonRef = new LightManager();  return singletonRef; };
102
103  void loadParams(const TiXmlElement* root);
104  void loadLights(const TiXmlElement* root);
105
106  void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
107
108  Light* getLight(int lightNumber) const;
109  inline Light* getLight() const { return this->currentLight; };
110
111  void draw() const;
112
113  void debug(void) const;
114
115 private:
116  LightManager(void);
117
118  int  registerLight(Light* light);
119  void unregisterLight(Light* light);
120
121 private:
122  static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
123  GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
124
125  Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
126  Light*                  currentLight;       //!< The current Light, we are working with.
127
128};
129
130#endif /* _LIGHT_H */
Note: See TracBrowser for help on using the repository browser.