Skip to content

Commit bc10b4c

Browse files
authored
Merge pull request #21 from adriengivry/feature/actor_picking_improvements
Actor picking debug mode and gizmo translation
2 parents cb9dfab + eb5e968 commit bc10b4c

18 files changed

Lines changed: 534 additions & 78 deletions

Resources/Editor/Models/Arrow.fbx

-34.4 KB
Binary file not shown.
36 KB
Binary file not shown.
15.4 KB
Binary file not shown.
15.8 KB
Binary file not shown.

Sources/Overload/OvEditor/OvEditor.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ xcopy "$(ProjectDir)Layout.ini" "$(SolutionDir)..\..\Build\$(ProjectName)\$(Conf
140140
<ClCompile Include="src\OvEditor\Core\EditorActions.cpp" />
141141
<ClCompile Include="src\OvEditor\Core\EditorRenderer.cpp" />
142142
<ClCompile Include="src\OvEditor\Core\EditorResources.cpp" />
143+
<ClCompile Include="src\OvEditor\Core\GizmoBehaviour.cpp" />
143144
<ClCompile Include="src\OvEditor\Core\PanelsManager.cpp" />
144145
<ClCompile Include="src\OvEditor\Core\ProjectHub.cpp" />
145146
<ClCompile Include="src\OvEditor\Panels\AssetBrowser.cpp" />
@@ -169,6 +170,7 @@ xcopy "$(ProjectDir)Layout.ini" "$(SolutionDir)..\..\Build\$(ProjectName)\$(Conf
169170
<ClInclude Include="include\OvEditor\Core\EditorActions.h" />
170171
<ClInclude Include="include\OvEditor\Core\EditorRenderer.h" />
171172
<ClInclude Include="include\OvEditor\Core\EditorResources.h" />
173+
<ClInclude Include="include\OvEditor\Core\GizmoBehaviour.h" />
172174
<ClInclude Include="include\OvEditor\Core\PanelsManager.h" />
173175
<ClInclude Include="include\OvEditor\Core\ProjectHub.h" />
174176
<ClInclude Include="include\OvEditor\Resources\RawShaders.h" />

Sources/Overload/OvEditor/OvEditor.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
<ClCompile Include="src\OvEditor\Resources\RawShaders.cpp">
9797
<Filter>Source Files</Filter>
9898
</ClCompile>
99+
<ClCompile Include="src\OvEditor\Core\GizmoBehaviour.cpp">
100+
<Filter>Source Files</Filter>
101+
</ClCompile>
99102
</ItemGroup>
100103
<ItemGroup>
101104
<ClInclude Include="include\OvEditor\Panels\AssetBrowser.h">
@@ -182,6 +185,9 @@
182185
<ClInclude Include="include\OvEditor\Resources\RawShaders.h">
183186
<Filter>Header Files</Filter>
184187
</ClInclude>
188+
<ClInclude Include="include\OvEditor\Core\GizmoBehaviour.h">
189+
<Filter>Header Files</Filter>
190+
</ClInclude>
185191
</ItemGroup>
186192
<ItemGroup>
187193
<None Include="include\OvEditor\Core\EditorActions.inl">

Sources/Overload/OvEditor/include/OvEditor/Core/CameraController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ namespace OvEditor::Core
7878
*/
7979
OvMaths::FVector3 GetPosition() const;
8080

81+
/**
82+
* Returns true if the right mouse click is being pressed
83+
*/
84+
bool IsRightMousePressed() const;
85+
8186
private:
8287
void HandleCameraXYMovement(float p_deltaTime);
8388
void HandleCameraZMovement(float p_deltaTime);

Sources/Overload/OvEditor/include/OvEditor/Core/EditorRenderer.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "OvEditor/Core/Context.h"
1919

20+
namespace OvEditor::Core { enum class EGizmoOperation; }
2021
namespace OvEditor::Panels { class AView; }
2122

2223
namespace OvEditor::Core
@@ -72,11 +73,13 @@ namespace OvEditor::Core
7273
void RenderCameras();
7374

7475
/**
75-
* Render a guizmo at position
76+
* Render a gizmo at position
7677
* @param p_position
7778
* @param p_rotation
79+
* @param p_operation
80+
* @param p_pickable (Determine the shader to use to render the gizmo)
7881
*/
79-
void RenderGuizmo(const OvMaths::FVector3& p_position, const OvMaths::FQuaternion& p_rotation);
82+
void RenderGizmo(const OvMaths::FVector3& p_position, const OvMaths::FQuaternion& p_rotation, OvEditor::Core::EGizmoOperation p_operation, bool p_pickable = false);
8083

