#include "TGLLightSet.h"
#include "TGLBoundingBox.h"
#include "TGLOrthoCamera.h"
#include "TGLIncludes.h"
ClassImp(TGLLightSet)
TGLLightSet::TGLLightSet() :
TObject(),
fLightState(kLightMask),
fUseSpecular(kTRUE)
{
}
void TGLLightSet::ToggleLight(ELight light)
{
if (light == kLightSpecular) {
fUseSpecular = !fUseSpecular;
} else if (light >= kLightMask) {
Error("TGLLightSet::ToggleLight", "invalid light type");
return;
} else {
fLightState ^= light;
}
}
void TGLLightSet::SetLight(ELight light, Bool_t on)
{
if (light == kLightSpecular) {
fUseSpecular = on;
} else if (light >= kLightMask) {
Error("TGLViewer::ToggleLight", "invalid light type");
return;
}
if (on) {
fLightState |= light;
} else {
fLightState &= ~light;
}
}
void TGLLightSet::StdSetupLights(const TGLBoundingBox& bbox,
const TGLCamera & camera, Bool_t debug)
{
glPushMatrix();
if (!bbox.IsEmpty())
{
Double_t lightRadius = bbox.Extents().Mag() * 2.9;
Double_t sideLightsZ, frontLightZ;
const TGLOrthoCamera* orthoCamera = dynamic_cast<const TGLOrthoCamera*>(&camera);
if (orthoCamera) {
sideLightsZ =
camera.FrustumPlane(TGLCamera::kNear).DistanceTo(camera.FrustumCenter())*0.7;
frontLightZ = sideLightsZ;
} else {
TGLVector3 eyeVector = camera.EyePoint() - camera.FrustumCenter();
sideLightsZ = eyeVector.Mag() * -0.85;
frontLightZ = 0.2 * lightRadius;
}
glLoadIdentity();
TGLVertex3 center = bbox.Center();
Float_t pos0[] = { 0.0, 0.0, frontLightZ, 1.0 };
Float_t pos1[] = { center.X(), center.Y() + lightRadius, sideLightsZ, 1.0 };
Float_t pos2[] = { center.X(), center.Y() - lightRadius, sideLightsZ, 1.0 };
Float_t pos3[] = { center.X() - lightRadius, center.Y(), sideLightsZ, 1.0 };
Float_t pos4[] = { center.X() + lightRadius, center.Y(), sideLightsZ, 1.0 };
const Float_t frontLightColor[] = { 0.4, 0.4, 0.4, 1.0 };
const Float_t sideLightColor[] = { 0.7, 0.7, 0.7, 1.0 };
const Float_t whiteSpec[] = { 0.8, 0.8, 0.8, 1.0 };
const Float_t nullSpec[] = { 0.0, 0.0, 0.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, pos0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, frontLightColor);
glLightfv(GL_LIGHT0, GL_SPECULAR, fUseSpecular ? whiteSpec : nullSpec);
glLightfv(GL_LIGHT1, GL_POSITION, pos1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, sideLightColor);
glLightfv(GL_LIGHT2, GL_POSITION, pos2);
glLightfv(GL_LIGHT2, GL_DIFFUSE, sideLightColor);
glLightfv(GL_LIGHT3, GL_POSITION, pos3);
glLightfv(GL_LIGHT3, GL_DIFFUSE, sideLightColor);
glLightfv(GL_LIGHT4, GL_POSITION, pos4);
glLightfv(GL_LIGHT4, GL_DIFFUSE, sideLightColor);
}
for (UInt_t light = 0; (1<<light) < kLightMask; light++)
{
if ((1<<light) & fLightState)
{
glEnable(GLenum(GL_LIGHT0 + light));
if (debug)
{
glDisable(GL_LIGHTING);
Float_t yellow[4] = { 1.0, 1.0, 0.0, 1.0 };
Float_t position[4];
glGetLightfv(GLenum(GL_LIGHT0 + light), GL_POSITION, position);
Double_t size = bbox.Extents().Mag() / 10.0;
TGLVertex3 dPosition(position[0], position[1], position[2]);
TGLUtil::DrawSphere(dPosition, size, yellow);
glEnable(GL_LIGHTING);
}
}
else
{
glDisable(GLenum(GL_LIGHT0 + light));
}
}
glPopMatrix();
}
Last change: Wed Jun 25 08:41:00 2008
Last generated: 2008-06-25 08:41
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.