mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-07-08 14:37:09 -04:00
Editor Snap to Ground works
This commit is contained in:
@@ -82,21 +82,28 @@ void Gizmo::Translate() {
|
||||
_selected->Pos->x = (cameras[0].pos[0] + _ray.x * PickDistance) + _cursorOffset.x;
|
||||
_selected->Pos->y = (cameras[0].pos[1] + _ray.y * PickDistance) + _cursorOffset.y;
|
||||
_selected->Pos->z = (cameras[0].pos[2] + _ray.z * PickDistance) + _cursorOffset.z;
|
||||
if (CVarGetInteger("gEditorSnapToGround", false) == true) {
|
||||
_selected->Pos->y = SnapToSurface(_selected->Pos);
|
||||
}
|
||||
printf("TEST %f\n", _selected->Pos->y);
|
||||
break;
|
||||
case GizmoHandle::X_Axis:
|
||||
_selected->Pos->x = (cameras[0].pos[0] + _ray.x * length) + _cursorOffset.x;
|
||||
if (CVarGetInteger("gEditorSnapToGround", false) == true) {
|
||||
_selected->Pos->y = SnapToSurface(_selected->Pos);
|
||||
}
|
||||
break;
|
||||
case GizmoHandle::Y_Axis:
|
||||
_selected->Pos->y = (cameras[0].pos[1] + _ray.y * length) + _cursorOffset.y;
|
||||
break;
|
||||
case GizmoHandle::Z_Axis:
|
||||
_selected->Pos->z = (cameras[0].pos[2] + _ray.z * length) + _cursorOffset.z;
|
||||
if (CVarGetInteger("gEditorSnapToGround", false) == true) {
|
||||
_selected->Pos->y = SnapToSurface(_selected->Pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (CVarGetInteger("gEditorSnapToGround", false) == true) {
|
||||
_selected->Pos->y = spawn_actor_on_surface(_selected->Pos->x, 2000.0f, _selected->Pos->z);
|
||||
}
|
||||
|
||||
Pos = FVector(
|
||||
_selected->Pos->x,
|
||||
@@ -106,6 +113,17 @@ void Gizmo::Translate() {
|
||||
}
|
||||
}
|
||||
|
||||
f32 Gizmo::SnapToSurface(FVector* pos) {
|
||||
float y;
|
||||
y = spawn_actor_on_surface(pos->x, 2000.0f, pos->z);
|
||||
|
||||
if (y == 3000.0f || y == -3000.0f) {
|
||||
y = pos->y;
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
// void Gizmo::Rotate() {
|
||||
|
||||
// }
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
void Enable(GameObject* object, Ray ray);
|
||||
void Translate();
|
||||
void DrawHandles();
|
||||
f32 SnapToSurface(FVector* pos);
|
||||
|
||||
|
||||
bool Enabled;
|
||||
|
||||
@@ -23,4 +23,4 @@ namespace Editor {
|
||||
// Handle button click (example)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,5 @@ namespace Editor {
|
||||
if (ImGui::Button("Click Me")) {
|
||||
// Handle button click (example)
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-1
@@ -23,8 +23,29 @@ namespace Editor {
|
||||
|
||||
void ToolsWindow::DrawElement() {
|
||||
static bool toggleState = false;
|
||||
static int selectedTool = 0; // 0: Move, 1: Rotate, 2: Scale
|
||||
|
||||
// Function to check and highlight the selected button
|
||||
auto ToolButton = [&](const char* label, int id) {
|
||||
bool isSelected = (selectedTool == id);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, isSelected ? ImVec4(0.2f, 0.8f, 0.2f, 1.0f) : ImVec4(0.8f, 0.2f, 0.2f, 1.0f));
|
||||
|
||||
if (ImGui::Button(label, ImVec2(125, 25))) {
|
||||
selectedTool = id; // Set the selected tool
|
||||
}
|
||||
|
||||
ImGui::PopStyleColor();
|
||||
};
|
||||
|
||||
// Draw buttons
|
||||
ToolButton("Move", 0);
|
||||
ImGui::SameLine();
|
||||
ToolButton("Rotate", 1);
|
||||
ImGui::SameLine();
|
||||
ToolButton("Scale", 2);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, toggleState ? ImVec4(0.2f, 0.8f, 0.2f, 1.0f) : ImVec4(0.8f, 0.2f, 0.2f, 1.0f));
|
||||
if (ImGui::Button(toggleState ? "v" : "v", ImVec2(50, 25))) {
|
||||
if (ImGui::Button(toggleState ? "SNAP TO GROUND" : "SNAP TO GROUND", ImVec2(125, 25))) {
|
||||
toggleState = !toggleState;
|
||||
|
||||
CVarSetInteger("gEditorSnapToGround", toggleState);
|
||||
|
||||
Reference in New Issue
Block a user