24 ClassImp(TGLLightSet);
26 TGLLightSet::TGLLightSet() :
29 fLightState(kLightMask),
32 fFrontPower(0.4), fSidePower(0.7), fSpecularPower(0.8)
40 void TGLLightSet::ToggleLight(ELight light)
42 if (light == kLightSpecular) {
43 fUseSpecular = !fUseSpecular;
44 }
else if (light >= kLightMask) {
45 Error(
"TGLLightSet::ToggleLight",
"invalid light type");
55 void TGLLightSet::SetLight(ELight light, Bool_t on)
57 if (light == kLightSpecular) {
59 }
else if (light >= kLightMask) {
60 Error(
"TGLViewer::ToggleLight",
"invalid light type");
67 fLightState &= ~light;
76 void TGLLightSet::StdSetupLights(
const TGLBoundingBox& bbox,
77 const TGLCamera & camera, Bool_t debug)
84 Double_t lightRadius = bbox.Extents().Mag() * 2.9;
85 Double_t sideLightsZ, frontLightZ;
87 const TGLOrthoCamera* orthoCamera =
dynamic_cast<const TGLOrthoCamera*
>(&camera);
92 camera.FrustumPlane(TGLCamera::kNear).DistanceTo(camera.FrustumCenter())*0.7;
93 frontLightZ = sideLightsZ;
98 TGLVector3 eyeVector = camera.EyePoint() - camera.FrustumCenter();
101 sideLightsZ = eyeVector.Mag() * -0.85;
102 frontLightZ = 0.2 * lightRadius;
110 TGLVertex3 c = bbox.Center();
111 TGLVector3 center(c.X(), c.Y(), c.Z());
112 camera.RefModelViewMatrix().MultiplyIP(center);
114 Float_t pos0[] = { 0.0, 0.0, Float_t(frontLightZ), 1.0 };
115 Float_t pos1[] = { Float_t(center.X()), Float_t(center.Y() + lightRadius), Float_t(sideLightsZ), 1.0 };
116 Float_t pos2[] = { Float_t(center.X()), Float_t(center.Y() - lightRadius), Float_t(sideLightsZ), 1.0 };
117 Float_t pos3[] = { Float_t(center.X() - lightRadius), Float_t(center.Y()), Float_t(sideLightsZ), 1.0 };
118 Float_t pos4[] = { Float_t(center.X() + lightRadius), Float_t(center.Y()), Float_t(sideLightsZ), 1.0 };
120 Float_t specular = fUseSpecular ? fSpecularPower : 0.0f;
121 const Float_t frontLightColor[] = { fFrontPower, fFrontPower, fFrontPower, 1.0f };
122 const Float_t sideLightColor[] = { fSidePower, fSidePower, fSidePower, 1.0f };
123 const Float_t specLightColor[] = { specular, specular, specular, 1.0f };
125 glLightfv(GL_LIGHT0, GL_POSITION, pos0);
126 glLightfv(GL_LIGHT0, GL_DIFFUSE, frontLightColor);
127 glLightfv(GL_LIGHT0, GL_SPECULAR, specLightColor);
129 glLightfv(GL_LIGHT1, GL_POSITION, pos1);
130 glLightfv(GL_LIGHT1, GL_DIFFUSE, sideLightColor);
131 glLightfv(GL_LIGHT2, GL_POSITION, pos2);
132 glLightfv(GL_LIGHT2, GL_DIFFUSE, sideLightColor);
133 glLightfv(GL_LIGHT3, GL_POSITION, pos3);
134 glLightfv(GL_LIGHT3, GL_DIFFUSE, sideLightColor);
135 glLightfv(GL_LIGHT4, GL_POSITION, pos4);
136 glLightfv(GL_LIGHT4, GL_DIFFUSE, sideLightColor);
142 for (UInt_t light = 0; (1<<light) < kLightMask; light++)
144 if ((1<<light) & fLightState)
146 glEnable(GLenum(GL_LIGHT0 + light));
152 glDisable(GL_LIGHTING);
154 glGetLightfv(GLenum(GL_LIGHT0 + light), GL_POSITION, position);
155 Double_t size = bbox.Extents().Mag() / 10.0;
156 TGLVertex3 dPosition(position[0], position[1], position[2]);
157 TGLUtil::DrawSphere(dPosition, size, TGLUtil::fgYellow);
158 glEnable(GL_LIGHTING);
163 glDisable(GLenum(GL_LIGHT0 + light));