Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6390 was 5405, checked in by bensch, 19 years ago

orxonox/trunk: renamed definition to the right term declaration…

File size: 4.2 KB
RevLine 
[4734]1/*!
[5039]2 * @file light.h
[4836]3  *  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
[5405]20// FORWARD DECLARATIONS //
[3436]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:
[4736]28  Light(const TiXmlElement* root = NULL);
[4746]29  virtual ~Light();
[3597]30
[4734]31  void loadParams(const TiXmlElement* root);
32
[3597]33  void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
34  void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
35  void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
[4734]36  void setSpotDirection(const Vector& direction);
37  void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); };
[3597]38  void setSpotCutoff(GLfloat cutoff);
39
[4836]40  /** @returns the lightNumber*/
[4746]41  int getLightNumber() const {return this->lightNumber;}
[4734]42
[4736]43  virtual void draw() const;
[3597]44
[4746]45  void debug() const;
[3598]46
[3597]47  // attributes
[3598]48 private:
[4469]49  int              lightNumber;               //!< The number of this Light.
50  GLfloat          diffuseColor[4];           //!< The Diffuse Color this Light emmits.
51  GLfloat          specularColor[4];          //!< The specular Color of this Light.
52  float            constantAttenuation;       //!< The Factor of the the Constant Attenuation.
53  float            linearAttenuation;         //!< The Factor of the the Linear Attenuation.
54  float            quadraticAttenuation;      //!< The Factor of the the Quadratic Attenuation.
55  GLfloat          spotDirection[4];          //!< The direction of the Spot Light.
56  GLfloat          spotCutoff;                //!< The cutoff Angle of the Light Source
[3597]57};
58
[4469]59
60
[3436]61//! A class that handles Lights
[3329]62/**
[3436]63   A Light is a source that emits light rays (photons)
[3600]64
65   <b>Usage:</b>\n
[4736]66   First you have to get the Light Manager up and running by using LightManager::getInstance().
[3600]67   This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n
68   Then you will create a new light using:
[4736]69   \li new Light();
[3600]70
[4738]71   if you want to operate on this Light just apply the following functions onto it.
72       (You can also optain the Light-pointer with LightManager::getInstance()->getLight(lightNumber))
73
[3600]74   now you can operate on the light as follows:
75   \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
76   \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
77   \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
78   \li void setSpotDirection(Vector direction);
79   \li void setSpotCutoff(GLfloat cutoff);
[4736]80   \li all PNode stuff also works
[3600]81
82   To redraw the light use
[4738]83   \li void draw() const; (this is automatically done by the LightManager)
[4734]84
[3600]85   for some nice output just use:
[4746]86   \li void debug() const; (either on LightManager for a resume or on any Light for single information.)
[3329]87*/
[3597]88class LightManager : public BaseObject
[3436]89{
[4736]90  friend class Light;
[3440]91
[1904]92 public:
[4746]93  virtual ~LightManager();
[4836]94  /** @returns a Pointer to the only object of this Class */
[4746]95  inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager();  return singletonRef; };
[1853]96
[4734]97  void loadParams(const TiXmlElement* root);
[4735]98  void loadLights(const TiXmlElement* root);
[4734]99
[3597]100  void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
101
[4736]102  Light* getLight(int lightNumber) const;
103  inline Light* getLight() const { return this->currentLight; };
[3598]104
[4736]105  void draw() const;
[3453]106
[4746]107  void debug() const;
[4469]108
109 private:
[4746]110  LightManager();
[4469]111
[4736]112  int  registerLight(Light* light);
113  void unregisterLight(Light* light);
[4734]114
[4469]115 private:
116  static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
117  GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
118
119  Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
120  Light*                  currentLight;       //!< The current Light, we are working with.
[4734]121
[1853]122};
123
[3436]124#endif /* _LIGHT_H */
Note: See TracBrowser for help on using the repository browser.