/
TextureToolRotateManipulator.cpp
151 lines (115 loc) · 3.66 KB
/
TextureToolRotateManipulator.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
#include "TextureToolRotateManipulator.h"
#include "iselectiontest.h"
#include "selection/BestPoint.h"
#include "selection/SelectionPool.h"
#include "pivot.h"
namespace selection
{
void TextureRotator::beginTransformation(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint)
{
auto device2Pivot = constructDevice2Pivot(pivot2world, view);
auto pivotPoint = device2Pivot.transformPoint(Vector3(devicePoint.x(), devicePoint.y(), 0));
_start = Vector2(pivotPoint.x(), pivotPoint.y());
auto length = _start.getLength();
if (length > 0)
{
_start /= length;
}
}
void TextureRotator::transform(const Matrix4& pivot2world, const VolumeTest& view, const Vector2& devicePoint, unsigned int constraintFlags)
{
auto device2Pivot = constructDevice2Pivot(pivot2world, view);
auto current3D = device2Pivot.transformPoint(Vector3(devicePoint.x(), devicePoint.y(), 0));
auto current = Vector2(current3D.x(), current3D.y());
auto length = current.getLength();
if (length > 0)
{
current /= length;
}
_curAngle = acos(_start.dot(current));
if (constraintFlags & Constraint::Type1)
{
_curAngle = float_snapped(_curAngle, 5 * c_DEG2RADMULT);
}
auto sign = _start.crossProduct(current) < 0 ? +1 : -1;
_curAngle *= sign;
_rotateFunctor(_curAngle);
}
void TextureRotator::resetCurAngle()
{
_curAngle = 0;
}
Vector3::ElementType TextureRotator::getCurAngle() const
{
return _curAngle;
}
TextureToolRotateManipulator::TextureToolRotateManipulator() :
_rotator(std::bind(&TextureToolRotateManipulator::rotateSelected, this, std::placeholders::_1)),
_renderableCircle(8 << 3)
{
draw_circle(8, 1.0f, &_renderableCircle.front(), RemapXYZ());
_renderableCircle.setColour(Colour4b(255, 0, 0, 255));
}
std::size_t TextureToolRotateManipulator::getId() const
{
return _id;
}
void TextureToolRotateManipulator::setId(std::size_t id)
{
_id = id;
}
IManipulator::Type TextureToolRotateManipulator::getType() const
{
return IManipulator::Rotate;
}
IManipulator::Component* TextureToolRotateManipulator::getActiveComponent()
{
return &_rotator;
}
void TextureToolRotateManipulator::setSelected(bool select)
{
_selectableZ.setSelected(select);
}
bool TextureToolRotateManipulator::isSelected() const
{
return _selectableZ.isSelected();
}
void TextureToolRotateManipulator::testSelect(SelectionTest& test, const Matrix4& pivot2world)
{
SelectionPool selector;
test.BeginMesh(pivot2world, false);
SelectionIntersection best;
test.TestLineStrip(VertexPointer(&_renderableCircle.front().vertex, sizeof(VertexCb)), _renderableCircle.size(), best);
if (best.isValid())
{
Selector_add(selector, _selectableZ);
}
if (!selector.empty())
{
selector.begin()->second->setSelected(true);
}
}
void TextureToolRotateManipulator::renderComponents(const Matrix4& pivot2World)
{
if (!_shader)
{
_shader = GlobalRenderSystem().capture("$WIRE_OVERLAY");
}
if (_renderableCircle.empty()) return;
const auto& translation = pivot2World.tCol().getVector3();
_renderableCircle.setColour(Colour4b(255, isSelected() ? 255 : 0, 0, 255));
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslated(translation.x(), translation.y(), 0);
// Enable point colours if required
glEnableClientState(GL_COLOR_ARRAY);
pointvertex_gl_array(&_renderableCircle.front());
glDrawArrays(GL_LINE_LOOP, 0, static_cast<GLsizei>(_renderableCircle.size()));
glDisableClientState(GL_COLOR_ARRAY);
glPopMatrix();
}
void TextureToolRotateManipulator::rotateSelected(double angle)
{
// TODO
}
}