TDME2 1.9.121
Gizmo.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
10#include <tdme/engine/Frustum.h>
12#include <tdme/math/Matrix4x4.h>
14#include <tdme/math/Vector3.h>
15#include <tdme/math/Vector4.h>
19
21
37
38Gizmo::Gizmo(Engine* engine, const string& id, int32_t gizmoTypeMask)
39{
40 this->engine = engine;
41 this->id = id;
42 this->gizmoTypeMask = gizmoTypeMask;
46}
47
49}
50
51void Gizmo::updateGizmo(const Vector3& gizmoCenter, const Transformations& transformations) {
52 Object3D* gizmoEntity = nullptr;
53 auto zNearNormal = engine->getCamera()->getFrustum()->getPlanes()[Frustum::PLANE_NEAR].getNormal();
54 auto lookFrom = engine->getCamera()->getLookFrom();
55 auto zNearDistance = engine->getCamera()->getFrustum()->getPlanes()[Frustum::PLANE_NEAR].computeDistance(gizmoCenter);
56 Vector3 a,b,c,d;
57 Vector4 e;
58 Quaternion q1, q2;
59 q1.rotate(zNearNormal, -45.0f);
60 q2.rotate(zNearNormal, 135.0f);
61 e = engine->getCamera()->getModelViewProjectionMatrix().multiply(Vector4(lookFrom + zNearNormal * 1.0f + q1.multiply(Vector3(0.0f, -0.5f, 0.0f)), 1.0f));
62 e.scale(1.0f / e.getW());
63 a.set(e.getX(), e.getY(), e.getZ());
64 e = engine->getCamera()->getModelViewProjectionMatrix().multiply(Vector4(lookFrom + zNearNormal * 1.0f + q2.multiply(Vector3(0.0f, -0.5f, 0.0f)), 1.0f));
65 e.scale(1.0f / e.getW());
66 b.set(e.getX(), e.getY(), e.getZ());
67 e = engine->getCamera()->getModelViewProjectionMatrix().multiply(Vector4(lookFrom + zNearNormal * zNearDistance + q1.multiply(Vector3(0.0f, -0.5f, 0.0f)), 1.0f));
68 e.scale(1.0f / e.getW());
69 c.set(e.getX(), e.getY(), e.getZ());
70 e = engine->getCamera()->getModelViewProjectionMatrix().multiply(Vector4(lookFrom + zNearNormal * zNearDistance + q2.multiply(Vector3(0.0f, -0.5f, 0.0f)), 1.0f));
71 e.scale(1.0f / e.getW());
72 d.set(e.getX(), e.getY(), e.getZ());
73 auto baX = b.getX() - a.getX();
74 auto baY = b.getY() - a.getY();
75 auto dcX = d.getX() - c.getX();
76 auto dcY = d.getY() - c.getY();
77 auto baXDivdcX = baX / dcX;
78 auto baYDivdcY = baY / dcY;
79 auto scale = baXDivdcX / 3.0f ;
80 switch (getGizmoType()) {
81 case GIZMOTYPE_ALL:
82 {
86 engine->removeEntity(id + ".tdme.gizmo.translation");
87 engine->removeEntity(id + ".tdme.gizmo.scale");
88 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.all"));
89 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.all", Tools::getGizmoAll()));
90 gizmoEntity->setPickable(true);
91 gizmoEntity->setDisableDepthTest(true);
92 gizmoEntity->setTranslation(gizmoCenter);
93 gizmoEntity->setScale(Vector3(scale, scale, scale));
94 gizmoEntity->update();
95 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.rotations"));
96 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.rotations", Tools::getGizmoRotations()));
97 gizmoEntity->setPickable(true);
98 gizmoEntity->setDisableDepthTest(true);
99 gizmoEntity->setTranslation(gizmoCenter);
100 gizmoEntity->setScale(Vector3(scale, scale, scale));
101 gizmoEntity->update();
102 } else
105 engine->removeEntity(id + ".tdme.gizmo.translation");
106 engine->removeEntity(id + ".tdme.gizmo.rotations");
107 engine->removeEntity(id + ".tdme.gizmo.scale");
108 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.all"));
109 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.all", Tools::getGizmoTranslationScale()));
110 gizmoEntity->setPickable(true);
111 gizmoEntity->setDisableDepthTest(true);
112 gizmoEntity->setTranslation(gizmoCenter);
113 gizmoEntity->setScale(Vector3(scale, scale, scale));
114 gizmoEntity->update();
115 } else {
117 engine->removeEntity(id + ".tdme.gizmo.all");
118 engine->removeEntity(id + ".tdme.gizmo.rotations");
119 engine->removeEntity(id + ".tdme.gizmo.scale");
120 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.translation"));
121 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.translation", Tools::getGizmoTranslation()));
122 gizmoEntity->setPickable(true);
123 gizmoEntity->setDisableDepthTest(true);
124 gizmoEntity->setTranslation(gizmoCenter);
125 gizmoEntity->setScale(Vector3(scale, scale, scale));
126 gizmoEntity->update();
127 }
129 engine->removeEntity(id + ".tdme.gizmo.all");
130 engine->removeEntity(id + ".tdme.gizmo.translation");
131 engine->removeEntity(id + ".tdme.gizmo.scale");
132 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.rotations"));
133 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.rotations", Tools::getGizmoRotations()));
134 gizmoEntity->setPickable(true);
135 gizmoEntity->setDisableDepthTest(true);
136 gizmoEntity->setTranslation(gizmoCenter);
137 gizmoEntity->setScale(Vector3(scale, scale, scale));
138 gizmoEntity->update();
139 }
141 engine->removeEntity(id + ".tdme.gizmo.all");
142 engine->removeEntity(id + ".tdme.gizmo.translation");
143 engine->removeEntity(id + ".tdme.gizmo.rotations");
144 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.scale"));
145 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.scale", Tools::getGizmoScale()));
146 gizmoEntity->setPickable(true);
147 gizmoEntity->setDisableDepthTest(true);
148 gizmoEntity->setTranslation(gizmoCenter);
149 gizmoEntity->setScale(Vector3(scale, scale, scale));
150 gizmoEntity->update();
151 }
152 }
153 break;
154 }
156 {
157 engine->removeEntity(id + ".tdme.gizmo.all");
158 engine->removeEntity(id + ".tdme.gizmo.scale");
159 engine->removeEntity(id + ".tdme.gizmo.rotations");
160 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.translation"));
161 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.translation", Tools::getGizmoTranslation()));
162 gizmoEntity->setPickable(true);
163 gizmoEntity->setDisableDepthTest(true);
164 gizmoEntity->setTranslation(gizmoCenter);
165 gizmoEntity->setScale(Vector3(scale, scale, scale));
166 gizmoEntity->update();
167 break;
168 }
169 case GIZMOTYPE_ROTATE:
170 {
171 engine->removeEntity(id + ".tdme.gizmo.all");
172 engine->removeEntity(id + ".tdme.gizmo.translation");
173 engine->removeEntity(id + ".tdme.gizmo.scale");
174 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.rotations"));
175 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.rotations", Tools::getGizmoRotations()));
176 gizmoEntity->setPickable(true);
177 gizmoEntity->setDisableDepthTest(true);
178 gizmoEntity->setTranslation(gizmoCenter);
179 gizmoEntity->setScale(Vector3(scale, scale, scale));
180 gizmoEntity->update();
181 break;
182 }
183 case GIZMOTYPE_SCALE:
184 {
185 engine->removeEntity(id + ".tdme.gizmo.all");
186 engine->removeEntity(id + ".tdme.gizmo.translation");
187 engine->removeEntity(id + ".tdme.gizmo.rotations");
188 gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.scale"));
189 if (gizmoEntity == nullptr) engine->addEntity(gizmoEntity = new Object3D(id + ".tdme.gizmo.scale", Tools::getGizmoScale()));
190 gizmoEntity->setPickable(true);
191 gizmoEntity->setDisableDepthTest(true);
192 gizmoEntity->setTranslation(gizmoCenter);
193 gizmoEntity->setScale(Vector3(scale, scale, scale));
194 gizmoEntity->update();
195 break;
196 }
197 case GIZMOTYPE_NONE:
198 break;
199 }
200 setGizmoRotation(transformations);
201}
202
204 auto gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.all"));
205 if (gizmoEntity == nullptr) gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.translation"));
206 if (gizmoEntity == nullptr) gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.rotations"));
207 if (gizmoEntity == nullptr) gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.scale"));
208 return gizmoEntity;
209}
210
212 engine->removeEntity(id + ".tdme.gizmo.all");
213 engine->removeEntity(id + ".tdme.gizmo.translation");
214 engine->removeEntity(id + ".tdme.gizmo.scale");
215 engine->removeEntity(id + ".tdme.gizmo.rotations");
217}
218
219bool Gizmo::determineGizmoMovement(int mouseX, int mouseY, vector<Vector3> vertices, Vector3& deltaMovement) {
220 auto gizmoEntity = getGizmoObject3D();
221 if (gizmoEntity == nullptr) return false;
222 auto nearPlaneWorldCoordinate = engine->computeWorldCoordinateByMousePosition(mouseX, mouseY, 0.0f);
223 auto farPlaneWorldCoordinate = engine->computeWorldCoordinateByMousePosition(mouseX, mouseY, 1.0f);
224 Vector3 lineTriangleContact;
225 for (auto& vertex: vertices) {
226 vertex.add(gizmoEntity->getTranslation());
227 }
228 if (LineSegment::doesLineSegmentCollideWithTriangle(
229 vertices[0],
230 vertices[1],
231 vertices[2],
232 nearPlaneWorldCoordinate,
233 farPlaneWorldCoordinate,
234 lineTriangleContact) == true ||
235 LineSegment::doesLineSegmentCollideWithTriangle(
236 vertices[2],
237 vertices[3],
238 vertices[0],
239 nearPlaneWorldCoordinate,
240 farPlaneWorldCoordinate,
241 lineTriangleContact) == true
242 ) {
243 auto success = gizmoLastResultAvailable == true;
244 if (success == true) {
245 deltaMovement = lineTriangleContact.clone().sub(gizmoLastResult);
246 }
247 gizmoLastResult = lineTriangleContact;
249 return success;
250 }
251 return false;
252}
253
254bool Gizmo::determineGizmoDeltaTransformations(int mouseLastX, int mouseLastY, int mouseX, int mouseY, Vector3& deltaTranslation, Vector3& deltaRotation, Vector3& deltaScale) {
255 if (getGizmoMode() == GIZMOMODE_NONE) return false;
256 auto deltaX = mouseX - mouseLastX;
257 auto deltaY = mouseY - mouseLastY;
258 deltaTranslation.set(0.0f, 0.0f, 0.0f);
259 deltaRotation.set(0.0f, 0.0f, 0.0f);
260 deltaScale.set(1.0f, 1.0f, 1.0f);
261 Vector3 gizmoDeltaMovement;
262 const vector<Vector3> planeXY =
263 {
264 Vector3(-5000.0f, -5000.0f, 0.0f),
265 Vector3(-5000.0f, 5000.0f, 0.0f),
266 Vector3(5000.0f, 5000.0f, 0.0f),
267 Vector3(5000.0f, -5000.0f, 0.0f)
268 };
269 const vector<Vector3> planeXZ =
270 {
271 Vector3(-5000.0f, 0.0f, -5000.0f),
272 Vector3(-5000.0f, 0.0f, 5000.0f),
273 Vector3(5000.0f, 0.0f, 5000.0f),
274 Vector3(5000.0f, 0.0f, -5000.0f)
275 };
276 const vector<Vector3> planeYZ =
277 {
278 Vector3(0.0f, -5000.0f, -5000.0f),
279 Vector3(0.0f, -5000.0f, 5000.0f),
280 Vector3(0.0f, 5000.0f, 5000.0f),
281 Vector3(0.0f, 5000.0f, -5000.0f)
282
283 };
284 switch (getGizmoMode()) {
286 {
287 vector<Vector3> vertices = planeXZ;
288 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
289 deltaTranslation.setX(gizmoDeltaMovement.getX());
290 }
291 break;
292 }
294 {
295 vector<Vector3> vertices = planeYZ;
296 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
297 deltaTranslation.setY(gizmoDeltaMovement.getY());
298 }
299 break;
300 }
302 {
303 vector<Vector3> vertices = planeXZ;
304 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
305 deltaTranslation.setZ(gizmoDeltaMovement.getZ());
306 }
307 break;
308 }
310 {
311 vector<Vector3> vertices = planeYZ;
312 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
313 deltaTranslation.setY(gizmoDeltaMovement.getY());
314 deltaTranslation.setZ(gizmoDeltaMovement.getZ());
315 }
316 break;
317 }
319 {
320 vector<Vector3> vertices = planeXZ;
321 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
322 deltaTranslation.setX(gizmoDeltaMovement.getX());
323 deltaTranslation.setZ(gizmoDeltaMovement.getZ());
324 }
325 break;
326 }
328 {
329 vector<Vector3> vertices = planeXY;
330 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
331 deltaTranslation.setX(gizmoDeltaMovement.getX());
332 deltaTranslation.setY(gizmoDeltaMovement.getY());
333 }
334 break;
335 }
337 {
338 vector<Vector3> vertices = planeXZ;
339 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
340 deltaScale.add(Vector3(gizmoDeltaMovement.getX(), 0.0f, 0.0f));
341 }
342 break;
343 }
345 {
346 vector<Vector3> vertices = planeYZ;
347 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
348 deltaScale.add(Vector3(0.0f, gizmoDeltaMovement.getY(), 0.0f));
349 }
350 break;
351 }
353 {
354 vector<Vector3> vertices = planeXZ;
355 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
356 deltaScale.add(Vector3(0.0f, 0.0f, -gizmoDeltaMovement.getZ()));
357 }
358 break;
359 }
361 {
362 vector<Vector3> vertices = planeYZ;
363 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
364 deltaScale.add(Vector3(0.0f, gizmoDeltaMovement.getY(), gizmoDeltaMovement.getZ()));
365 }
366 break;
367 }
369 {
370 vector<Vector3> vertices = planeXZ;
371 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
372 deltaScale.add(Vector3(gizmoDeltaMovement.getX(), 0.0f, gizmoDeltaMovement.getZ()));
373 }
374 break;
375 }
377 {
378 vector<Vector3> vertices = planeXY;
379 if (determineGizmoMovement(mouseX, mouseY, vertices, gizmoDeltaMovement) == true) {
380 deltaScale.add(Vector3(gizmoDeltaMovement.getX(), gizmoDeltaMovement.getY(), 0.0f));
381 }
382 break;
383 }
385 deltaRotation.setX((deltaX + -deltaY) * 20.0f * engine->getTiming()->getDeltaTime() / 1000.0f);
386 break;
388 deltaRotation.setY((deltaX + -deltaY) * 20.0f * engine->getTiming()->getDeltaTime() / 1000.0f);
389 break;
391 deltaRotation.setZ((deltaX + -deltaY) * 20.0f * engine->getTiming()->getDeltaTime() / 1000.0f);
392 break;
393 case GIZMOMODE_NONE:
394 // no op, satisfy the compiler
395 break;
396 }
397 return true;
398}
399
400bool Gizmo::determineGizmoMode(Entity* selectedEntity, Node* selectedEntityNode) {
401 if (selectedEntity != nullptr &&
402 StringTools::startsWith(selectedEntity->getId(), id + ".tdme.gizmo.") == true && selectedEntityNode != nullptr) {
403 auto selectedEntityNodeId = selectedEntityNode->getId();
404 if (StringTools::startsWith(selectedEntityNodeId, "all_") == true) selectedEntityNodeId = StringTools::substring(selectedEntityNodeId, 4);
405 if (selectedEntityNodeId == "translate_x") setGizmoMode(GIZMOMODE_TRANSLATE_X); else
406 if (selectedEntityNodeId == "translate_y") setGizmoMode(GIZMOMODE_TRANSLATE_Y); else
407 if (selectedEntityNodeId == "translate_z") setGizmoMode(GIZMOMODE_TRANSLATE_Z); else
408 if (selectedEntityNodeId == "translate_x_plane") setGizmoMode(GIZMOMODE_TRANSLATEPLANE_X); else
409 if (selectedEntityNodeId == "translate_y_plane") setGizmoMode(GIZMOMODE_TRANSLATEPLANE_Z); else
410 if (selectedEntityNodeId == "translate_z_plane") setGizmoMode(GIZMOMODE_TRANSLATEPLANE_Y); else
411 if (selectedEntityNodeId == "rotate_x") setGizmoMode(GIZMOMODE_ROTATE_X); else
412 if (selectedEntityNodeId == "rotate_y") setGizmoMode(GIZMOMODE_ROTATE_Y); else
413 if (selectedEntityNodeId == "rotate_z") setGizmoMode(GIZMOMODE_ROTATE_Z); else
414 if (selectedEntityNodeId == "scale_x") setGizmoMode(GIZMOMODE_SCALE_X); else
415 if (selectedEntityNodeId == "scale_y") setGizmoMode(GIZMOMODE_SCALE_Y); else
416 if (selectedEntityNodeId == "scale_z") setGizmoMode(GIZMOMODE_SCALE_Z); else
417 if (selectedEntityNodeId == "scale_x_plane") setGizmoMode(GIZMOMODE_SCALEPLANE_X); else
418 if (selectedEntityNodeId == "scale_y_plane") setGizmoMode(GIZMOMODE_SCALEPLANE_Y); else
419 if (selectedEntityNodeId == "scale_z_plane") setGizmoMode(GIZMOMODE_SCALEPLANE_Z); else
421 return true;
422 }
423 return false;
424}
425
426void Gizmo::setGizmoRotation(const Transformations& transformations) {
427 auto rotationsMatrix = transformations.getRotationsQuaternion().computeMatrix();
428 {
429 auto gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.scale"));
430 if (gizmoEntity != nullptr) {
431 gizmoEntity->setNodeTransformationsMatrix("scale_x", gizmoEntity->getModel()->getNodeById("scale_x")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
432 gizmoEntity->setNodeTransformationsMatrix("scale_y", gizmoEntity->getModel()->getNodeById("scale_y")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
433 gizmoEntity->setNodeTransformationsMatrix("scale_z", gizmoEntity->getModel()->getNodeById("scale_z")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
434 gizmoEntity->setNodeTransformationsMatrix("scale_x_plane", gizmoEntity->getModel()->getNodeById("scale_x_plane")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
435 gizmoEntity->setNodeTransformationsMatrix("scale_y_plane", gizmoEntity->getModel()->getNodeById("scale_y_plane")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
436 gizmoEntity->setNodeTransformationsMatrix("scale_z_plane", gizmoEntity->getModel()->getNodeById("scale_x_plane")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
437 gizmoEntity->update();
438 }
439 }
440 {
441 auto gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.rotations"));
442 if (gizmoEntity != nullptr) {
443 gizmoEntity->setNodeTransformationsMatrix("rotate_x", gizmoEntity->getModel()->getNodeById("rotate_x")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
444 gizmoEntity->setNodeTransformationsMatrix("rotate_y", gizmoEntity->getModel()->getNodeById("rotate_y")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
445 gizmoEntity->setNodeTransformationsMatrix("rotate_z", gizmoEntity->getModel()->getNodeById("rotate_z")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
446 gizmoEntity->update();
447 }
448 }
449 {
450 auto gizmoEntity = dynamic_cast<Object3D*>(engine->getEntity(id + ".tdme.gizmo.all"));
451 if (gizmoEntity != nullptr) {
452 if (gizmoEntity->getModel()->getNodeById("all_scale_x") != nullptr) gizmoEntity->setNodeTransformationsMatrix("all_scale_x", gizmoEntity->getModel()->getNodeById("all_scale_x")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
453 if (gizmoEntity->getModel()->getNodeById("all_scale_y") != nullptr) gizmoEntity->setNodeTransformationsMatrix("all_scale_y", gizmoEntity->getModel()->getNodeById("all_scale_y")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
454 if (gizmoEntity->getModel()->getNodeById("all_scale_z") != nullptr) gizmoEntity->setNodeTransformationsMatrix("all_scale_z", gizmoEntity->getModel()->getNodeById("all_scale_z")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
455 if (gizmoEntity->getModel()->getNodeById("scale_x") != nullptr) gizmoEntity->setNodeTransformationsMatrix("scale_x", gizmoEntity->getModel()->getNodeById("scale_x")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
456 if (gizmoEntity->getModel()->getNodeById("scale_y") != nullptr) gizmoEntity->setNodeTransformationsMatrix("scale_y", gizmoEntity->getModel()->getNodeById("scale_y")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
457 if (gizmoEntity->getModel()->getNodeById("scale_z") != nullptr) gizmoEntity->setNodeTransformationsMatrix("scale_z", gizmoEntity->getModel()->getNodeById("scale_z")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
458 if (gizmoEntity->getModel()->getNodeById("scale_x_plane") != nullptr) gizmoEntity->setNodeTransformationsMatrix("scale_x_plane", gizmoEntity->getModel()->getNodeById("scale_x_plane")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
459 if (gizmoEntity->getModel()->getNodeById("scale_y_plane") != nullptr) gizmoEntity->setNodeTransformationsMatrix("scale_y_plane", gizmoEntity->getModel()->getNodeById("scale_y_plane")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
460 if (gizmoEntity->getModel()->getNodeById("scale_z_plane") != nullptr) gizmoEntity->setNodeTransformationsMatrix("scale_z_plane", gizmoEntity->getModel()->getNodeById("scale_x_plane")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
461 if (gizmoEntity->getModel()->getNodeById("rotate_x") != nullptr) gizmoEntity->setNodeTransformationsMatrix("rotate_x", gizmoEntity->getModel()->getNodeById("rotate_x")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
462 if (gizmoEntity->getModel()->getNodeById("rotate_y") != nullptr) gizmoEntity->setNodeTransformationsMatrix("rotate_y", gizmoEntity->getModel()->getNodeById("rotate_y")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
463 if (gizmoEntity->getModel()->getNodeById("rotate_z") != nullptr) gizmoEntity->setNodeTransformationsMatrix("rotate_z", gizmoEntity->getModel()->getNodeById("rotate_z")->getTransformationsMatrix().clone().multiply(rotationsMatrix));
464 gizmoEntity->update();
465 }
466 }
467}
const Vector3 & getLookFrom() const
Definition: Camera.h:213
Frustum * getFrustum()
Definition: Camera.h:271
const Matrix4x4 & getModelViewProjectionMatrix() const
Definition: Camera.h:257
Engine main class.
Definition: Engine.h:122
bool removeEntity(const string &id)
Removes an entity.
Definition: Engine.cpp:451
Timing * getTiming()
Definition: Engine.h:900
Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z)
Compute world coordinate from mouse position and z value.
Definition: Engine.cpp:1469
void addEntity(Entity *entity)
Adds an entity by id.
Definition: Engine.cpp:364
Entity * getEntity(const string &id)
Returns a entity by given id.
Definition: Engine.h:981
Camera * getCamera()
Definition: Engine.h:907
TDME engine entity.
Definition: Entity.h:31
virtual const string & getId()=0
Frustum class.
Definition: Frustum.h:30
const array< Plane, 6 > & getPlanes()
Definition: Frustum.h:57
Object 3D to be used with engine class.
Definition: Object3D.h:60
void setTranslation(const Vector3 &translation) override
Set translation.
Definition: Object3D.h:271
void update() override
Update transformations.
Definition: Object3D.cpp:58
void setPickable(bool pickable) override
Set this object pickable.
Definition: Object3D.h:263
void setScale(const Vector3 &scale) override
Set scale.
Definition: Object3D.h:279
void setDisableDepthTest(bool disableDepthTest)
Set disable depth test.
Definition: Object3D.h:484
int64_t getDeltaTime()
Gets the time passed between last and current frame.
Definition: Timing.h:83
Transformations which contain scale, rotations and translation.
const Quaternion & getRotationsQuaternion() const
Representation of a 3d model.
Definition: Model.h:32
Model node.
Definition: Node.h:31
const string & getId()
Returns id.
Definition: Node.h:85
Line segment helper functions.
Definition: LineSegment.h:17
void setNodeTransformationsMatrix(const string &id, const Matrix4x4 &matrix)
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Definition: Matrix4x4.h:351
Quaternion class.
Definition: Quaternion.h:22
Quaternion & rotate(const Vector3 &axis, float angle)
Creates a rotation quaternion.
Definition: Quaternion.h:196
Quaternion & multiply(const Quaternion q)
Multiplies this quaternion with quaternion q.
Definition: Quaternion.h:227
Matrix4x4 computeMatrix() const
Computes a matrix from given.
Definition: Quaternion.h:299
3D vector 3 class
Definition: Vector3.h:22
float getY() const
Definition: Vector3.h:119
float getX() const
Definition: Vector3.h:103
float getZ() const
Definition: Vector3.h:136
Vector3 & setZ(float z)
Set Z.
Definition: Vector3.h:145
Vector3 & set(float x, float y, float z)
Set up vector.
Definition: Vector3.h:73
Vector3 & setX(float x)
Set X.
Definition: Vector3.h:111
Vector3 clone() const
Clones the vector.
Definition: Vector3.h:372
Vector3 & sub(const Vector3 &v)
Subtracts a vector.
Definition: Vector3.h:325
Vector3 & add(const Vector3 &v)
Adds a vector.
Definition: Vector3.h:301
Vector3 & setY(float y)
Set Y.
Definition: Vector3.h:128
3D vector 4 class
Definition: Vector4.h:19
float getY() const
Definition: Vector4.h:149
float getX() const
Definition: Vector4.h:132
float getZ() const
Definition: Vector4.h:166
float getW() const
Definition: Vector4.h:183
Vector4 & scale(float scale)
Scale this vector.
Definition: Vector4.h:229
Gizmo tool for views.
Definition: Gizmo.h:26
virtual ~Gizmo()
Destructor.
Definition: Gizmo.cpp:48
void updateGizmo(const Vector3 &gizmoCenter, const Transformations &transformations)
Update gizmo.
Definition: Gizmo.cpp:51
void setGizmoMode(GizmoMode gizmoMode)
Set GIZMO mode.
Definition: Gizmo.h:128
GizmoType getGizmoType() const
Definition: Gizmo.h:104
bool determineGizmoMovement(int mouseX, int mouseY, vector< Vector3 > vertices, Vector3 &deltaMovement)
Determine movement on a plane given by 4 vertices.
Definition: Gizmo.cpp:219
void setGizmoRotation(const Transformations &transformations)
Set gizmo rotation.
Definition: Gizmo.cpp:426
bool determineGizmoDeltaTransformations(int mouseLastX, int mouseLastY, int mouseX, int mouseY, Vector3 &deltaTranslation, Vector3 &deltaRotation, Vector3 &deltaScale)
Determine GIZMO delta transformations.
Definition: Gizmo.cpp:254
void removeGizmo()
Remove gizmo.
Definition: Gizmo.cpp:211
void setGizmoType(GizmoType gizmoType)
Set GIZMO type.
Definition: Gizmo.h:112
GizmoMode getGizmoMode() const
Definition: Gizmo.h:120
bool determineGizmoMode(Entity *selectedEntity, Node *selectedEntityNode)
Select GIZMO mode.
Definition: Gizmo.cpp:400
static Model * getGizmoTranslation()
Definition: Tools.cpp:614
static Model * getGizmoTranslationScale()
Definition: Tools.cpp:607
static Model * getGizmoScale()
Definition: Tools.cpp:621
static Model * getGizmoRotations()
Definition: Tools.cpp:628
static Model * getGizmoAll()
Definition: Tools.cpp:600
Console class.
Definition: Console.h:26
String tools class.
Definition: StringTools.h:20