Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vplight.cpp

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 // ChangeLog
00006 // Jan 10, 2005 - Bruno de Oliveira Schneider
00007 // - Fixed DoxyGen class description.
00008 // - Removed a few "std::" wich were not needed.
00009 // - Changed attributes of the SUN to make it brighter.
00010 // Oct 13, 2004 - Bruno de Oliveira Schneider
00011 // - Code typing has been cleaned. DoxyGen documentation started.
00012 // - Moved "using namespace std" from header file to implementation file.
00013 // - Removed "vp" prefix from every method name.
00014 // - Added "location" attribute. THIS MAKES THE VPDirectionalLight DECREPTED!
00015 // - Added the methods: SetLocation, GetLocation.
00016 // - Added "(const std::string&, float, float, const VPColor&, const VPPoint4D&)"
00017 //   constructor, "SUN()" and "BRIGHT_AMBIENT()".
00018 // - Added "const" modifier wherever possible.
00019 // - Added a copy constructor and "operator=" because light is not static.
00020 // - Added DrawOGL method.
00021 // - Lights are now derived from VPSceneNode.
00022 // - Removed constant symbols "ON" and "OFF".
00023 // Jun 28, 2000 - Anderson Maciel
00024 // - Classes declaration and methods addition.
00025 // Jun 08, 2000 - Luciana Porcher Nedel
00026 // - Classes declaration.
00027 // Jun 19, 2000 - Rodrigo Berggevist Martins
00028 // - Classes declaration.
00029 // - Constructors and some methods implementation.
00030 // May 30, 2000 - Isabel Harb Manssour
00031 // - Constructors and some methods implementation.
00032 // May 22, 2000 - Isabel Harb Manssour
00033 // - Classes declaration.
00034 
00035 #include "vplight.h"
00036 
00037 #ifdef VP_OGL
00038 #include <GL/gl.h>
00039 #endif
00040 
00041 using namespace std;
00042 
00043 VPLight::VPLight() {
00044     // FixMe: As with most VPAT default constructors, an unitilized object could be
00045     // created here.
00046     color.SetRGBA(255,255,255,255);
00047     intensity = 1;
00048     ambientIntensity = 1;
00049     on = true;
00050 }
00051 
00052 VPLight::VPLight (float i, float ai, VPColor c, bool o) {
00053     intensity=i;
00054     ambientIntensity=ai;
00055     color=c;
00056     on=o;
00057 }
00058 
00059 VPLight::VPLight(const string& newDescription, float newIntensity,
00060                  float newAmbientIntensity, const VPColor& newColor,
00061                  const VPPoint4D& newLocation)
00062 {
00063     description = newDescription;
00064     intensity = newIntensity;
00065     ambientIntensity = newAmbientIntensity;
00066     color = newColor;
00067     location = newLocation;
00068     on = true;
00069 }
00070 
00071 VPLight::VPLight(const VPLight& light) {
00072     description = light.description;
00073     intensity = light.intensity;
00074     ambientIntensity = light.ambientIntensity;
00075     color = light.color;
00076     location = light.location;
00077     on = light.on;
00078 }
00079 
00080 VPLight::~VPLight() {
00081 }
00082 
00083 VPLight& VPLight::operator=(const VPLight& light) {
00084     description = light.description;
00085     intensity = light.intensity;
00086     ambientIntensity = light.ambientIntensity;
00087     color = light.color;
00088     location = light.location;
00089     on = light.on;
00090     return (*this);
00091 }
00092 
00093 const VPLight& VPLight::SUN() {
00094     static const VPLight sun("TheSun", 0.7, 0.7, VPColor::WHITE(), VPPoint4D(0,-1,0,0));
00095     return sun;
00096 }
00097 const VPLight& VPLight::BRIGHT_AMBIENT() {
00098     static const VPLight ba("BrightAmbient", 0.3, 0.7, VPColor::WHITE(), VPPoint4D::ORIGIN());
00099     return ba;
00100 }
00101 
00102 void VPLight::SetIntensity(float i) {
00103     intensity = i;
00104 }
00105 
00106 float VPLight::GetIntensity() const {
00107     return(intensity);
00108 }
00109 
00110 void VPLight::SetAmbientIntensity(float ai){
00111     ambientIntensity = ai;
00112 }
00113 
00114 float VPLight::GetAmbientIntensity() const {
00115     return(ambientIntensity);
00116 }
00117 
00118 void VPLight::SetColor(const VPColor& c){
00119     color = c;
00120 }
00121 
00122 VPColor VPLight::GetColor() const {
00123     return(color);
00124 }
00125 
00126 void VPLight::Turn(bool on_off){
00127     on=on_off;
00128 }
00129 
00130 bool VPLight::IsOn() const {
00131     return on;
00132 }
00133 
00134 void VPLight::SetLocation(const VPPoint4D& newLocation){
00135     location = newLocation;
00136 }
00137 
00138 bool VPLight::DrawOGL(unsigned int oglLightID) const {
00139 // The ID is needed because OpenGL calls require it.
00140 #ifdef VP_OGL
00141     if (on) { // Is light enabled?
00142         float weightedColor[4];
00143         GLenum realID;
00144 
00145         switch (oglLightID) {
00146             case 0:
00147                 realID = GL_LIGHT0;
00148                 break;
00149             case 1:
00150                 realID = GL_LIGHT1;
00151                 break;
00152             case 2:
00153                 realID = GL_LIGHT2;
00154                 break;
00155             case 3:
00156                 realID = GL_LIGHT3;
00157                 break;
00158             case 4:
00159                 realID = GL_LIGHT4;
00160                 break;
00161             case 5:
00162                 realID = GL_LIGHT5;
00163                 break;
00164             case 6:
00165                 realID = GL_LIGHT6;
00166                 break;
00167             default:
00168                 realID = GL_LIGHT7;
00169                 break;
00170         }
00171         glEnable(realID);
00172         color.GetScaled(ambientIntensity, weightedColor);
00173         glLightfv(realID, GL_AMBIENT, weightedColor);
00174         color.GetScaled(intensity, weightedColor);
00175         glLightfv(realID, GL_DIFFUSE, weightedColor);
00176     }
00177     // FixMe: if light is turned off, it seems that glDisable should be called.
00178     return true;
00179 #else
00180     return false;
00181 #endif
00182 }

Generated on Tue Sep 6 10:00:04 2005 for VPAT by  doxygen 1.4.4