Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: changed all getInstances into inline functions to save some (minor) time

File size: 5.0 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  /** \returns a Pointer to the only object of this Class */
109  inline static LightManager* getInstance(void) { if (!singletonRef) singletonRef = new LightManager();  return singletonRef; };
110
111  // set Attributes
112  int addLight(void);
113  int addLight(int lightNumber);
114  void editLightNumber(int lightNumber);
115  void deleteLight(void);
116  void deleteLight(int lightNumber);
117
118  void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
119
120  void draw();
121
122  //set Attributes
123  void setPosition(Vector position);
124  void setPosition(GLfloat x, GLfloat y, GLfloat z);
125  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
126  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
127  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
128  void setSpotDirection(Vector direction);
129  void setSpotCutoff(GLfloat cutoff);
130
131  // get Attributes
132  Vector getPosition(void) const;
133  Vector getPosition(int lightNumber) const;
134 
135  Light* getLight(int lightNumber) const;
136 
137  void debug(void) const;
138
139
140 private:
141  LightManager(void);
142  void initLight(int LightNumber);
143 
144
145 private:
146  static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
147  GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
148
149  Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
150  Light*                  currentLight;       //!< The current Light, we are working with.
151 
152};
153
154#endif /* _LIGHT_H */
Note: See TracBrowser for help on using the repository browser.