Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

WP_Light.h

Go to the documentation of this file.
00001 /* Copyright (C) 2001 W.P. van Paassen - peter@paassen.tmfweb.nl
00002 
00003    This program is free software; you can redistribute it and/or modify it under
00004    the terms of the GNU General Public License as published by the Free
00005    Software Foundation; either version 2 of the License, or (at your
00006    option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful, but WITHOUT
00009    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00010    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00011    for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; see the file COPYING.  If not, write to the Free
00015    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
00016 
00017 #ifndef WP_LIGHT_H
00018 #define WP_LIGHT_H
00019 
00020 #include "WP_Def.h"
00021 #include "WP_Color.h"
00022 
00023 namespace WPCG
00024 {
00025 //forward declarations
00026 class WP_Point3D;
00027 class WP_Vector3D;
00028 
00048 class WP_Light
00049 { 
00050  public:
00054   enum WP_Light_Pos_Kind {point, vector};
00055 
00056   WP_Light():number(0)
00057     {
00058       k = point;
00059       p = new WP_Point3D(0.0, 0.0, 0.0);
00060     }
00061 
00062   WP_Light(unsigned char _number, const WP_Point3D& position, const WP_Color& ambient, const WP_Color& diffuse, const WP_Color& specular, const WP_Color& emissive, bool remote = true):ambient_color(ambient), diffuse_color(diffuse), specular_color(specular), emissive_color(emissive),number(_number)
00063     {
00064       if (remote)
00065         {
00066           k = vector;
00067           v = new WP_Vector3D(position.data[0], position.data[1], position.data[2]);
00068         }
00069       else
00070         {
00071           k = point;
00072           p = new WP_Point3D(position);
00073         }
00074     }
00075 
00076   //COPY CONSTRUCTOR
00077   WP_Light(const WP_Light &light)
00078     {
00079       k = light.k;
00080 
00081       if (k == point)
00082         p = light.p;
00083       else
00084         v = light.v;
00085 
00086       ambient_color = light.ambient_color;
00087       diffuse_color = light.diffuse_color;
00088       specular_color = light.specular_color;
00089       emissive_color = light.emissive_color;
00090     }
00091   
00092   ~WP_Light()
00093     {
00094       if (k == point)
00095         {
00096           delete p;
00097         }
00098       else
00099         {
00100           delete v;
00101         }
00102     }
00103 
00107   WP_Light& operator=(const WP_Light& light)
00108     {
00109       if (this == &light)
00110         return *this;
00111 
00112       k = light.k;
00113       if (k == point)
00114         {
00115           delete p;
00116           p = light.p;
00117         }
00118       else
00119         {
00120           delete v;
00121           v = light.v;
00122         }
00123       ambient_color = light.ambient_color;
00124       diffuse_color = light.diffuse_color;
00125       specular_color = light.specular_color;
00126       emissive_color = light.emissive_color;
00127       return *this;
00128     }
00129   
00134   WP_Light_Pos_Kind getKind() const
00135     {
00136       return k;
00137     }
00138 
00143   WP_Point3D* getPointPosition() const 
00144     {
00145       if (k == point)
00146         {
00147           return p;
00148         }
00149       return 0;
00150     }
00151 
00156   WP_Vector3D* getVectorPosition() const
00157     {
00158       if (k == vector)
00159         {
00160           return v;
00161         }
00162       return 0;
00163     }
00164 
00168   void drawOpenGL()
00169     {
00170       glPushMatrix();
00171       if (k == vector)
00172         {
00173           glLightfv(GL_LIGHT0 + number, GL_POSITION, v->data);
00174           /*      glBegin(GL_POLYGON);
00175             glVertex3f(v->data[0], v->data[1], v->data[2]);
00176             glVertex3f(v->data[0] + 1.0, v->data[1] + 1.0, v->data[2]);
00177             glVertex3f(v->data[0] + 1.0, v->data[1], v->data[2]);
00178             glEnd();*/
00179         }
00180       else
00181         {
00182           glLightfv(GL_LIGHT0 + number, GL_POSITION, p->data);
00183           
00184           /*glBegin(GL_POLYGON);
00185             glVertex3f(p->data[0], p->data[1], p->data[2]);
00186             glVertex3f(p->data[0] + 1.0, p->data[1] + 1.0, p->data[2]);
00187             glVertex3f(p->data[0] + 1.0, p->data[1], p->data[2]);
00188             glEnd();*/
00189         }
00190       glPopMatrix();
00191     } 
00192 
00200   void setPosition(float x, float y, float z, float h)
00201     {
00202       if (h == 1.0)
00203         {
00204           if (k == vector)
00205             {
00206               delete v;
00207             }
00208           else
00209             {
00210               delete p;
00211             }
00212 
00213           k = point;
00214           p = new WP_Point3D(x, y, z);
00215         }
00216       else
00217         {
00218           if (k == vector)
00219             {
00220               delete v;
00221             }
00222           else 
00223             {
00224               delete p;
00225             }
00226 
00227           k = vector;
00228           v = new WP_Vector3D(x, y, z);
00229         }
00230     }
00231 
00235   WP_Color ambient_color;
00236   WP_Color diffuse_color;
00237   WP_Color specular_color;
00238   WP_Color emissive_color;
00239 
00240  private:
00241 
00242   //an enumeration holding the representation of the position, being a point or a vector
00243   WP_Light_Pos_Kind k;
00244   
00248   union
00249   {
00250     WP_Point3D* p;
00251     WP_Vector3D* v;
00252   };
00253 
00254   unsigned char number;
00255 };
00256 }
00257 #endif
00258 

Generated on Tue Jan 28 20:26:33 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002