-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrow.cpp
More file actions
91 lines (77 loc) · 2.39 KB
/
Copy pathArrow.cpp
File metadata and controls
91 lines (77 loc) · 2.39 KB
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
#include "MyViewer.h"
void MyViewer::drawAxes() const {
const Vec& p = axes.position;
glColor3d(1.0, 0.0, 0.0);
drawArrow(p, p + Vec(axes.size, 0.0, 0.0), axes.size / 50.0);
glColor3d(0.0, 1.0, 0.0);
drawArrow(p, p + Vec(0.0, axes.size, 0.0), axes.size / 50.0);
glColor3d(0.0, 0.0, 1.0);
drawArrow(p, p + Vec(0.0, 0.0, axes.size), axes.size / 50.0);
glEnd();
}
void MyViewer::drawWithNames() {
if (axes.shown)
return drawAxesWithNames();
switch (model_type) {
case ModelType::NONE: break;
case ModelType::MESH:
if (!show_wireframe)
return;
for (auto v : mesh.vertices()) {
glPushName(v.idx());
glRasterPos3dv(mesh.point(v).data());
glPopName();
}
break;
case ModelType::BEZIER_SURFACE:
if (!show_control_points)
return;
break;
case ModelType::INVERZ:
target.drawarrow();
break;
}
}
void MyViewer::drawAxesWithNames() const {
const Vec& p = axes.position;
glPushName(0);
drawArrow(p, p + Vec(axes.size, 0.0, 0.0), axes.size / 50.0);
glPopName();
glPushName(1);
drawArrow(p, p + Vec(0.0, axes.size, 0.0), axes.size / 50.0);
glPopName();
glPushName(2);
drawArrow(p, p + Vec(0.0, 0.0, axes.size), axes.size / 50.0);
glPopName();
}
void MyViewer::postSelection(const QPoint& p) {
int sel = selectedName();
if (sel == -1) {
axes.shown = false;
return;
}
if (axes.shown) {
axes.selected_axis = sel;
bool found;
axes.grabbed_pos = camera()->pointUnderPixel(p, found);
axes.original_pos = axes.position;
if (!found)
axes.shown = false;
return;
}
selected_vertex = sel;
if (model_type == ModelType::MESH)
axes.position = Vec(mesh.point(MyMesh::VertexHandle(sel)).data());
if (model_type == ModelType::BEZIER_SURFACE)
axes.position = control_points[sel];
if (model_type == ModelType::INVERZ)
{
axes.position = target.position;
}
double depth = camera()->projectedCoordinatesOf(axes.position)[2];
Vec q1 = camera()->unprojectedCoordinatesOf(Vec(0.0, 0.0, depth));
Vec q2 = camera()->unprojectedCoordinatesOf(Vec(width(), height(), depth));
axes.size = (q1 - q2).norm() / 10.0;
axes.shown = true;
axes.selected_axis = -1;
}