1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#if defined(_MSC_VER) /* MSVC Compiler */
#pragma warning ( disable : 4305 )
#pragma warning ( disable : 4786 )
#endif
#include <float.h>
#include "qwt3d_plot.h"
using namespace Qwt3D;
namespace {
inline GLenum lightEnum(unsigned idx)
{
switch(idx) {
case 0:
return GL_LIGHT0;
case 1:
return GL_LIGHT1;
case 2:
return GL_LIGHT2;
case 3:
return GL_LIGHT3;
case 4:
return GL_LIGHT4;
case 5:
return GL_LIGHT5;
case 6:
return GL_LIGHT6;
case 7:
return GL_LIGHT7;
default:
return GL_LIGHT0;
}
}
}
void Plot3D::enableLighting(bool val)
{
if (lighting_enabled_ == val)
return;
lighting_enabled_ = val;
makeCurrent();
if (val)
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
if (!initializedGL())
return;
updateGL();
}
void Plot3D::disableLighting(bool val)
{
enableLighting(!val);
}
bool Plot3D::lightingEnabled() const
{
return lighting_enabled_;
}
/**
\param light light number [0..7]
\see setLight
*/
void Plot3D::illuminate(unsigned light)
{
if (light>7)
return;
lights_[light].unlit = false;
}
/**
\param light light number [0..7]
\see setLight
*/
void Plot3D::blowout(unsigned light)
{
if (light>7)
return;
lights_[light].unlit = false;
}
/**
Sets GL material properties
*/
void Plot3D::setMaterialComponent(GLenum property, double r, double g, double b, double a)
{
GLfloat rgba[4] = {(GLfloat)r, (GLfloat)g, (GLfloat)b, (GLfloat)a};
makeCurrent();
glMaterialfv(GL_FRONT_AND_BACK, property, rgba);
}
/**
This function is for convenience. It sets GL material properties with the equal r,g,b values
and a blending alpha with value 1.0
*/
void Plot3D::setMaterialComponent(GLenum property, double intensity)
{
setMaterialComponent(property,intensity,intensity,intensity,1.0);
}
/**
Sets GL shininess
*/
void Plot3D::setShininess(double exponent)
{
makeCurrent();
glMaterialf(GL_FRONT, GL_SHININESS, exponent);
}
/**
Sets GL light properties for light 'light'
*/
void Plot3D::setLightComponent(GLenum property, double r, double g, double b, double a, unsigned light)
{
GLfloat rgba[4] = {(GLfloat)r, (GLfloat)g, (GLfloat)b, (GLfloat)a};
makeCurrent();
glLightfv(lightEnum(light), property, rgba);
}
/**
This function is for convenience. It sets GL light properties with the equal r,g,b values
and a blending alpha with value 1.0
*/
void Plot3D::setLightComponent(GLenum property, double intensity, unsigned light)
{
setLightComponent(property,intensity,intensity,intensity,1.0, lightEnum(light));
}
/**
Set the rotation angle of the light source. If you look along the respective axis towards ascending values,
the rotation is performed in mathematical \e negative sense
\param xVal angle in \e degree to rotate around the X axis
\param yVal angle in \e degree to rotate around the Y axis
\param zVal angle in \e degree to rotate around the Z axis
\param light light number
*/
void Plot3D::setLightRotation( double xVal, double yVal, double zVal, unsigned light )
{
if (light>7)
return;
lights_[light].rot.x = xVal;
lights_[light].rot.y = yVal;
lights_[light].rot.z = zVal;
}
/**
Set the shift in light source (world) coordinates.
\param xVal shift along (world) X axis
\param yVal shift along (world) Y axis
\param zVal shift along (world) Z axis
\param light light number
\see setViewportShift()
*/
void Plot3D::setLightShift( double xVal, double yVal, double zVal, unsigned light )
{
if (light>7)
return;
lights_[light].shift.x = xVal;
lights_[light].shift.y = yVal;
lights_[light].shift.z = zVal;
}
void Plot3D::applyLight(unsigned light)
{
if (lights_[light].unlit)
return;
glEnable(lightEnum(light));
glLoadIdentity();
glRotatef( lights_[light].rot.x-90, 1.0, 0.0, 0.0 );
glRotatef( lights_[light].rot.y , 0.0, 1.0, 0.0 );
glRotatef( lights_[light].rot.z , 0.0, 0.0, 1.0 );
GLfloat lightPos[4] = { lights_[light].shift.x, lights_[light].shift.y, lights_[light].shift.z, 1.0};
GLenum le = lightEnum(light);
glLightfv(le, GL_POSITION, lightPos);
}
void Plot3D::applyLights()
{
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
for (unsigned i=0; i<8; ++i)
{
applyLight(i);
}
glPopMatrix();
}
|