@@ -5,9 +5,12 @@ Editor* Editor::m_instance;
55Editor::Editor () {
66 this ->m_bMenuOpen = false ;
77 this ->m_sceneMgr = nullptr ;
8+ this ->m_inspectorObj = nullptr ;
9+ this ->m_nWidth = 0 ;
10+ this ->m_nHeight = 0 ;
811}
912
10- void Editor::Init () {
13+ void Editor::Init (UINT nWidth, UINT nHeight ) {
1114 this ->m_sceneMgr = SceneManager::GetInstance ();
1215
1316 ImGuiIO& io = ImGui::GetIO ();
@@ -98,6 +101,9 @@ void Editor::Init() {
98101 style->GrabRounding = 3 ;
99102 style->LogSliderDeadzone = 4 ;
100103 style->TabRounding = 4 ;
104+
105+ this ->m_nWidth = nWidth;
106+ this ->m_nHeight = nHeight;
101107}
102108
103109void Editor::Update () {
@@ -122,14 +128,111 @@ void Editor::Update() {
122128 ImGui::EndMainMenuBar ();
123129
124130 if (this ->m_sceneMgr ) {
131+
132+ float identityMatrix[16 ] = {
133+ 1 .0f , 0 .0f , 0 .0f , 0 .0f ,
134+ 0 .0f , 1 .0f , 0 .0f , 0 .0f ,
135+ 0 .0f , 0 .0f , 1 .0f , 0 .0f ,
136+ 0 .0f , 0 .0f , 0 .0f , 1 .0f // Posición del cubo (X=1.0f, Y=1.0f, Z=0.0f)
137+ };
138+
139+ ImGuizmo::Enable (true );
140+
125141 ImGui::SetNextWindowSize (ImVec2{ 300 .f , 600 .f });
126142 ImGui::Begin (" Scene" );
127143
128144 Scene* scene = this ->m_sceneMgr ->GetCurrentScene ();
145+ Camera* camera = scene->GetCurrentCamera ();
146+
147+ Transform cameraTransform = camera->transform ;
148+
149+ XMVECTOR eye = XMVectorSet (
150+ cameraTransform.location .x ,
151+ cameraTransform.location .y ,
152+ cameraTransform.location .z ,
153+ 1 .0f
154+ );
155+
156+ float pitch = XMConvertToRadians (cameraTransform.rotation .x );
157+ float yaw = XMConvertToRadians (cameraTransform.rotation .y );
158+
159+ XMVECTOR forward = XMVectorSet (
160+ cosf (pitch) * sinf (yaw),
161+ -sinf (pitch),
162+ -cosf (pitch) * cosf (yaw),
163+ 0 .0f
164+ );
165+
166+ XMVECTOR at = XMVectorAdd (eye, forward);
167+
168+ XMVECTOR up = XMVectorSet (0 .0f , 1 .0f , 0 .0f , 0 .0f );
169+
170+ this ->m_wvp .View = (XMMatrixLookAtLH (eye, at, up));
171+ this ->m_wvp .World = (XMMatrixIdentity ());
172+ this ->m_wvp .Projection = (XMMatrixPerspectiveFovLH (XMConvertToRadians (70 .f ), static_cast <float >(this ->m_nWidth ) / static_cast <float >(this ->m_nHeight ), 0 .01f , 3000 .f ));
173+
174+ /* Convert our View Projection matrices to a length 16 array of floats */
175+ float viewMatrix[16 ];
176+ float projectionMatrix[16 ];
177+ XMStoreFloat4x4 (reinterpret_cast <XMFLOAT4X4*>(viewMatrix), this ->m_wvp .View );
178+ XMStoreFloat4x4 (reinterpret_cast <XMFLOAT4X4*>(projectionMatrix), this ->m_wvp .Projection );
179+
180+ ImGuizmo::DrawGrid (viewMatrix, projectionMatrix, identityMatrix, 100 );
181+
182+ float worldMatrix[16 ];
183+
184+ float objectMatrix[16 ] = {
185+ 1 .0f , 0 .0f , 0 .0f , 0 .0f ,
186+ 0 .0f , 1 .0f , 0 .0f , 0 .0f ,
187+ 0 .0f , 0 .0f , 1 .0f , 0 .0f ,
188+ 1 .0f , 1 .0f , 0 .0f , 1 .0f // Posición del cubo (X=1.0f, Y=1.0f, Z=0.0f)
189+ };
129190
130191 for (std::pair<std::string, GameObject*> object : scene->m_gameObjects ) {
131- if (ImGui::Button (object.second ->m_name .c_str ())) {}
192+ if (ImGui::Button (object.second ->m_name .c_str ())) {
193+ this ->m_inspectorObj = object.second ;
194+ }
195+ }
196+
197+ ImGui::SetNextWindowSize (ImVec2{ 300 .f , 600 .f });
198+ ImGui::SetNextWindowPos (ImVec2{ 1575 ,180 });
199+ ImGui::Begin (" Inspector" );
200+ if (this ->m_inspectorObj ) {
201+ Transform* pObjTransform = &this ->m_inspectorObj ->transform ;
202+
203+ this ->m_wvp .World *= (XMMatrixRotationX (XMConvertToRadians (pObjTransform->rotation .x )));
204+ this ->m_wvp .World *= (XMMatrixRotationY (XMConvertToRadians (pObjTransform->rotation .y )));
205+ this ->m_wvp .World *= (XMMatrixRotationZ (XMConvertToRadians (pObjTransform->rotation .z )));
206+ this ->m_wvp .World *= (XMMatrixTranslation (
207+ pObjTransform->location .x ,
208+ pObjTransform->location .y ,
209+ pObjTransform->location .z ));
210+
211+ this ->m_wvp .World = XMMatrixTranspose (this ->m_wvp .World );
212+ XMStoreFloat4x4 (reinterpret_cast <XMFLOAT4X4*>(worldMatrix), this ->m_wvp .World );
213+
214+ ImGuizmo::Manipulate (viewMatrix, projectionMatrix, ImGuizmo::OPERATION::TRANSLATE, ImGuizmo::MODE::WORLD, worldMatrix);
215+
216+ ImGui::Text (this ->m_inspectorObj ->m_name .c_str ());
217+ ImGui::Text (" Location" );
218+ ImGui::PushItemWidth (100 );
219+
220+ ImGui::InputFloat (" ##X" , &pObjTransform->location .x , 0 .1f , 1 .f , " %.2f" );
221+ ImGui::InputFloat (" ##Y" , &pObjTransform->location .y , 0 .1f , 1 .f , " %.2f" );
222+ ImGui::InputFloat (" ##Z" , &pObjTransform->location .z , 0 .1f , 1 .f , " %.2f" );
223+ ImGui::PopItemWidth ();
224+ ImGui::Text (" Rotation" );
225+ ImGui::PushItemWidth (100 );
226+
227+ ImGui::InputFloat (" ##X" , &pObjTransform->rotation .x , 5 .f , 10 .f , " %.2f" );
228+ ImGui::InputFloat (" ##Y" , &pObjTransform->rotation .y , 5 .f , 10 .f , " %.2f" );
229+ ImGui::InputFloat (" ##Z" , &pObjTransform->rotation .z , 5 .f , 10 .f , " %.2f" );
230+ ImGui::PopItemWidth ();
231+ }
232+ else {
233+ ImGui::Text (" Select an object..." );
132234 }
235+ ImGui::End ();
133236
134237 ImGui::End ();
135238 }
0 commit comments