Skip to content

Commit

Permalink
Collider AABBs, debug camera inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
angryzor committed Dec 2, 2024
1 parent aef16ea commit a8b950f
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.1.58
* Added panel that allows direct editing of debug camera parameters.
* Selection box now also works for box, cylinder and capsule colliders.


# v0.1.57
* Fixed a bug in object placement introduced in the previous version.

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.28)
# DevTools
project(devtools VERSION 0.1.57
project(devtools VERSION 0.1.58
DESCRIPTION "Hedgehog Engine 2 DevTools"
LANGUAGES CXX)

Expand Down
2 changes: 1 addition & 1 deletion sdks/miller-sdk
2 changes: 1 addition & 1 deletion sdks/rangers-sdk
Submodule rangers-sdk updated 1 files
+1 −1 rangers-api
2 changes: 1 addition & 1 deletion sdks/wars-sdk
28 changes: 28 additions & 0 deletions src/ui/ToolBar.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ToolBar.h"
#include <debug-rendering/GOCVisualDebugDrawRenderer.h>
#include <rip/schemas/hedgeset.h>
#include <ui/common/Editors/Basic.h>
#include "Desktop.h"
#include "SettingsManager.h"
#include "GlobalSettings.h"
Expand Down Expand Up @@ -188,11 +189,38 @@ void ToolBar::Render() {
bool tempDebugCameraLocked{ debugCameraLocked };

ImGui::Checkbox("Lock debug camera position", &tempDebugCameraLocked);
ImGui::SameLine();

if (debugCameraLocked != tempDebugCameraLocked)
debugCameraMgr->GetCamera()->SetLocked(tempDebugCameraLocked);

static bool showCameraInfo{};
ImGui::Checkbox("Show camera information", &showCameraInfo);
ImGui::SameLine();

if (showCameraInfo) {
#ifdef DEVTOOLS_TARGET_SDK_wars
auto& camCtrl = *((hh::game::FreeCameraController*)&*debugCameraMgr->GetCamera()->controller);
#else
auto& camCtrl = *((hh::game::DefaultFreeCameraController*)&*debugCameraMgr->GetCamera()->controller)->padController;
#endif
if (ImGui::Begin("Debug camera options")) {
Editor("Origin / reset position", camCtrl.unk3.camera.origin);
Editor("Position offset", camCtrl.unk3.camera.position);
Editor("Yaw", camCtrl.unk3.camera.yaw);
Editor("Pitch", camCtrl.unk3.camera.pitch);
Editor("Roll", camCtrl.unk3.camera.roll);
Editor("Zoom", camCtrl.unk3.camera.zoom);
Editor("Near clip", camCtrl.unk3.viewport.nearClip);
Editor("Far clip", camCtrl.unk3.viewport.farClip);
Editor("Field of view", camCtrl.unk3.viewport.fov);
ImGui::Separator();
Editor("Current speed", camCtrl.currentSpeed);
Editor("Speed options", camCtrl.speedOptions);
Editor("Current speed option index", camCtrl.currentSpeedOptionIdx);
}
ImGui::End();
}
}

ImGui::Checkbox("Render debug visuals", &GOCVisualDebugDrawRenderer::instance->enabled);
Expand Down
133 changes: 106 additions & 27 deletions src/utilities/BoundingBoxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

bool AddToAabb(hh::game::GameObject* object, csl::geom::Aabb& aabb) {
if (auto* visual = object->GetComponent<hh::gfx::GOCVisualTransformed>()) {
aabb.min.x() = std::fminf(aabb.min.x(), visual->transformedAabb.min.x());
aabb.min.y() = std::fminf(aabb.min.y(), visual->transformedAabb.min.y());
aabb.min.z() = std::fminf(aabb.min.z(), visual->transformedAabb.min.z());
aabb.max.x() = std::fmaxf(aabb.max.x(), visual->transformedAabb.max.x());
aabb.max.y() = std::fmaxf(aabb.max.y(), visual->transformedAabb.max.y());
aabb.max.z() = std::fmaxf(aabb.max.z(), visual->transformedAabb.max.z());
AddAabb(aabb, visual->transformedAabb);
return true;
}

Expand All @@ -16,45 +11,46 @@ bool AddToAabb(hh::game::GameObject* object, csl::geom::Aabb& aabb) {

for (auto* component : object->components) {
if (component->pStaticClass == hh::physics::GOCSphereCollider::GetClass()) {
auto* coll = static_cast<hh::physics::GOCSphereCollider*>(component);
tempAabb.min = coll->GetWorldTransform() * Eigen::Vector3f{ -coll->radius, -coll->radius, -coll->radius };
tempAabb.max = coll->GetWorldTransform() * Eigen::Vector3f{ coll->radius, coll->radius, coll->radius };
tempAabb = CalcAabb(*static_cast<hh::physics::GOCSphereCollider*>(component));
colliderCount++;
if (colliderCount > 1)
break;
}
if (component->pStaticClass == hh::physics::GOCBoxCollider::GetClass()) {
tempAabb = CalcAabb(*static_cast<hh::physics::GOCBoxCollider*>(component));
colliderCount++;
if (colliderCount > 1)
break;
}
if (component->pStaticClass == hh::physics::GOCCylinderCollider::GetClass()) {
tempAabb = CalcAabb(*static_cast<hh::physics::GOCCylinderCollider*>(component));
colliderCount++;
if (colliderCount > 1)
break;
}
if (component->pStaticClass == hh::physics::GOCCapsuleCollider::GetClass()) {
tempAabb = CalcAabb(*static_cast<hh::physics::GOCCapsuleCollider*>(component));
colliderCount++;
if (colliderCount > 1)
break;
}
}

if (colliderCount == 1) {
aabb.min.x() = std::fminf(aabb.min.x(), tempAabb.min.x());
aabb.min.y() = std::fminf(aabb.min.y(), tempAabb.min.y());
aabb.min.z() = std::fminf(aabb.min.z(), tempAabb.min.z());
aabb.max.x() = std::fmaxf(aabb.max.x(), tempAabb.max.x());
aabb.max.y() = std::fmaxf(aabb.max.y(), tempAabb.max.y());
aabb.max.z() = std::fmaxf(aabb.max.z(), tempAabb.max.z());
AddAabb(aabb, tempAabb);
return true;
}

if (auto* gocTransform = object->GetComponent<hh::game::GOCTransform>()) {
aabb.min.x() = std::fminf(aabb.min.x(), gocTransform->GetFrame().fullTransform.position.x());
aabb.min.y() = std::fminf(aabb.min.y(), gocTransform->GetFrame().fullTransform.position.y());
aabb.min.z() = std::fminf(aabb.min.z(), gocTransform->GetFrame().fullTransform.position.z());
aabb.max.x() = std::fmaxf(aabb.max.x(), gocTransform->GetFrame().fullTransform.position.x());
aabb.max.y() = std::fmaxf(aabb.max.y(), gocTransform->GetFrame().fullTransform.position.y());
aabb.max.z() = std::fmaxf(aabb.max.z(), gocTransform->GetFrame().fullTransform.position.z());
aabb.AddPoint(gocTransform->GetFrame().fullTransform.position);
return true;
}

return false;
}

bool AddToAabb(hh::game::ObjectData* objectData, csl::geom::Aabb& aabb) {
aabb.min.x() = std::fminf(aabb.min.x(), objectData->transform.position.x());
aabb.min.y() = std::fminf(aabb.min.y(), objectData->transform.position.y());
aabb.min.z() = std::fminf(aabb.min.z(), objectData->transform.position.z());
aabb.max.x() = std::fmaxf(aabb.max.x(), objectData->transform.position.x());
aabb.max.y() = std::fmaxf(aabb.max.y(), objectData->transform.position.y());
aabb.max.z() = std::fmaxf(aabb.max.z(), objectData->transform.position.z());
aabb.AddPoint(objectData->transform.position);
return true;
}

Expand Down Expand Up @@ -139,3 +135,86 @@ csl::geom::Aabb CalcAabb(const csl::geom::Obb& obb)

return res;
}

csl::geom::Aabb CalcAabb(const hh::physics::GOCSphereCollider& coll) {
auto tf = coll.GetWorldTransform();

Eigen::Matrix3f rot;
Eigen::Matrix3f scale;

tf.computeRotationScaling(&rot, &scale);

Eigen::Affine3f transform{};
transform.fromPositionOrientationScale(tf.translation(), Eigen::Quaternionf::Identity(), scale.diagonal());

return {
transform * Eigen::Vector3f{ -coll.radius, -coll.radius, -coll.radius },
transform * Eigen::Vector3f{ coll.radius, coll.radius, coll.radius },
};
}

csl::geom::Aabb CalcAabb(const hh::physics::GOCBoxCollider& coll) {
auto tf = coll.GetWorldTransform();

csl::math::Vector3 corners[8]{
tf * csl::math::Vector3{ -coll.dimensions.x(), -coll.dimensions.y(), -coll.dimensions.z() },
tf * csl::math::Vector3{ -coll.dimensions.x(), -coll.dimensions.y(), coll.dimensions.z() },
tf * csl::math::Vector3{ -coll.dimensions.x(), coll.dimensions.y(), -coll.dimensions.z() },
tf * csl::math::Vector3{ coll.dimensions.x(), -coll.dimensions.y(), -coll.dimensions.z() },
tf * csl::math::Vector3{ coll.dimensions.x(), coll.dimensions.y(), -coll.dimensions.z() },
tf * csl::math::Vector3{ coll.dimensions.x(), -coll.dimensions.y(), coll.dimensions.z() },
tf * csl::math::Vector3{ -coll.dimensions.x(), coll.dimensions.y(), coll.dimensions.z() },
tf * csl::math::Vector3{ coll.dimensions.x(), coll.dimensions.y(), coll.dimensions.z() },
};

csl::geom::Aabb res{ { INFINITY, INFINITY, INFINITY }, { -INFINITY, -INFINITY, -INFINITY } };

for (size_t i = 0; i < 8; i++)
res.AddPoint(corners[i]);

return res;
}

csl::geom::Aabb CalcAabb(const hh::physics::GOCCylinderCollider& coll) {
auto tf = coll.GetWorldTransform();

csl::math::Vector3 corners[8]{
tf * csl::math::Vector3{ -coll.radius, -coll.halfHeight, -coll.radius },
tf * csl::math::Vector3{ -coll.radius, -coll.halfHeight, coll.radius },
tf * csl::math::Vector3{ -coll.radius, coll.halfHeight, -coll.radius },
tf * csl::math::Vector3{ coll.radius, -coll.halfHeight, -coll.radius },
tf * csl::math::Vector3{ coll.radius, coll.halfHeight, -coll.radius },
tf * csl::math::Vector3{ coll.radius, -coll.halfHeight, coll.radius },
tf * csl::math::Vector3{ -coll.radius, coll.halfHeight, coll.radius },
tf * csl::math::Vector3{ coll.radius, coll.halfHeight, coll.radius },
};

csl::geom::Aabb res{ { INFINITY, INFINITY, INFINITY }, { -INFINITY, -INFINITY, -INFINITY } };

for (size_t i = 0; i < 8; i++)
res.AddPoint(corners[i]);

return res;
}

csl::geom::Aabb CalcAabb(const hh::physics::GOCCapsuleCollider& coll) {
auto tf = coll.GetWorldTransform();

csl::math::Vector3 corners[8]{
tf * csl::math::Vector3{ -coll.radius, -(coll.halfHeight + coll.radius), -coll.radius },
tf * csl::math::Vector3{ -coll.radius, -(coll.halfHeight + coll.radius), coll.radius },
tf * csl::math::Vector3{ -coll.radius, (coll.halfHeight + coll.radius), -coll.radius },
tf * csl::math::Vector3{ coll.radius, -(coll.halfHeight + coll.radius), -coll.radius },
tf * csl::math::Vector3{ coll.radius, (coll.halfHeight + coll.radius), -coll.radius },
tf * csl::math::Vector3{ coll.radius, -(coll.halfHeight + coll.radius), coll.radius },
tf * csl::math::Vector3{ -coll.radius, (coll.halfHeight + coll.radius), coll.radius },
tf * csl::math::Vector3{ coll.radius, (coll.halfHeight + coll.radius), coll.radius },
};

csl::geom::Aabb res{ { INFINITY, INFINITY, INFINITY }, { -INFINITY, -INFINITY, -INFINITY } };

for (size_t i = 0; i < 8; i++)
res.AddPoint(corners[i]);

return res;
}
4 changes: 4 additions & 0 deletions src/utilities/BoundingBoxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ csl::geom::Aabb Union(const csl::geom::Aabb& one, const csl::geom::Aabb& other);
csl::geom::Aabb CalcAabb(const csl::geom::Sphere& sphere);
csl::geom::Aabb CalcAabb(const csl::geom::Cylinder& sphere);
csl::geom::Aabb CalcAabb(const csl::geom::Obb& sphere);
csl::geom::Aabb CalcAabb(const hh::physics::GOCSphereCollider& coll);
csl::geom::Aabb CalcAabb(const hh::physics::GOCBoxCollider& coll);
csl::geom::Aabb CalcAabb(const hh::physics::GOCCylinderCollider& coll);
csl::geom::Aabb CalcAabb(const hh::physics::GOCCapsuleCollider& coll);

0 comments on commit a8b950f

Please sign in to comment.