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
24
26 TObject(),
27
28 fLightState(kLightMask), // All on
29 fUseSpecular(kTRUE),
30
31 fFrontPower(0.4), fSidePower(0.7), fSpecularPower(0.8)
32{
33 // Constructor.
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Toggle light on/off.
38
40{
41 if (light == kLightSpecular) {
43 } else if (light >= kLightMask) {
44 Error("TGLLightSet::ToggleLight", "invalid light type");
45 return;
46 } else {
48 }
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Set a light on/off.
53
55{
56 if (light == kLightSpecular) {
58 } else if (light >= kLightMask) {
59 Error("TGLViewer::ToggleLight", "invalid light type");
60 return;
61 }
62
63 if (on) {
65 } else {
67 }
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Setup lights for current given bounding box and camera.
72/// This is called by standard GL viewer.
73/// Expects matrix-mode to be model-view.
74
77{
79
80 if (!bbox.IsEmpty())
81 {
82 // Calculate a sphere radius to arrange lights round
83 Double_t lightRadius = bbox.Extents().Mag() * 2.9;
85
86 const TGLOrthoCamera* orthoCamera = dynamic_cast<const TGLOrthoCamera*>(&camera);
87 if (orthoCamera) {
88 // Find distance from near clip plane to furstum center - i.e. vector of half
89 // clip depth. Ortho lights placed this distance from eye point
91 camera.FrustumPlane(TGLCamera::kNear).DistanceTo(camera.FrustumCenter())*0.7;
93 } else {
94 // Perspective camera
95 // Extract vector from camera eye point to center.
96 // Camera must have been applied already.
97 TGLVector3 eyeVector = camera.EyePoint() - camera.FrustumCenter();
98
99 // Pull forward slightly (0.85) to avoid to sharp a cutoff
100 sideLightsZ = eyeVector.Mag() * -0.85;
101 frontLightZ = 0.2 * lightRadius;
102 }
103
104 // Reset the modelview so static lights are placed in fixed eye space
105 // This will destroy camera application.
107
108 // 0: Front, 1: Top, 2: Bottom, 3: Left, 4: Right
109 TGLVertex3 c = bbox.Center();
110 TGLVector3 center(c.X(), c.Y(), c.Z());
111 camera.RefModelViewMatrix().MultiplyIP(center);
112 // Float_t pos0[] = { center.X(), center.Y(), frontLightZ, 1.0 };
113 Float_t pos0[] = { 0.0, 0.0, Float_t(frontLightZ), 1.0 };
114 Float_t pos1[] = { Float_t(center.X()), Float_t(center.Y() + lightRadius), Float_t(sideLightsZ), 1.0 };
115 Float_t pos2[] = { Float_t(center.X()), Float_t(center.Y() - lightRadius), Float_t(sideLightsZ), 1.0 };
116 Float_t pos3[] = { Float_t(center.X() - lightRadius), Float_t(center.Y()), Float_t(sideLightsZ), 1.0 };
117 Float_t pos4[] = { Float_t(center.X() + lightRadius), Float_t(center.Y()), Float_t(sideLightsZ), 1.0 };
118
122 const Float_t specLightColor[] = { specular, specular, specular, 1.0f };
123
127
136 }
137
138 // Set light states every time - must be deferred until now when we know we
139 // are in the correct thread for GL context
140 // TODO: Could detect state change and only adjust if a change
141 for (UInt_t light = 0; (1<<light) < kLightMask; light++)
142 {
143 if ((1<<light) & fLightState)
144 {
146
147 // Debug mode - show active lights in yellow
148 if (debug)
149 {
150 // Lighting itself needs to be disable so a single one can show...!
152 Float_t position[4]; // Only float parameters for lights (no double)....
154 Double_t size = bbox.Extents().Mag() / 10.0;
155 TGLVertex3 dPosition(position[0], position[1], position[2]);
158 }
159 }
160 else
161 {
163 }
164 }
165
166 // Restore camera which was applied before we were called, and is disturbed
167 // by static light positioning above.
168 glPopMatrix();
169}
#define c(i)
Definition RSha256.hxx:101
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
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.
TGLVector3 Extents() const
TGLVertex3 Center() const
Bool_t IsEmpty() const
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Definition TGLCamera.h:44
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:2348
static const UChar_t fgYellow[4]
Definition TGLUtil.h:1424
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
Double_t Mag() const
Definition TGLUtil.h:298
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:1071