/
ScaleManipulator.cpp
143 lines (119 loc) · 3.92 KB
/
ScaleManipulator.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
#include "ScaleManipulator.h"
#include "selection/Remap.h"
#include "selection/SelectionPool.h"
#include "selection/BestPoint.h"
#include "selection/TransformationVisitors.h"
#include "render/View.h"
namespace selection
{
// Constructor
ScaleManipulator::ScaleManipulator(ManipulationPivot& pivot, std::size_t segments, float length) :
_pivot(pivot),
_scaleFree(*this),
_scaleAxis(*this)
{
draw_arrowline(length, &_arrowX.front(), 0);
draw_arrowline(length, &_arrowY.front(), 1);
draw_arrowline(length, &_arrowZ.front(), 2);
draw_quad(16, &_quadScreen.front());
}
void ScaleManipulator::UpdateColours() {
_arrowX.setColour(colourSelected(COLOUR_X(), _selectableX.isSelected()));
_arrowY.setColour(colourSelected(COLOUR_Y(), _selectableY.isSelected()));
_arrowZ.setColour(colourSelected(COLOUR_Z(), _selectableZ.isSelected()));
_quadScreen.setColour(colourSelected(ManipulatorBase::COLOUR_SCREEN(), _selectableScreen.isSelected()));
}
void ScaleManipulator::render(RenderableCollector& collector, const VolumeTest& volume)
{
_pivot2World.update(_pivot.getMatrix4(), volume.GetModelview(), volume.GetProjection(), volume.GetViewport());
// temp hack
UpdateColours();
collector.addRenderable(_arrowX, _pivot2World._worldSpace);
collector.addRenderable(_arrowY, _pivot2World._worldSpace);
collector.addRenderable(_arrowZ, _pivot2World._worldSpace);
collector.addRenderable(_quadScreen, _pivot2World._viewpointSpace);
}
void ScaleManipulator::testSelect(const render::View& view, const Matrix4& pivot2world)
{
_pivot2World.update(_pivot.getMatrix4(), view.GetModelview(), view.GetProjection(), view.GetViewport());
SelectionPool selector;
{
Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot2World._worldSpace));
{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowX.front(), best);
selector.addSelectable(best, &_selectableX);
}
{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowY.front(), best);
selector.addSelectable(best, &_selectableY);
}
{
SelectionIntersection best;
Line_BestPoint(local2view, &_arrowZ.front(), best);
selector.addSelectable(best, &_selectableZ);
}
}
{
Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot2World._viewpointSpace));
{
SelectionIntersection best;
Quad_BestPoint(local2view, eClipCullCW, &_quadScreen.front(), best);
selector.addSelectable(best, &_selectableScreen);
}
}
if(!selector.empty())
{
(*selector.begin()).second->setSelected(true);
}
}
ScaleManipulator::Component* ScaleManipulator::getActiveComponent()
{
if(_selectableX.isSelected())
{
_scaleAxis.SetAxis(g_vector3_axis_x);
return &_scaleAxis;
}
else if(_selectableY.isSelected())
{
_scaleAxis.SetAxis(g_vector3_axis_y);
return &_scaleAxis;
}
else if(_selectableZ.isSelected())
{
_scaleAxis.SetAxis(g_vector3_axis_z);
return &_scaleAxis;
}
else
return &_scaleFree;
}
void ScaleManipulator::setSelected(bool select)
{
_selectableX.setSelected(select);
_selectableY.setSelected(select);
_selectableZ.setSelected(select);
_selectableScreen.setSelected(select);
}
bool ScaleManipulator::isSelected() const
{
return _selectableX.isSelected()
| _selectableY.isSelected()
| _selectableZ.isSelected()
| _selectableScreen.isSelected();
}
void ScaleManipulator::scale(const Vector3& scaling)
{
// Pass the scale to the according traversor
if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
{
GlobalSelectionSystem().foreachSelectedComponent(ScaleComponentSelected(scaling, _pivot.getVector3()));
}
else
{
GlobalSelectionSystem().foreachSelected(ScaleSelected(scaling, _pivot.getVector3()));
}
// Update the scene views
SceneChangeNotify();
}
}