Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4504 was 4469, checked in by patrick, 19 years ago

orxonox/trunk: light documented and cleaned up

File size: 4.9 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;
22
23
24//! A class that handles Lights. The LightManager operates on this.
25class Light : public PNode
26{
27 public:
28  Light(int lightNumber);
29  virtual ~Light(void);
30
31  void setPosition(Vector position);
32  void setPosition(GLfloat x, GLfloat y, GLfloat z);
33  Vector getPosition() const;
34
35  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
36  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
37  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
38  void setSpotDirection(Vector direction);
39  void setSpotCutoff(GLfloat cutoff);
40
41  /** \returns the lightNumber*/
42  int getLightNumber(void) const {return this->lightNumber;}
43 
44  virtual void draw();
45
46  void debug(void) const;
47
48  // attributes
49 private:
50  int              lightNumber;               //!< The number of this Light.
51  GLfloat          lightPosition[4];          //!< The Position of this Light.
52  GLfloat          diffuseColor[4];           //!< The Diffuse Color this Light emmits.
53  GLfloat          specularColor[4];          //!< The specular Color of this Light.
54  float            constantAttenuation;       //!< The Factor of the the Constant Attenuation.
55  float            linearAttenuation;         //!< The Factor of the the Linear Attenuation.
56  float            quadraticAttenuation;      //!< The Factor of the the Quadratic Attenuation.
57  GLfloat          spotDirection[4];          //!< The direction of the Spot Light.
58  GLfloat          spotCutoff;                //!< The cutoff Angle of the Light Source
59};
60
61
62
63//! A class that handles Lights
64/**
65   A Light is a source that emits light rays (photons)
66
67   <b>Usage:</b>\n
68   First you have to get the Light Manager up and running by using LightManager::getInstance.
69   This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n
70   Then you will create a new light using:
71   \li int addLight(void);
72   \li int addLight(int lightNumber);
73
74   now you can operate on the light as follows:
75   \li void setPosition(Vector position);
76   \li void setPosition(GLfloat x, GLfloat y, GLfloat z);
77   \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
78   \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
79   \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
80   \li void setSpotDirection(Vector direction);
81   \li void setSpotCutoff(GLfloat cutoff);
82
83   These functions are preatty selv-explaining, but you can read about them below.\n
84   If you want to fetch info, or the a Light use:
85   \li Vector getPosition(void) const;
86   \li Vector getPosition(int lightNumber) const;
87   \li Light* getLight(int LightNumber) const;
88
89   To redraw the light use
90   \li void draw();
91   
92   and to delete one just use
93   \li void deleteLight(void);
94
95   for some nice output just use:
96   \li void debug(void) const;
97
98   You can also operate on the single Lights themselves, by first retreaving them with
99   \li Light* getLight(int LightNumber);
100   \n
101   and then using the same functions on this to change settings.
102*/
103class LightManager : public BaseObject
104{
105
106 public:
107  virtual ~LightManager(void);
108  static LightManager* getInstance();
109
110  // set Attributes
111  int addLight(void);
112  int addLight(int lightNumber);
113  void editLightNumber(int lightNumber);
114  void deleteLight(void);
115  void deleteLight(int lightNumber);
116
117  void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
118
119  void draw();
120
121  //set Attributes
122  void setPosition(Vector position);
123  void setPosition(GLfloat x, GLfloat y, GLfloat z);
124  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
125  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
126  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
127  void setSpotDirection(Vector direction);
128  void setSpotCutoff(GLfloat cutoff);
129
130  // get Attributes
131  Vector getPosition(void) const;
132  Vector getPosition(int lightNumber) const;
133 
134  Light* getLight(int lightNumber) const;
135 
136  void debug(void) const;
137
138
139 private:
140  LightManager(void);
141  void initLight(int LightNumber);
142 
143
144 private:
145  static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
146  GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
147
148  Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
149  Light*                  currentLight;       //!< The current Light, we are working with.
150 
151};
152
153#endif /* _LIGHT_H */
Note: See TracBrowser for help on using the repository browser.