00001 #include <gra/reflection/GLReflection.h>
00002 #include <esg/emittance/SpotEmittance.h>
00003 #include <GL/gl.h>
00004
00005 using namespace gra;
00006
00007 void GLReflection::setScene(Scene * pScene)
00008 {
00009 LocalReflection::setScene(pScene);
00010
00011 if (!_pLights) return;
00012
00013 GLfloat lPosA[4];
00014 GLfloat lColA[4];
00015 GLenum attenuation;
00016 Vector3 src;
00017 Emittance* pEmittance;
00018 Matrix4* pTrMat;
00019 Color3f color;
00020
00021 glMatrixMode(GL_MODELVIEW);
00022
00023 for (ESGint i = 0; i < LightArray::MAX_LIGHTS; i++) {
00024 if (!_pLights->isSet(i)) continue;
00025 pEmittance = _pLights->getEmittance(i);
00026 if (!pEmittance) continue;
00027
00028 if (_pLights->isOn(i)) glEnable((GLenum)(GL_LIGHT0+i));
00029 else glDisable((GLenum)(GL_LIGHT0+i));
00030
00031 pEmittance->intensity(color);
00032 lColA[0] = color.x;
00033 lColA[1] = color.y;
00034 lColA[2] = color.z;
00035 lColA[3] = 1;
00036
00037 pTrMat = _pLights->getTransformation(i);
00038
00039 if (pTrMat) {
00040 float m[16];
00041 pTrMat->transpose();
00042 pTrMat->get(m);
00043 pTrMat->transpose();
00044 glPushMatrix();
00045 glMultMatrixf(m);
00046 }
00047
00048 if (pEmittance->sourceLocation(src)) {
00049 lPosA[0] = src.x;
00050 lPosA[1] = src.y;
00051 lPosA[2] = src.z;
00052 lPosA[3] = 1;
00053 } else
00054 lPosA[3] = 0;
00055
00056 int fadePower = (int) pEmittance->fadePower();
00057 if (fadePower < 1) attenuation = GL_CONSTANT_ATTENUATION;
00058 else
00059 if (fadePower < 2) attenuation = GL_LINEAR_ATTENUATION;
00060 else
00061 attenuation = GL_QUADRATIC_ATTENUATION;
00062
00063 glLightfv((GLenum)(GL_LIGHT0+i), GL_POSITION, lPosA);
00064 glLightfv((GLenum)(GL_LIGHT0+i), GL_DIFFUSE, lColA);
00065
00066 glLightfv((GLenum)(GL_LIGHT0+i), GL_SPECULAR, lColA);
00067 glLightf((GLenum)(GL_LIGHT0+i), attenuation, 1);
00068
00069 if (IS_INSTANCE_OF(*pEmittance, SpotEmittance)) {
00070 Vector3 vdir;
00071 (void) pEmittance->beamDirection(vdir);
00072 GLfloat dir[4] = { vdir.x, vdir.y, vdir.z, 1};
00073
00074 glLightfv((GLenum)(GL_LIGHT0+i), GL_SPOT_DIRECTION, dir);
00075 glLighti((GLenum)(GL_LIGHT0+i), GL_SPOT_EXPONENT,
00076 ((SpotEmittance*)pEmittance)->concentration());
00077 glLightf((GLenum)(GL_LIGHT0+i), GL_SPOT_CUTOFF,
00078 ((SpotEmittance*)pEmittance)->spreadAngle() * 180 / PI);
00079 }
00080
00081 if ((++i) >= GL_MAX_LIGHTS) return;
00082 }
00083 }