载入中...
搜索中...
未找到
TransformGizmo.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include <glm/mat4x4.hpp>
7#include <glm/vec3.hpp>
8
9namespace eve::editor {
10
17public:
19
20 void setMode(const std::string &mode);
21 std::string getMode() const { return mode_; }
22
23 void setSpace(const std::string &space);
24 std::string getSpace() const { return space_; }
25
26 void setSize(float size);
27 float getSize() const { return size_; }
28
29 void setPosition(float x, float y, float z);
30 float getPositionX() const { return position_.x; }
31 float getPositionY() const { return position_.y; }
32 float getPositionZ() const { return position_.z; }
33
35 void setRotationEuler(float x, float y, float z);
36 float getRotationX() const { return rotation_.x; }
37 float getRotationY() const { return rotation_.y; }
38 float getRotationZ() const { return rotation_.z; }
39
40 void setScale(float x, float y, float z);
41 float getScaleX() const { return scale_.x; }
42 float getScaleY() const { return scale_.y; }
43 float getScaleZ() const { return scale_.z; }
44
46 void setBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
47 float getBoundsMinX() const { return boundsMin_.x; }
48 float getBoundsMinY() const { return boundsMin_.y; }
49 float getBoundsMinZ() const { return boundsMin_.z; }
50 float getBoundsMaxX() const { return boundsMax_.x; }
51 float getBoundsMaxY() const { return boundsMax_.y; }
52 float getBoundsMaxZ() const { return boundsMax_.z; }
53
54 void setSnapTranslate(float x, float y, float z);
55 void setSnapRotate(float degrees);
56 void setSnapScale(float s);
57 float getSnapTranslateX() const { return snapTranslate_.x; }
58 float getSnapTranslateY() const { return snapTranslate_.y; }
59 float getSnapTranslateZ() const { return snapTranslate_.z; }
60 float getSnapRotate() const { return snapRotateDeg_; }
61 float getSnapScale() const { return snapScale_; }
62
64 float getMatrix(int index) const;
65
70 std::string pick(float ox, float oy, float oz, float dx, float dy, float dz);
71
72 bool beginDrag(const std::string &axis, float ox, float oy, float oz, float dx, float dy,
73 float dz);
74 bool updateDrag(float ox, float oy, float oz, float dx, float dy, float dz);
75 void endDrag();
76
77 bool isDragging() const { return dragging_; }
78 bool isHovered() const { return !hoverAxis_.empty(); }
79 std::string getActiveAxis() const { return activeAxis_; }
80 std::string getHoverAxis() const { return hoverAxis_; }
81
83 void rebuildParts();
84
85 int getPartCount() const { return static_cast<int>(parts_.size()); }
86 std::string getPartKind(int index) const;
87 std::string getPartAxis(int index) const;
88 float getPartColorR(int index) const;
89 float getPartColorG(int index) const;
90 float getPartColorB(int index) const;
91 float getPartColorA(int index) const;
92 float getPartOriginX(int index) const;
93 float getPartOriginY(int index) const;
94 float getPartOriginZ(int index) const;
95 float getPartDirX(int index) const;
96 float getPartDirY(int index) const;
97 float getPartDirZ(int index) const;
98 float getPartLength(int index) const;
99 float getPartRadius(int index) const;
100
101private:
102 struct Part {
103 std::string kind; // axis | plane | ring | box | center | handle
104 std::string axis;
105 glm::vec3 origin{0.f};
106 glm::vec3 dir{1.f, 0.f, 0.f};
107 float length = 1.f;
108 float radius = 0.05f;
109 glm::vec4 color{1.f, 0.f, 0.f, 1.f};
110 };
111
112 glm::mat4 localRotationMatrix() const;
113 glm::mat4 worldMatrix() const;
114 glm::vec3 axisWorld(int axis) const; // 0=x,1=y,2=z
115 void colorForAxis(const std::string &axis, glm::vec4 &out) const;
116
117 float hitAxis(const glm::vec3 &ro, const glm::vec3 &rd, int axisIndex, float &outT) const;
118 float hitPlane(const glm::vec3 &ro, const glm::vec3 &rd, int planeMask, float &outT) const;
119 float hitRing(const glm::vec3 &ro, const glm::vec3 &rd, int axisIndex, float &outT) const;
120 float hitBoundHandle(const glm::vec3 &ro, const glm::vec3 &rd, int handle, float &outT) const;
121
122 glm::vec3 projectToDragPlane(const glm::vec3 &ro, const glm::vec3 &rd) const;
123 void applySnapTranslate(glm::vec3 &v) const;
124 float applySnapRotate(float radians) const;
125 float applySnapScale(float s) const;
126
127 bool validPart(int index) const;
128
129 std::string mode_ = "translate";
130 std::string space_ = "world";
131 float size_ = 1.f;
132
133 glm::vec3 position_{0.f};
134 glm::vec3 rotation_{0.f};
135 glm::vec3 scale_{1.f};
136 glm::vec3 boundsMin_{-0.5f};
137 glm::vec3 boundsMax_{0.5f};
138
139 glm::vec3 snapTranslate_{0.f};
140 float snapRotateDeg_ = 0.f;
141 float snapScale_ = 0.f;
142
143 bool dragging_ = false;
144 std::string activeAxis_;
145 std::string hoverAxis_;
146
147 glm::vec3 dragStartPos_{0.f};
148 glm::vec3 dragStartRot_{0.f};
149 glm::vec3 dragStartScale_{0.f};
150 glm::vec3 dragStartHit_{0.f};
151 glm::vec3 dragPlaneNormal_{0.f, 1.f, 0.f};
152 glm::vec3 dragAxisDir_{1.f, 0.f, 0.f};
153
154 std::vector<Part> parts_;
155};
156
157} // namespace eve::editor
float degrees
Definition CardTypes.cpp:33
Tok kind
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int v
image::ImageData::Colorf color
V3 dir
Definition TreeMesh.cpp:121
uint32_t s
Definition Weather.cpp:28
3D transform gizmo (Three.js TransformControls + ImGuizmo style). Owns TRS + optional local bounds; i...
float getPartDirY(int index) const
std::string getHoverAxis() const
void setSnapRotate(float degrees)
float getPartColorR(int index) const
void rebuildParts()
Rebuild draw parts for current mode/space (call after TRS/mode change).
float getPartDirX(int index) const
std::string pick(float ox, float oy, float oz, float dx, float dy, float dz)
Ray pick against active mode handles. Returns axis id: "x"|"y"|"z"|"xy"|"yz"|"xz"|"xyz"|"bx"|…|"bz"|"...
float getPartDirZ(int index) const
std::string getPartKind(int index) const
std::string getMode() const
float getPartRadius(int index) const
float getMatrix(int index) const
Column-major matrix element 0..15 of current TRS.
float getPartColorG(int index) const
void setBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Local AABB extents for bound mode (relative to object origin).
float getPartColorB(int index) const
bool beginDrag(const std::string &axis, float ox, float oy, float oz, float dx, float dy, float dz)
float getPartOriginY(int index) const
void setSnapTranslate(float x, float y, float z)
std::string getActiveAxis() const
float getPartLength(int index) const
void setPosition(float x, float y, float z)
float getPartColorA(int index) const
bool updateDrag(float ox, float oy, float oz, float dx, float dy, float dz)
float getPartOriginX(int index) const
void setRotationEuler(float x, float y, float z)
Euler radians, XYZ order.
void setMode(const std::string &mode)
std::string getSpace() const
void setScale(float x, float y, float z)
std::string getPartAxis(int index) const
float getPartOriginZ(int index) const
void setSpace(const std::string &space)