00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00045
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
00140 #ifdef VP_OGL
00141 if (on) {
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
00178 return true;
00179 #else
00180 return false;
00181 #endif
00182 }