Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLLightSet.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Matevz Tadel, Feb 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TGLLightSet.h"
13
14#include "TGLBoundingBox.h"
15#include "TGLOrthoCamera.h"
16
17#include "TGLIncludes.h"
18
19/** \class TGLLightSet
20\ingroup opengl
21Encapsulates a set of lights for OpenGL.
22*/
23
25
27 TObject(),
28
29 fLightState(kLightMask), // All on
30 fUseSpecular(kTRUE),
31
32 fFrontPower(0.4), fSidePower(0.7), fSpecularPower(0.8)
33{
34 // Constructor.
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Toggle light on/off.
39
41{
42 if (light == kLightSpecular) {
44 } else if (light >= kLightMask) {
45 Error("TGLLightSet::ToggleLight", "invalid light type");
46 return;
47 } else {
49 }
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Set a light on/off.
54
56{
57 if (light == kLightSpecular) {
59 } else if (light >= kLightMask) {
60 Error("TGLViewer::ToggleLight", "invalid light type");
61 return;
62 }
63
64 if (on) {
66 } else {
68 }
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Setup lights for current given bounding box and camera.
73/// This is called by standard GL viewer.
74/// Expects matrix-mode to be model-view.
75
78{
80
81 if (!bbox.IsEmpty())
82 {
83 // Calculate a sphere radius to arrange lights round
84 Double_t lightRadius = bbox.Extents().Mag() * 2.9;
86
87 const TGLOrthoCamera* orthoCamera = dynamic_cast<const TGLOrthoCamera*>(&camera);
88 if (orthoCamera) {
89 // Find distance from near clip plane to furstum center - i.e. vector of half
90 // clip depth. Ortho lights placed this distance from eye point
92 camera.FrustumPlane(TGLCamera::kNear).DistanceTo(camera.FrustumCenter())*0.7;
94 } else {
95 // Perspective camera
96 // Extract vector from camera eye point to center.
97 // Camera must have been applied already.
98 TGLVector3 eyeVector = camera.EyePoint() - camera.FrustumCenter();
99
100 // Pull forward slightly (0.85) to avoid to sharp a cutoff
101 sideLightsZ = eyeVector.Mag() * -0.85;
102 frontLightZ = 0.2 * lightRadius;
103 }
104
105 // Reset the modelview so static lights are placed in fixed eye space
106 // This will destroy camera application.
108
109 // 0: Front, 1: Top, 2: Bottom, 3: Left, 4: Right
110 TGLVertex3 c = bbox.Center();
111 TGLVector3 center(c.X(), c.Y(), c.Z());
112 camera.RefModelViewMatrix().MultiplyIP(center);
113 // Float_t pos0[] = { center.X(), center.Y(), frontLightZ, 1.0 };
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 };
119
123 const Float_t specLightColor[] = { specular, specular, specular, 1.0f };
124
128
137 }
138
139 // Set light states every time - must be deferred until now when we know we
140 // are in the correct thread for GL context
141 // TODO: Could detect state change and only adjust if a change
142 for (UInt_t light = 0; (1<<light) < kLightMask; light++)
143 {
144 if ((1<<light) & fLightState)
145 {
147
148 // Debug mode - show active lights in yellow
149 if (debug)
150 {
151 // Lighting itself needs to be disable so a single one can show...!
153 Float_t position[4]; // Only float parameters for lights (no double)....
155 Double_t size = bbox.Extents().Mag() / 10.0;
156 TGLVertex3 dPosition(position[0], position[1], position[2]);
159 }
160 }
161 else
162 {
164 }
165 }
166
167 // Restore camera which was applied before we were called, and is disturbed
168 // by static light positioning above.
169 glPopMatrix();
170}
unsigned int GLenum
Definition GL_glu.h:266
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition TGLCamera.h:44
Encapsulates a set of lights for OpenGL.
Definition TGLLightSet.h:22
Bool_t fUseSpecular
light states (on/off) mask
Definition TGLLightSet.h:37
Float_t fFrontPower
Definition TGLLightSet.h:39
void StdSetupLights(const TGLBoundingBox &bbox, const TGLCamera &camera, Bool_t debug=kFALSE)
Setup lights for current given bounding box and camera.
void ToggleLight(ELight light)
Toggle light on/off.
Float_t fSidePower
power of the front lamp
Definition TGLLightSet.h:40
TGLLightSet()
power of specular lamp
Float_t fSpecularPower
power of the side lamps
Definition TGLLightSet.h:41
void SetLight(ELight light, Bool_t on)
Set a light on/off.
UInt_t fLightState
Definition TGLLightSet.h:36
Orthographic projection camera.
static void DrawSphere(const TGLVertex3 &position, Double_t radius, const UChar_t rgba[4])
Draw sphere, centered on vertex 'position', with radius 'radius', color 'rgba'.
Definition TGLUtil.cxx:2357
static const UChar_t fgYellow[4]
Definition TGLUtil.h:1433
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
Double_t X() const
Definition TGLUtil.h:119
Double_t Y() const
Definition TGLUtil.h:121
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987