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
|
#include "qwt3d_drawable.h"
using namespace Qwt3D;
Drawable::~Drawable()
{
detachAll();
}
void Drawable::saveGLState()
{
glGetBooleanv(GL_LINE_SMOOTH, &ls);
glGetBooleanv(GL_POLYGON_SMOOTH, &pols);
glGetFloatv(GL_LINE_WIDTH, &lw);
glGetIntegerv(GL_BLEND_SRC, &blsrc);
glGetIntegerv(GL_BLEND_DST, &bldst);
glGetDoublev(GL_CURRENT_COLOR, col);
glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &pattern);
glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &factor);
glGetBooleanv(GL_LINE_STIPPLE, &sallowed);
glGetBooleanv(GL_TEXTURE_2D, &tex2d);
glGetIntegerv(GL_POLYGON_MODE, polmode);
glGetIntegerv(GL_MATRIX_MODE, &matrixmode);
glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &poloffs[0]);
glGetFloatv(GL_POLYGON_OFFSET_UNITS, &poloffs[1]);
glGetBooleanv(GL_POLYGON_OFFSET_FILL, &poloffsfill);
}
void Drawable::restoreGLState()
{
Enable(GL_LINE_SMOOTH, ls);
Enable(GL_POLYGON_SMOOTH, pols);
setDeviceLineWidth(lw);
glBlendFunc(blsrc, bldst);
glColor4dv(col);
glLineStipple(factor,pattern);
Enable(GL_LINE_STIPPLE,sallowed);
Enable(GL_TEXTURE_2D,tex2d);
glPolygonMode(polmode[0], polmode[1]);
glMatrixMode(matrixmode);
glPolygonOffset(poloffs[0], poloffs[1]);
setDevicePolygonOffset(poloffs[0], poloffs[1]);
Enable(GL_POLYGON_OFFSET_FILL, poloffsfill);
}
void Drawable::Enable(GLenum what, GLboolean val)
{
if (val)
glEnable(what);
else
glDisable(what);
}
void Drawable::attach(Drawable* dr)
{
if ( dlist.end() == std::find( dlist.begin(), dlist.end(), dr ) )
if (dr)
{
dlist.push_back(dr);
}
}
void Drawable::detach(Drawable* dr)
{
std::list<Drawable*>::iterator it = std::find(dlist.begin(), dlist.end(), dr);
if ( it != dlist.end() )
{
dlist.erase(it);
}
}
void Drawable::detachAll()
{
dlist.clear();
}
//! simplified glut routine (glUnProject): windows coordinates_p --> object coordinates_p
/**
Don't rely on (use) this in display lists !
*/
Triple Drawable::ViewPort2World(Triple win, bool* err)
{
Triple obj;
getMatrices(modelMatrix, projMatrix, viewport);
int res = gluUnProject(win.x, win.y, win.z, modelMatrix, projMatrix, viewport, &obj.x, &obj.y, &obj.z);
if (err)
*err = (res) ? false : true;
return obj;
}
//! simplified glut routine (glProject): object coordinates_p --> windows coordinates_p
/**
Don't rely on (use) this in display lists !
*/
Triple Drawable::World2ViewPort(Triple obj, bool* err)
{
Triple win;
getMatrices(modelMatrix, projMatrix, viewport);
int res = gluProject(obj.x, obj.y, obj.z, modelMatrix, projMatrix, viewport, &win.x, &win.y, &win.z);
if (err)
*err = (res) ? false : true;
return win;
}
/**
Don't rely on (use) this in display lists !
*/
Triple Drawable::relativePosition(Triple rel)
{
return ViewPort2World(Triple((rel.x-viewport[0])*viewport[2],(rel.y-viewport[1])*viewport[3],rel.z));
}
void Drawable::draw()
{
saveGLState();
for (std::list<Drawable*>::iterator it = dlist.begin(); it!=dlist.end(); ++it)
{
(*it)->draw();
}
restoreGLState();
}
void Drawable::setColor(double r, double g, double b, double a)
{
color = RGBA(r,g,b,a);
}
void Drawable::setColor(RGBA rgba)
{
color = rgba;
}
|