-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEditorControl.h
More file actions
106 lines (86 loc) · 2.48 KB
/
Copy pathEditorControl.h
File metadata and controls
106 lines (86 loc) · 2.48 KB
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
#pragma once
#include "../Export.h"
#include "Core/EventSubscriber.h"
#include "Game/Component/Component.h"
#include "Game/Vector.h"
#include "Game/WorldEvents.hpp"
#include "glm/gtc/quaternion.hpp"
#ifdef None
#undef None
#endif
#include <cstdint>
#include <set>
namespace sh::game
{
class Camera;
class LineRenderer;
}
namespace sh::editor
{
class EditorUI;
class EditorControl : public game::Component
{
COMPONENT(EditorControl, "Editor")
public:
SH_EDITOR_API EditorControl(game::GameObject& owner);
SH_EDITOR_API ~EditorControl();
SH_EDITOR_API void Awake() override;
SH_EDITOR_API void Update() override;
SH_EDITOR_API void LateUpdate() override;
SH_EDITOR_API void SetCamera(game::Camera* camera);
SH_EDITOR_API auto Serialize() const -> core::Json override;
SH_EDITOR_API static void SetSnap(bool bSnap);
SH_EDITOR_API static void SetSnapDistance(float dis);
SH_EDITOR_API static void SetSnapAngle(float degree);
SH_EDITOR_API static auto GetSnap() -> bool { return bSnap; }
SH_EDITOR_API static auto GetSnapDistance() -> float { return snapDis; }
SH_EDITOR_API static auto GetSnapAngle() -> float { return snapAngle; }
private:
enum class Mode
{
None, Move, Rotate, Scale
};
struct Snapshot
{
game::Vec3 position;
game::Vec3 scale;
glm::quat rotation;
};
void MoveControl();
void ScaleControl();
void RotateControl();
void BeginManipulation(Mode nextMode);
void CompleteManipulation(bool bCancel);
void ResetManipulationState();
auto HasTransformChanged() const -> bool;
auto CreateSnapshot() const -> Snapshot;
static auto GetCommandName(Mode mode) -> const char*;
static auto GetTransactionName(Mode mode) -> const char*;
private:
Mode mode = Mode::None;
enum class Axis
{
None, X, Y, Z
} axis = Axis::None;
PROPERTY(camera)
game::Camera* camera = nullptr;
PROPERTY(helper, core::PropertyOption::invisible)
game::LineRenderer* helper = nullptr;
EditorUI* ui = nullptr;
game::Vec3 posLast, scaleLast;
glm::quat quatLast;
game::Vec2 clickPos;
bool bParticipatingManipulation = false;
game::Vec3 up, right, forward;
core::EventSubscriber<game::events::WorldEvent> worldEventSubscriber;
static std::set<EditorControl*> controls;
static float snapDis;
static float snapAngle;
static bool bPivot;
static bool bUpdatedControls;
static bool bSnap;
static uint32_t activeManipulationCount;
static bool bOwnsHistoryTransaction;
static bool bCancelHistoryTransaction;
};
}//namespace