-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInspectorScreen.cpp
More file actions
73 lines (62 loc) · 2.42 KB
/
InspectorScreen.cpp
File metadata and controls
73 lines (62 loc) · 2.42 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
#include "InspectorScreen.h"
#include "imgui.h"
#include "GameObjectManager.h"
#include "UIManager.h"
#include "AGameObject.h"
InspectorScreen::InspectorScreen() : AUIScreen("InspectorScreen")
{
}
InspectorScreen::~InspectorScreen()
{
}
void InspectorScreen::drawUI()
{
ImGui::Begin("Inspector Window");
ImGui::SetWindowPos(ImVec2(Window::WINDOW_WIDTH - 275, 20));
ImGui::SetWindowSize(ImVec2(250, Window::WINDOW_HEIGHT));
this->selectedObject = GameObjectManager::getInstance()->getSelectedObject();
if (this->selectedObject != NULL) {
String name = this->selectedObject->getName();
ImGui::Text("Selected Object: %s", name.c_str());
this->updateTransformDisplays();
bool enabled = this->selectedObject->isEnabled();
if (ImGui::Button("Delete", ImVec2(0, 0))) { this->deleteSelected(); }
if (ImGui::Checkbox("Enabled", &enabled)) { this->selectedObject->setEnabled(enabled); }
if (ImGui::InputFloat3("Position", this->positionDisplay, "%.4f")) { this->onTransformUpdate(); }
if (ImGui::InputFloat3("Rotation", this->rotationDisplay, "%.4f")) { this->onTransformUpdate(); }
if (ImGui::InputFloat3("Scale", this->scaleDisplay, "%.4f")) { this->onTransformUpdate(); }
}
else {
ImGui::Text("No object selected. Select an object first.");
}
ImGui::End();
}
void InspectorScreen::updateTransformDisplays()
{
Vector3D pos = this->selectedObject->getLocalPosition();
this->positionDisplay[0] = pos.getX();
this->positionDisplay[1] = pos.getY();
this->positionDisplay[2] = pos.getZ();
Vector3D rot = this->selectedObject->getLocalRotation();
this->rotationDisplay[0] = rot.getX();
this->rotationDisplay[1] = rot.getY();
this->rotationDisplay[2] = rot.getZ();
Vector3D scale = this->selectedObject->getLocalScale();
this->scaleDisplay[0] = scale.getX();
this->scaleDisplay[1] = scale.getY();
this->scaleDisplay[2] = scale.getZ();
}
void InspectorScreen::deleteSelected()
{
if (this->selectedObject == NULL)
return;
GameObjectManager::getInstance()->deleteObject(this->selectedObject);
}
void InspectorScreen::onTransformUpdate()
{
if (this->selectedObject != NULL) {
this->selectedObject->setPosition(Vector3D(this->positionDisplay[0], this->positionDisplay[1], this->positionDisplay[2]));
this->selectedObject->setRotation(Vector3D(this->rotationDisplay[0], this->rotationDisplay[1], this->rotationDisplay[2]));
this->selectedObject->setScale(Vector3D(this->scaleDisplay[0], this->scaleDisplay[1], this->scaleDisplay[2]));
}
}