TDME2 1.9.121
Gizmo.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include <tdme/tdme.h>
9#include <tdme/math/Vector3.h>
11
12using std::vector;
13
20
21/**
22 * Gizmo tool for views
23 * @author Andreas Drewke
24 */
26{
27public:
28 enum GizmoType {
34 };
35 enum GizmoMode {
52 };
53
54private:
55 Engine* engine { nullptr };
56 string id;
62
63public:
64 /**
65 * Public constructor
66 * @param engine engine
67 * @param id id
68 * @param gizmoTypeMask gizmo type mask
69 */
71
72 /**
73 * Destructor
74 */
75 virtual ~Gizmo();
76
77 /**
78 * Set engine
79 * @param engine engine
80 */
81 inline void setEngine(Engine* engine) {
82 this->engine = engine;
83 }
84
85 /**
86 * @return GIZMO type mask
87 */
88 inline int32_t getGizmoTypeMask() const {
89 return gizmoTypeMask;
90 }
91
92 /**
93 * Set GIZMO type mask
94 * @param gizmoTypeMask GIZMO type mask
95 */
97 this->gizmoTypeMask = gizmoTypeMask;
99 }
100
101 /**
102 * @return GIZMO type
103 */
104 inline GizmoType getGizmoType() const {
105 return gizmoType;
106 }
107
108 /**
109 * Set GIZMO type
110 * @param gizmoType GIZMO type
111 */
113 if (gizmoType != GIZMOTYPE_ALL && (gizmoType & gizmoTypeMask) == 0) return;
114 this->gizmoType = gizmoType;
115 }
116
117 /**
118 * @return GIZMO mode
119 */
120 inline GizmoMode getGizmoMode() const {
121 return gizmoMode;
122 }
123
124 /**
125 * Set GIZMO mode
126 * @param gizmoMode gizmo mode
127 */
129 this->gizmoMode = gizmoMode;
130 if (this->gizmoMode == GIZMOMODE_NONE) gizmoLastResultAvailable = false;
131 }
132
133 /**
134 * Update gizmo
135 * @param gizmoCenter GIZMO center
136 * @param transformations transformations used for rotation
137 */
138 void updateGizmo(const Vector3& gizmoCenter, const Transformations& transformations);
139
140 /**
141 * @return GIZMO object
142 */
144
145 /**
146 * Remove gizmo
147 */
148 void removeGizmo();
149
150 /**
151 * Determine movement on a plane given by 4 vertices
152 * @param mouseX current mouse X position
153 * @param mouseY current mouse Y position
154 * @param vertices 4 vertices that span a plane
155 * @param deltaMovement delta movement result
156 * @return success
157 */
158 bool determineGizmoMovement(int mouseX, int mouseY, vector<Vector3> vertices, Vector3& deltaMovement);
159
160 /**
161 * Determine GIZMO delta transformations
162 * @param mouseLastX last mouse X position
163 * @param mouseLastY last mouse Y position
164 * @param mouseX mouse X position
165 * @param mouseY mouse Y position
166 * @param deltaTranslation determined delta translation
167 * @param deltaRotation determined delta rotations
168 * @param deltaScale determined delta scale
169 */
170 bool determineGizmoDeltaTransformations(int mouseLastX, int mouseLastY, int mouseX, int mouseY, Vector3& deltaTranslation, Vector3& deltaRotation, Vector3& deltaScale);
171
172 /**
173 * Select GIZMO mode
174 * @param selectedEntity selected entity
175 * @param selectedEntityNode selected entity node
176 */
177 bool determineGizmoMode(Entity* selectedEntity, Node* selectedEntityNode);
178
179 /**
180 * Set gizmo rotation
181 * @param transformations transformations containing rotations
182 */
183 void setGizmoRotation(const Transformations& transformations);
184
185};
Engine main class.
Definition: Engine.h:122
TDME engine entity.
Definition: Entity.h:31
Object 3D to be used with engine class.
Definition: Object3D.h:60
Transformations which contain scale, rotations and translation.
Model node.
Definition: Node.h:31
3D vector 3 class
Definition: Vector3.h:22
Gizmo tool for views.
Definition: Gizmo.h:26
virtual ~Gizmo()
Destructor.
Definition: Gizmo.cpp:48
int32_t getGizmoTypeMask() const
Definition: Gizmo.h:88
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
void setEngine(Engine *engine)
Set engine.
Definition: Gizmo.h:81
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
Gizmo(Engine *engine, const string &id, int32_t gizmoTypeMask=GIZMOTYPE_TRANSLATE|GIZMOTYPE_ROTATE|GIZMOTYPE_SCALE)
Public constructor.
Definition: Gizmo.cpp:38
GizmoMode getGizmoMode() const
Definition: Gizmo.h:120
bool determineGizmoMode(Entity *selectedEntity, Node *selectedEntityNode)
Select GIZMO mode.
Definition: Gizmo.cpp:400
void setGizmoTypeMask(int gizmoTypeMask)
Set GIZMO type mask.
Definition: Gizmo.h:96