/
ManipulatorComponents.h
204 lines (167 loc) · 4.85 KB
/
ManipulatorComponents.h
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
#pragma once
#include "iscenegraph.h"
#include "math/Vector3.h"
#include "math/Matrix4.h"
#include "math/Quaternion.h"
#include "render.h"
#include "selection/TransformationVisitors.h"
#include "Translatable.h"
#include "Rotatable.h"
#include "Scalable.h"
#include "selection/ManipulationPivot.h"
#include <functional>
namespace selection
{
/* greebo: The following are specialised manipulatables that provide the methods as described in the ABC.
* They basically prepare and constraing the transformations of the three base movements above (Translatable, etc.)
*
* So, for example, the TranslateAxis class takes care that the Translatable is only moved in the axis directions.
* The necessary device pointer >> translation vector calculations are performed within Transform()
*/
class RotateFree :
public Manipulator::Component
{
Vector3 _start;
Rotatable& _rotatable;
public:
RotateFree(Rotatable& rotatable) :
_rotatable(rotatable)
{}
void Construct(const Matrix4& device2manip, const float x, const float y) override;
void Transform(const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y) override;
};
class RotateAxis :
public Manipulator::Component
{
Vector3 _axis;
Vector3 _start;
Rotatable& _rotatable;
public:
RotateAxis(Rotatable& rotatable) :
_rotatable(rotatable)
{}
void Construct(const Matrix4& device2manip, const float x, const float y) override;
/// \brief Converts current position to a normalised vector orthogonal to axis.
void Transform(const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y) override;
void SetAxis(const Vector3& axis)
{
_axis = axis;
}
};
class TranslateAxis : public Manipulator::Component
{
Vector3 _start;
Vector3 _axis;
Translatable& _translatable;
public:
TranslateAxis(Translatable& translatable) :
_translatable(translatable)
{}
void Construct(const Matrix4& device2manip, const float x, const float y) override;
void Transform(const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y) override;
void SetAxis(const Vector3& axis)
{
_axis = axis;
}
};
class TranslateFree :
public Manipulator::Component
{
private:
Vector3 _start;
Translatable& _translatable;
public:
TranslateFree(Translatable& translatable) :
_translatable(translatable)
{}
void Construct(const Matrix4& device2manip, const float x, const float y) override;
void Transform(const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y) override;
};
class ScaleAxis :
public Manipulator::Component
{
private:
Vector3 _start;
Vector3 _axis;
Scalable& _scalable;
public:
ScaleAxis(Scalable& scalable) :
_scalable(scalable)
{}
void Construct(const Matrix4& device2manip, const float x, const float y) override;
void Transform(const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y) override;
void SetAxis(const Vector3& axis)
{
_axis = axis;
}
};
class ScaleFree :
public Manipulator::Component
{
private:
Vector3 _start;
Scalable& _scalable;
public:
ScaleFree(Scalable& scalable) :
_scalable(scalable)
{}
void Construct(const Matrix4& device2manip, const float x, const float y) override;
void Transform(const Matrix4& manip2object, const Matrix4& device2manip, const float x, const float y) override;
};
// ========= Translatables ===============================================
class ResizeTranslatable :
public Translatable
{
void translate(const Vector3& translation) override
{
Scene_Translate_Component_Selected(GlobalSceneGraph(), translation);
}
};
class SelectionTranslator :
public Translatable
{
public:
typedef std::function<void(const Vector3&)> TranslationCallback;
private:
TranslationCallback _onTranslation;
public:
SelectionTranslator(const TranslationCallback& onTranslation) :
_onTranslation(onTranslation)
{}
void translate(const Vector3& translation) override
{
if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
{
Scene_Translate_Component_Selected(GlobalSceneGraph(), translation);
}
else
{
Scene_Translate_Selected(GlobalSceneGraph(), translation);
}
// Invoke the feedback function
if (_onTranslation)
{
_onTranslation(translation);
}
}
};
class TranslatablePivot :
public Translatable
{
private:
ManipulationPivot& _pivot;
public:
TranslatablePivot(ManipulationPivot& pivot) :
_pivot(pivot)
{}
void translate(const Vector3& translation) override
{
_pivot.applyTranslation(translation);
// User is placing the pivot manually, so let's keep it that way
_pivot.setUserLocked(true);
}
};
// ===============================================================================
void transform_local2object(Matrix4& object, const Matrix4& local, const Matrix4& local2object);
void translation_local2object(Vector3& object, const Vector3& local, const Matrix4& local2object);
}