Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3915 was 3603, checked in by bensch, 20 years ago

orxonox/trunk: attenuation works, and the Light is now in lib/graphics

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