Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: light loadable

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