00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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
00175
00176
00177
00178
00179 }
00180 else
00181 {
00182 glLightfv(GL_LIGHT0 + number, GL_POSITION, p->data);
00183
00184
00185
00186
00187
00188
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
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