diff --git a/include/light.h b/include/light.h index f21a805..f5f33d9 100755 --- a/include/light.h +++ b/include/light.h @@ -30,6 +30,7 @@ void translate(Vec d); void show(); void hide(); + void setColor(Color *); virtual void draw(); void trace(bool _s); }; diff --git a/sources/light.cpp b/sources/light.cpp index a3a4252..2f23ed4 100755 --- a/sources/light.cpp +++ b/sources/light.cpp @@ -1,7 +1,6 @@ #include "light.h" Light::Light() { - //TODO: this class should be abstract printf("light not initialized\n"); } @@ -17,12 +16,6 @@ showtrace = true; sphere = gluNewQuadric(); - //glLightfv(num, GL_AMBIENT, mat->ambient->v()); - glLightfv(num, GL_DIFFUSE, mat->ambient->v()); - glLightfv(num, GL_SPECULAR, mat->specular->v()); - //TODO - //glLightf(num,GL_QUADRATIC_ATTENUATION,.001f); - show(); } @@ -53,11 +46,22 @@ rot->add((Vec)a); } +void Light::setColor(Color* c) { + Color sp = *(mat->specular->clone()); + delete mat; + mat = new Material(*(c->clone()), sp); +} void Light::draw() { //save camera position glPushMatrix(); + //glLightfv(num, GL_AMBIENT, mat->ambient->v()); + glLightfv(num, GL_DIFFUSE, mat->ambient->v()); + glLightfv(num, GL_SPECULAR, mat->specular->v()); + //TODO + //glLightf(num,GL_QUADRATIC_ATTENUATION,.001f); + glTranslatef(pos->x(), pos->y(), pos->z()); float p[] = {0.0f, 0.0f, 0.0f, 1.0f}; @@ -94,10 +98,12 @@ glTranslatef(pos->x(), pos->y(), pos->z()); glLightf(num, GL_SPOT_CUTOFF, cutoff_angle); + //last parameter: 1 for positional + // 0 for directional float p[] = {0.0f, 0.0f, 0.0f, 1.0f}; glLightfv(num, GL_POSITION, p); - GLfloat dir[] = {0.0f, -1.0f, 0.0f, 1.0f}; + GLfloat dir[] = {0.0f, -1.0f, 0.0f}; glLightfv(num, GL_SPOT_DIRECTION, dir); if (showtrace) {