8184
/**
8285
* Render a model to the stencil buffer
@@ -146,8 +149,9 @@ namespace OvEditor::Core
146149
OvCore::Resources::Material m_emptyMaterial;
147150
OvCore::Resources::Material m_defaultMaterial;
148151
OvCore::Resources::Material m_cameraMaterial;
149-
OvCore::Resources::Material m_guizmoArrowMaterial;
150-
OvCore::Resources::Material m_guizmoBallMaterial;
152+
OvCore::Resources::Material m_gizmoArrowMaterial;
153+
OvCore::Resources::Material m_gizmoBallMaterial;
154+
OvCore::Resources::Material m_gizmoPickingMaterial;
151155
OvCore::Resources::Material m_actorPickingMaterial;
152156
};
153157
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* @project: Overload
3+
* @author: Overload Tech.
4+
* @restrictions: This software may not be resold, redistributed or otherwise conveyed to a third party.
5+
*/
6+
7+
#pragma once
8+
9+
#include <OvEditor/Core/EditorActions.h>
10+
11+
namespace OvEditor::Core
12+
{
13+
enum class EGizmoOperation
14+
{
15+
TRANSLATE,
16+
ROTATE,
17+
SCALE
18+
};
19+
20+
/* Handle gizmo behaviours */
21+
class GizmoBehaviour
22+
{
23+
public:
24+
enum class EDirection
25+
{
26+
X,
27+
Y,
28+
Z
29+
};
30+
31+
/**
32+
* Starts the gizmo picking behaviour for the given target in the given direction
33+
* @param p_actor
34+
* @param p_cameraPosition
35+
* @param p_operation
36+
* @param p_direction
37+
*/
38+
void StartPicking(OvCore::ECS::Actor& p_target, const OvMaths::FVector3& p_cameraPosition, EGizmoOperation p_operation, EDirection p_direction);
39+
40+
/**
41+
* Stops the gizmo picking behaviour
42+
*/
43+
void StopPicking();
44+
45+
/**
46+
* Handle the current behaviour
47+
* @param p_viewMatrix
48+
* @param p_projectionMatrix
49+
* @param p_viewSize
50+
*/
51+
void ApplyOperation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize);
52+
53+
/**
54+
* Set the given mouse position as the current mouse position and update the previous mouse position
55+
* @param p_mousePosition
56+
*/
57+
void SetCurrentMouse(const OvMaths::FVector2& p_mousePosition);
58+
59+
/**
60+
* Returns true if the gizmo is currently picked
61+
*/
62+
bool IsPicking() const;
63+
64+
private:
65+
/**
66+
* Returns the global direction matching with the current m_direction
67+
*/
68+
OvMaths::FVector3 GetFakeDirection() const;
69+
70+
/**
71+
* Returns the actual direction of the target matching with the current m_direction
72+
* @param p_relative (If true, the direction depends on hierarchy)
73+
*/
74+
OvMaths::FVector3 GetRealDirection(bool p_relative = false) const;
75+
76+
/**
77+
* Returns the 3D vector of the arrow projected to the screen
78+
* @param p_viewMatrix
79+
* @param p_projectionMatrix
80+
* @param p_viewSize
81+
*/
82+
OvMaths::FVector2 GetScreenDirection(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const;
83+
84+
/**
85+
* Handle the translation behaviour
86+
* @param p_viewMatrix
87+
* @param p_projectionMatrix
88+
* @param p_viewSize
89+
*/
90+
void ApplyTranslation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const;
91+
92+
/**
93+
* Handle the rotation behaviour
94+
* @param p_viewMatrix
95+
* @param p_projectionMatrix
96+
* @param p_viewSize
97+
*/
98+
void ApplyRotation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const;
99+
100+
/**
101+
* Handle the scale behaviour
102+
* @param p_viewMatrix
103+
* @param p_projectionMatrix
104+
* @param p_viewSize
105+
*/
106+
void ApplyScale(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const;
107+
108+
private:
109+
bool m_firstMouse = true;
110+
float m_distanceToActor = 0.0f;
111+
OvCore::ECS::Actor* m_target;
112+
EGizmoOperation m_currentOperation;
113+
EDirection m_direction;
114+
OvMaths::FTransform m_originalTransform;
115+
OvMaths::FVector2 m_originMouse;
116+
OvMaths::FVector2 m_currentMouse;
117+
OvMaths::FVector2 m_screenDirection;
118+
};
119+
}

Sources/Overload/OvEditor/include/OvEditor/Panels/AViewControllable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace OvEditor::Panels
4040
*/
4141
OvEditor::Core::CameraController& GetCameraController();
4242

43-
private:
43+
protected:
4444
OvEditor::Core::CameraController m_cameraController;
4545
};
4646
}

0 commit comments

Comments
 (0)