Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4515 was 4469, checked in by patrick, 20 years ago

orxonox/trunk: light documented and cleaned up

File size: 4.9 KB
RevLine 
[3245]1/*!
[3436]2    \file light.h
3    \brief Handles Lights.
[3329]4
[3436]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.
[3245]8*/
[1853]9
[3436]10#ifndef _LIGHT_H
11#define _LIGHT_H
[1853]12
[4338]13#include "p_node.h"
[3436]14#include "glincl.h"
[1853]15
[3598]16//! The maximum number of Lights this OpenGL-implementation supports.
[3437]17#define NUMBEROFLIGHTS GL_MAX_LIGHTS
18
[4469]19
[3436]20// FORWARD DEFINITIONS //
21class Vector;
[2036]22
[4469]23
[3598]24//! A class that handles Lights. The LightManager operates on this.
[4338]25class Light : public PNode
[3597]26{
27 public:
28  Light(int lightNumber);
[3598]29  virtual ~Light(void);
[3597]30
31  void setPosition(Vector position);
32  void setPosition(GLfloat x, GLfloat y, GLfloat z);
[4469]33  Vector getPosition() const;
34
[3597]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
[3598]41  /** \returns the lightNumber*/
[3600]42  int getLightNumber(void) const {return this->lightNumber;}
[3598]43 
[3597]44  virtual void draw();
45
[3600]46  void debug(void) const;
[3598]47
[3597]48  // attributes
[3598]49 private:
[4469]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
[3597]59};
60
[4469]61
62
[3436]63//! A class that handles Lights
[3329]64/**
[3436]65   A Light is a source that emits light rays (photons)
[3600]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.
[3329]102*/
[3597]103class LightManager : public BaseObject
[3436]104{
[3440]105
[1904]106 public:
[4469]107  virtual ~LightManager(void);
[3597]108  static LightManager* getInstance();
[1853]109
[3436]110  // set Attributes
[3437]111  int addLight(void);
112  int addLight(int lightNumber);
113  void editLightNumber(int lightNumber);
114  void deleteLight(void);
115  void deleteLight(int lightNumber);
116
[3597]117  void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
118
[3598]119  void draw();
120
[3597]121  //set Attributes
[3436]122  void setPosition(Vector position);
[3437]123  void setPosition(GLfloat x, GLfloat y, GLfloat z);
[3436]124  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
125  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
[3597]126  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
[3453]127  void setSpotDirection(Vector direction);
128  void setSpotCutoff(GLfloat cutoff);
129
[3436]130  // get Attributes
[3600]131  Vector getPosition(void) const;
132  Vector getPosition(int lightNumber) const;
[3598]133 
[3600]134  Light* getLight(int lightNumber) const;
135 
136  void debug(void) const;
[4469]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 
[1853]151};
152
[3436]153#endif /* _LIGHT_H */
Note: See TracBrowser for help on using the repository browser.