Polyphase Game Engine
Loading...
Searching...
No Matches
TransformSnap.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "Maths.h"
6
7#include <vector>
8
9class Camera3D;
10class Node;
11
12enum class SnapMode : uint8_t
13{
14 Increment,
15 Vertex,
16 Edge,
17 Face,
18
19 Count
20};
21
22// Cursor-locked (G/R/S) transforms are incremental, so snapping works on the
23// raw value accumulated since the drag began and applies the difference.
24struct TransformSnapAccum
25{
26 glm::vec3 mRawTranslate = {};
27 glm::vec3 mAppliedTranslate = {};
28 glm::vec2 mRawTranslate2D = {};
29 glm::vec2 mRawSize2D = {};
30 float mRawAngle = 0.0f;
31 float mAppliedAngle = 0.0f;
32 float mRawScale = 0.0f;
33 float mAppliedScale = 0.0f;
34 bool mWasActive = false;
35
36 void Reset() { *this = TransformSnapAccum(); }
37};
38
39namespace TransformSnap
40{
41 // Snapping preference XOR Shift held.
42 bool IsActive();
43 SnapMode GetMode();
44 void ToggleEnabled();
45 void CycleMode();
46
47 // Speed multiplier for cursor-locked transforms (normal vs Control held).
48 float GetModalSpeedMultiplier();
49 // Mouse scale for ImGuizmo handle drags. 1.0 unless Control is held.
50 float GetGizmoPrecisionScale();
51
52 float GetTranslateIncrement();
53 float GetRotateIncrement(); // degrees
54 float GetScaleIncrement();
55 float GetWidgetIncrement(); // pixels
56
57 // Rounds to the nearest multiple. increment <= 0 passes the value through.
58 float SnapValue(float value, float increment);
59 glm::vec2 SnapValue(glm::vec2 value, float increment);
60 glm::vec3 SnapValue(glm::vec3 value, float increment);
61
62 void BeginDrag();
63 void EndDrag();
64
65 // Vertex / Edge / Face: finds the snap target on the scene geometry behind
66 // rawPos (as seen from camera). Nodes in 'excluded' and their descendants
67 // are ignored. Returns false when nothing qualifies; keep rawPos then.
68 bool SnapToSurface(Camera3D* camera, const std::vector<Node*>& excluded, glm::vec3 rawPos, glm::vec3& outPos);
69
70 void DrawIndicator();
71}
72
73#endif
Definition Camera3d.h:12
Definition Node.h:67
Definition Vertex.h:20