@@ -8,6 +8,11 @@ Editor::Editor() {
88 this ->m_inspectorObj = nullptr ;
99 this ->m_nWidth = 0 ;
1010 this ->m_nHeight = 0 ;
11+
12+ this ->m_bLocation = true ;
13+ this ->m_bRotation = false ;
14+ this ->m_bScale = false ;
15+ this ->m_guizmoOp = ImGuizmo::OPERATION::TRANSLATE;
1116}
1217
1318void Editor::Init (UINT nWidth, UINT nHeight) {
@@ -164,28 +169,55 @@ void Editor::Update() {
164169 ImGui::Begin (" Inspector" );
165170
166171 if (this ->m_inspectorObj ) {
172+ ImGui::Text (this ->m_inspectorObj ->m_name .c_str ());
173+ ImGui::Text (" Mode" );
174+ if (ImGui::RadioButton (" Location" , this ->m_bLocation )) {
175+ this ->m_bLocation = true ;
176+ this ->m_bRotation = false ;
177+ this ->m_bScale = false ;
178+ this ->m_guizmoOp = ImGuizmo::OPERATION::TRANSLATE;
179+ }
180+ ImGui::SameLine ();
181+ if (ImGui::RadioButton (" Rotation" , this ->m_bRotation )) {
182+ this ->m_bLocation = false ;
183+ this ->m_bRotation = true ;
184+ this ->m_bScale = false ;
185+ this ->m_guizmoOp = ImGuizmo::OPERATION::ROTATE;
186+ }
187+ ImGui::SameLine ();
188+ if (ImGui::RadioButton (" Scale" , this ->m_bScale )) {
189+ this ->m_bLocation = false ;
190+ this ->m_bRotation = false ;
191+ this ->m_bScale = true ;
192+ this ->m_guizmoOp = ImGuizmo::OPERATION::SCALE;
193+ }
194+
167195 Transform* transform = &this ->m_inspectorObj ->transform ;
168196
169- XMMATRIX worldMatrixXM = XMMatrixScaling (transform->scale .x , transform->scale .y , transform->scale .z ) *
170- XMMatrixRotationX (XMConvertToRadians (transform->rotation .x )) *
171- XMMatrixRotationY (XMConvertToRadians (transform->rotation .y )) *
172- XMMatrixRotationZ (XMConvertToRadians (transform->rotation .z )) *
173- XMMatrixTranslation (transform->location .x , transform->location .y , transform->location .z );
197+ XMMATRIX scaleMat = XMMatrixScaling (transform->scale .x , transform->scale .y , transform->scale .z );
198+ XMMATRIX rotMat = XMMatrixRotationRollPitchYaw (
199+ XMConvertToRadians (transform->rotation .x ),
200+ XMConvertToRadians (transform->rotation .y ),
201+ XMConvertToRadians (transform->rotation .z )
202+ );
203+ XMMATRIX transMat = XMMatrixTranslation (transform->location .x , transform->location .y , transform->location .z );
204+
205+ XMMATRIX worldMatrixXM = scaleMat * rotMat * transMat;
174206
175207 float worldMatrix[16 ];
176208 XMStoreFloat4x4 (reinterpret_cast <XMFLOAT4X4*>(worldMatrix), worldMatrixXM);
177209
178- ImGuizmo::Manipulate (viewMatrix, projectionMatrix, ImGuizmo::TRANSLATE , ImGuizmo::WORLD, worldMatrix);
210+ ImGuizmo::Manipulate (viewMatrix, projectionMatrix, this -> m_guizmoOp , ImGuizmo::WORLD, worldMatrix);
179211
180212 if (ImGuizmo::IsUsing ()) {
181213 float loc[3 ], rot[3 ], scale[3 ];
182214 ImGuizmo::DecomposeMatrixToComponents (worldMatrix, loc, rot, scale);
215+
183216 transform->location = Vector3{ loc[0 ], loc[1 ], loc[2 ] };
184- transform->rotation = Vector3{ rot[0 ], rot[1 ], rot[2 ] };
217+ transform->rotation = Vector3{ rot[0 ], rot[1 ], rot[2 ]};
185218 transform->scale = Vector3{ scale[0 ], scale[1 ], scale[2 ] };
186219 }
187220
188- ImGui::Text (this ->m_inspectorObj ->m_name .c_str ());
189221
190222 ImGui::Text (" Location" );
191223 ImGui::PushItemWidth (100 );
0 commit comments