46 Gizmo::Gizmo(
Engine* engine,
const string&
id, int32_t gizmoTypeMask)
68 Object* gizmoEntity =
nullptr;
202 if (gizmoEntity ==
nullptr) gizmoEntity =
dynamic_cast<Object*
>(
engine->
getEntity(
id +
".tdme.gizmo.translation"));
203 if (gizmoEntity ==
nullptr) gizmoEntity =
dynamic_cast<Object*
>(
engine->
getEntity(
id +
".tdme.gizmo.rotations"));
204 if (gizmoEntity ==
nullptr) gizmoEntity =
dynamic_cast<Object*
>(
engine->
getEntity(
id +
".tdme.gizmo.scale"));
230 Vector3 gizmoTranslationOnAxis;
231 Vector3 gizmoTranslationOnAxisTmp;
232 LineSegment::computeClosestPointsOnLineSegments(axisMin, axisMax, nearPlaneWorldCoordinate, farPlaneWorldCoordinate, gizmoTranslationOnAxis, gizmoTranslationOnAxisTmp);
242 if (success ==
true) {
245 if (deltaMovement[axisIdx] < Math::EPSILON) {
246 deltaMovement[axisIdx] = -1.0f;
247 deltaMovement[axisIdx]*= movementLength;
249 if (deltaMovement[axisIdx] > Math::EPSILON) {
250 deltaMovement[axisIdx] = 1.0f;
251 deltaMovement[axisIdx]*= movementLength;
253 deltaMovement[axisIdx] = 0.0f;
280 LineSegment::computeClosestPointsOnLineSegments(axisMin, axisMax, nearPlaneWorldCoordinate, farPlaneWorldCoordinate, contactOnAxis, contactOnAxisTmp);
282 if (success ==
true) {
283 auto direction = 1.0f;
296 auto transformedVertices = vertices;
297 for (
auto& vertex: transformedVertices) {
300 if (LineSegment::doesLineSegmentCollideWithTriangle(
301 transformedVertices[0],
302 transformedVertices[1],
303 transformedVertices[2],
304 nearPlaneWorldCoordinate,
305 farPlaneWorldCoordinate,
306 lineTriangleContact) ==
true ||
307 LineSegment::doesLineSegmentCollideWithTriangle(
308 transformedVertices[2],
309 transformedVertices[3],
310 transformedVertices[0],
311 nearPlaneWorldCoordinate,
312 farPlaneWorldCoordinate,
313 lineTriangleContact) ==
true
316 if (success ==
true) {
319 deltaRotation = Vector3::computeAngle(a, b, planeNormal);
320 if (deltaRotation > 180.0f) deltaRotation = deltaRotation - 360.0f;
333 deltaTranslation.
set(0.0f, 0.0f, 0.0f);
334 deltaRotation.
set(0.0f, 0.0f, 0.0f);
335 deltaScale.
set(1.0f, 1.0f, 1.0f);
339 const Vector3 planeXYNormal(0.0f, 0.0f, -1.0f);
340 const array<Vector3, 4> planeXY = {
341 Vector3(-5000.0f, -5000.0f, 0.0f),
342 Vector3(-5000.0f, 5000.0f, 0.0f),
343 Vector3(5000.0f, 5000.0f, 0.0f),
344 Vector3(5000.0f, -5000.0f, 0.0f)
348 const Vector3 planeXZNormal(0.0f, -1.0f, 0.0f);
349 const array<Vector3, 4> planeXZ = {
350 Vector3(-5000.0f, 0.0f, -5000.0f),
351 Vector3(-5000.0f, 0.0f, 5000.0f),
352 Vector3(5000.0f, 0.0f, 5000.0f),
353 Vector3(5000.0f, 0.0f, -5000.0f)
357 const Vector3 planeYZNormal(-1.0f, 0.0f, 0.0f);
358 const array<Vector3, 4> planeYZ = {
359 Vector3(0.0f, -5000.0f, -5000.0f),
360 Vector3(0.0f, -5000.0f, 5000.0f),
361 Vector3(0.0f, 5000.0f, 5000.0f),
362 Vector3(0.0f, 5000.0f, -5000.0f)
370 deltaTranslation.
setX(gizmoMovement.
getX());
377 deltaTranslation.
setY(gizmoMovement.
getY());
384 deltaTranslation.
setZ(gizmoMovement.
getZ());
392 deltaTranslation.
setY(gizmoMovement.
getY());
393 deltaTranslation.
setZ(gizmoMovement.
getZ());
401 deltaTranslation.
setX(gizmoMovement.
getX());
402 deltaTranslation.
setZ(gizmoMovement.
getZ());
410 deltaTranslation.
setX(gizmoMovement.
getX());
411 deltaTranslation.
setY(gizmoMovement.
getY());
418 deltaScale.
add(gizmoMovement);
425 deltaScale.
add(gizmoMovement);
432 deltaScale.
add(gizmoMovement);
440 deltaScale.
add(gizmoMovement);
448 deltaScale.
add(gizmoMovement);
456 deltaScale.
add(gizmoMovement);
462 const auto& planeVertices = planeYZ;
463 const auto& planeNormal = planeYZNormal;
464 float gizmoDeltaRotation = 0.0f;
465 auto vertices = planeVertices;
466 for (
auto& vertex: vertices) {
470 if (
determineGizmoRotation(mouseX, mouseY, vertices, planeNormalTransformed, gizmoDeltaRotation) ==
true) {
471 deltaRotation.
setX(gizmoDeltaRotation);
478 const auto& planeVertices = planeXZ;
479 const auto& planeNormal = planeXZNormal;
480 float gizmoDeltaRotation = 0.0f;
481 auto vertices = planeVertices;
482 for (
auto& vertex: vertices) {
486 if (
determineGizmoRotation(mouseX, mouseY, vertices, planeNormalTransformed, gizmoDeltaRotation) ==
true) {
487 deltaRotation.
setY(gizmoDeltaRotation);
494 const auto& planeVertices = planeXY;
495 const auto& planeNormal = planeXYNormal;
496 float gizmoDeltaRotation = 0.0f;
497 auto vertices = planeVertices;
498 for (
auto& vertex: vertices) {
502 if (
determineGizmoRotation(mouseX, mouseY, vertices, planeNormalTransformed, gizmoDeltaRotation) ==
true) {
503 deltaRotation.
setZ(gizmoDeltaRotation);
516 if (selectedEntity !=
nullptr &&
517 StringTools::startsWith(selectedEntity->
getId(),
id +
".tdme.gizmo.") ==
true && selectedEntityNode !=
nullptr) {
518 auto selectedEntityNodeId = selectedEntityNode->
getId();
519 if (StringTools::startsWith(selectedEntityNodeId,
"all_") ==
true) selectedEntityNodeId = StringTools::substring(selectedEntityNodeId, 4);
548 cameraRotationTransformations.
update();
553 if (gizmoEntity !=
nullptr) {
554 cameraRotationTransformations.
setTranslation(gizmoEntity->getTranslation());
555 cameraRotationTransformations.
setScale(gizmoEntity->getScale());
556 cameraRotationTransformations.
update();
557 gizmoEntity->setTransform(cameraRotationTransformations);
558 gizmoEntity->update();
563 if (gizmoEntity !=
nullptr) {
564 cameraRotationTransformations.
setTranslation(gizmoEntity->getTranslation());
565 cameraRotationTransformations.
setScale(gizmoEntity->getScale());
566 cameraRotationTransformations.
update();
567 gizmoEntity->setTransform(cameraRotationTransformations);
571 gizmoEntity->update();
576 if (gizmoEntity !=
nullptr) {
577 cameraRotationTransformations.
setTranslation(gizmoEntity->getTranslation());
578 cameraRotationTransformations.
setScale(gizmoEntity->getScale());
579 cameraRotationTransformations.
update();
580 gizmoEntity->setTransform(cameraRotationTransformations);
587 gizmoEntity->update();
592 if (gizmoEntity !=
nullptr) {
593 cameraRotationTransformations.
setTranslation(gizmoEntity->getTranslation());
594 cameraRotationTransformations.
setScale(gizmoEntity->getScale());
595 cameraRotationTransformations.
update();
596 gizmoEntity->setTransform(cameraRotationTransformations);
603 gizmoEntity->update();
const Matrix4x4 & getCameraMatrix() const
bool removeEntity(const string &id)
Removes an entity.
Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z)
Compute world coordinate from mouse position and z value.
void addEntity(Entity *entity)
Adds an entity by id.
Entity * getEntity(const string &id)
Returns a entity by given id.
virtual const string & getId()=0
Object to be used with engine class.
void setTranslation(const Vector3 &translation) override
Set translation.
void setRenderPass(RenderPass renderPass) override
Set render pass.
void update() override
Update transform.
void setPickable(bool pickable) override
Set this entity pickable.
void setScale(const Vector3 &scale) override
Set scale.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
Representation of a 3D model.
const string & getId()
Returns id.
Line segment helper functions.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Vector3 computeEulerAngles() const
Compute Euler angles (rotation around x, y, z axes)
Quaternion class representing quaternion mathematical structure and operations with x,...
Matrix4x4 computeMatrix() const
Computes a rotation matrix4x4 from this quaternion.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & setX(float x)
Sets x component.
float computeLength() const
Vector3 & add(float scalar)
Adds a scalar.
Vector3 & setY(float y)
Sets y component.
float computeLengthSquared() const
Vector3 clone() const
Clones this vector3.
Vector3 & sub(float scalar)
Subtracts a scalar.
Vector3 & scale(float scalar)
Scales by scalar.
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Vector3 & setZ(float z)
Sets z component.
Vector3 & normalize()
Normalizes this vector3.
Vector4 class representing vector4 mathematical structure and operations with x, y,...