-
Notifications
You must be signed in to change notification settings - Fork 2
/
DPWidgetRen.cpp
371 lines (320 loc) · 10.1 KB
/
DPWidgetRen.cpp
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
//-------------------------------------------------------------------------
//
// Joe Kniss
// Data Probe widget
// DPWidgetRen.cpp Probes volumetric data
// 3-14-01
// ________ ____ ___
// | \ / | / /
// +---+ \/ |/ /
// +--+| |\ /| <
// | || | \ / | |\ \
// | | \/ | | \ \
// \_____| |__| \__\
// Copyright 2001
// Joe Michael Kniss
// "All Your Base are Belong to Us"
//-------------------------------------------------------------------------
#include <iostream.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/glut.h>
#include "VectorMath.h"
#include "gluvv.h"
#include "DPWidgetRen.h"
//================================================= DPWidgetRen()
//===============================================================
DPWidgetRen::DPWidgetRen()
{
//g = gluvv;
widgetInit();
transparent();
pos[0] = 0.0;
pos[1] = 0.0;
pos[2] = 0.0;
length = .5;
sliderpos = .8;
gluvv.probe.slider = sliderpos;
pntfac = .1;
pickedObj = 0;
identityMatrix(xform);
if(gluvv.mv)
update_pos();
}
//================================================ ~DPWidgetRen()
//===============================================================
DPWidgetRen::~DPWidgetRen()
{
}
//========================================================== Draw
//===============================================================
void DPWidgetRen::draw()
{
if(!gluvv.mv) return;
if(gluvv.picking) fill();
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
//glDisable(GL_TEXTURE_3D_EXT);
if(gluvv.reblend == GB_NONE){
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
}
else if(gluvv.reblend == GB_UNDER){
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
glDepthFunc(GL_EQUAL);
}
defaultMaterial();
glPushMatrix();{
gluvvPushName();
glPushName(11);
glPushName(111);
glPushName(1111);
move_pos();
glTranslatef(pos[0], pos[1], pos[2]);
glMultMatrixf(xform);
glRotatef(-90, 1, 0, 0);
//glDrawBuffer(GL_BACK);
float spos[3] = {0,0,length+length*pntfac};
if(!gluvv.reblend)
glColor4f(0,0,0,0);
else
glColor4f(.1, .07, .57, 1); //balls
drawSphere(spos, topball);
float slpos[3] = {0, 0, length*pntfac + sliderpos*(length - ballRad)};
drawSlider(0, WdgZAxis, slpos, slider1); //slider
float bpos[3] = {0, 0, length*pntfac};
if(!gluvv.reblend)
glColor4f(0,0,0,0);
else
glColor4f(.09, .34, .55, 1); //bar
drawBar(0, WdgZAxis, length, bpos, mainbar);
float cpos[3] = {0,0,0};
drawCone(0, WdgZAxis, length*pntfac, cpos, point);
//glDrawBuffer(GL_FRONT);
//glColor4f(.1, .07, .57, 1); //ball
//drawSphere(spos, topball);
//drawSlider(0, WdgZAxis, slpos, slider1); //slider
//glColor4f(.09, .34, .55, 1); //bars
//drawBar(0, WdgZAxis, length, bpos, mainbar);
//drawCone(0, WdgZAxis, length*pntfac, cpos, point);
gluvvPopNames();
} glPopMatrix();
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
DPWidgetRenGlErr("draw");
if(gluvv.picking) transparent();
}
//========================================================== pick
//===============================================================
int DPWidgetRen::pick(int data1, int data2, int data3,
float x, float y, float z)
{
fill();
pickedObj = data3;
update_pos();
glutSetWindowTitle("Data Probe Widget");
gluvv.mprobe = 0;
return 1;
}
int DPWidgetRen::pick()
{
fill();
pickedObj = gluvv.pick.data3;
update_pos();
glutSetWindowTitle("Data Probe Widget");
gluvv.mprobe = 0;
return 1;
}
//===================================================================== key
//=========================================================================
int DPWidgetRen::key(unsigned char key, int x, int y)
{
if(key == 32){ //space bar
gluvv.tf.paintme = 1;
glutPostRedisplay();
return 1; //key used
}
return 0; //key not used
}
//========================================================= mouse
//===============================================================
int DPWidgetRen::mouse(int button, int state,
int x, int y)
{
//cerr << "DPWidget moused" << endl;
if(state == GLUT_DOWN){
winpos[0] = lastwinpos[0] = x;
winpos[1] = lastwinpos[1] = y;
switch(button){
case GLUT_LEFT_BUTTON:
switch(pickedObj){
case topball:
tball.start((2.0 * x - gluvv.win.width) / gluvv.win.width,
(2.0 * y - gluvv.win.height) / gluvv.win.height);
}
break;
case GLUT_MIDDLE_BUTTON:
break;
case GLUT_RIGHT_BUTTON:
break;
}
}
else{ //state is _UP
gluvv.volren.sampleRate = gluvv.volren.goodSamp;
glutSetWindowTitle("Data Probe Widget");
glutPostRedisplay();
}
return 1;
}
//========================================================== move
//===============================================================
int DPWidgetRen::move(int x, int y)
{
float dx = (float)(x - lastwinpos[0])/(float)gluvv.win.width;
float dy = (float)(y - lastwinpos[1])/(float)gluvv.win.height;
float d[3];
subV3(d, pos, gluvv.env.eye);
float dist = normV3(d);
dx *= (gluvv.env.frustum[1]-gluvv.env.frustum[0]) * dist/gluvv.env.clip[0];
dy *= (gluvv.env.frustum[3]-gluvv.env.frustum[2]) * dist/gluvv.env.clip[0];
if((gluvv.mouse.state == GLUT_DOWN) && //left
(gluvv.mouse.button == GLUT_LEFT_BUTTON) && //down
(pickedObj == topball)){ //topball
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
tball.update((2.0 * x - gluvv.win.width) /gluvv.win.width,
(2.0 * y - gluvv.win.height) /gluvv.win.height);
tball.buildRotMatrix((float (*)[4])xform);
glutPostRedisplay();
}
else if((gluvv.mouse.state == GLUT_DOWN) && //left
(gluvv.mouse.button == GLUT_LEFT_BUTTON) && //down
(pickedObj == slider1)){ //slider1
sliderpos += ((float)(x - lastwinpos[0])/(float)gluvv.win.width -
(float)(y - lastwinpos[1])/(float)gluvv.win.height);
sliderpos = (sliderpos > 1) ? 1 : ((sliderpos < 0) ? 0 : sliderpos);
gluvv.probe.slider = sliderpos;
gluvv.tf.loadme = 1;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutPostRedisplay();
}
else if((gluvv.mouse.state == GLUT_DOWN) && //left
(gluvv.mouse.button == GLUT_LEFT_BUTTON)){ //down
pos[0] -= dx; //any
pos[1] -= dy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutPostRedisplay();
}
else if((gluvv.mouse.state == GLUT_DOWN) && //middle
(gluvv.mouse.button == GLUT_MIDDLE_BUTTON)){//down
pos[0] -= dx; //any
pos[2] += dy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutPostRedisplay();
}
else if((gluvv.mouse.state == GLUT_DOWN) && //right
(gluvv.mouse.button == GLUT_RIGHT_BUTTON)){ //down
pos[2] -= dx; //any
pos[1] -= dy;
gluvv.volren.sampleRate = gluvv.volren.interactSamp;
glutPostRedisplay();
}
update_pos();
lastwinpos[0] = x;
lastwinpos[1] = y;
return 1;
}
//======================================================= Release
//===============================================================
int DPWidgetRen::release()
{
transparent();
//cerr << "DPWidget released" << endl;
return 0;
}
void DPWidgetRen::update_pos()
{
//move the point tip to volume space
float m1[16];
identityMatrix(m1);
m1[12] = gluvv.rinfo.trans[0];
m1[13] = gluvv.rinfo.trans[1];
m1[14] = gluvv.rinfo.trans[2];
float m2[16];
matrixMult(m2, m1, gluvv.rinfo.xform);
float scale[16];
identityMatrix(scale);
scale[0] = gluvv.rinfo.scale;
scale[5] = gluvv.rinfo.scale;
scale[10]= gluvv.rinfo.scale;
float m3[16];
matrixMult(m3, m2, scale);
float m4[16];
identityMatrix(m4);
m4[12] = -.5 * gluvv.mv->xfSize;
m4[13] = -.5 * gluvv.mv->yfSize;
m4[14] = -.5 * gluvv.mv->zfSize;
float m5[16];
matrixMult(m5, m3, m4);
float m6[16] = {gluvv.mv->xfSize, 0, 0, 0,
0, gluvv.mv->yfSize, 0, 0,
0, 0, gluvv.mv->zfSize, 0,
0, 0, 0, 1};
float volm[16];
matrixMult(volm, m5, m6);
float invVolm[16];
inverseMatrix(invVolm, volm);
float vpos[3];
translateV3W(vpos, invVolm, pos);
gluvv.probe.vpos[0] = vpos[0];
gluvv.probe.vpos[1] = vpos[1];
gluvv.probe.vpos[2] = vpos[2];
//cerr << "pos = " << vpos[0] << " " << vpos[1] << " " << vpos[2] << endl;
}
inline
void DPWidgetRen::move_pos()
{
float m1[16];
identityMatrix(m1);
m1[12] = gluvv.rinfo.trans[0];
m1[13] = gluvv.rinfo.trans[1];
m1[14] = gluvv.rinfo.trans[2];
float m2[16];
matrixMult(m2, m1, gluvv.rinfo.xform);
float scale[16];
identityMatrix(scale);
scale[0] = gluvv.rinfo.scale;
scale[5] = gluvv.rinfo.scale;
scale[10]= gluvv.rinfo.scale;
float m3[16];
matrixMult(m3, m2, scale);
float m4[16];
identityMatrix(m4);
m4[12] = -.5*gluvv.mv->xfSize;
m4[13] = -.5*gluvv.mv->yfSize;
m4[14] = -.5*gluvv.mv->zfSize;
float m5[16];
matrixMult(m5, m3, m4);
float m6[16] = {gluvv.mv->xfSize, 0, 0, 0,
0, gluvv.mv->yfSize, 0, 0,
0, 0, gluvv.mv->zfSize, 0,
0, 0, 0, 1};
float volm[16];
matrixMult(volm, m5, m6);
translateV3W(pos, volm, gluvv.probe.vpos);
}
//============================================== DPWidgetRenGlErr
//===============================================================
int DPWidgetRen::DPWidgetRenGlErr(char *place)
{
GLenum errCode;
const GLubyte *errString;
if((errCode = glGetError()) != GL_NO_ERROR){
errString = gluErrorString(errCode);
cerr << endl << "OpenGL error : DPWidgetRen::" << place << " : "
<< (char *) errString << endl << endl;
return 1;
}
return 0;
}