feat: add imguizmo + trigger buxfix
This commit is contained in:
@@ -453,6 +453,64 @@ namespace {
|
||||
SceneManager::GetInstance().Destroy();
|
||||
}
|
||||
|
||||
class TriggerCounter final : public Component {
|
||||
public:
|
||||
explicit TriggerCounter(GameObject& parent)
|
||||
: Component(parent, "TriggerCounter") {}
|
||||
|
||||
std::string GetTypeName() const override { return "TriggerCounter"; }
|
||||
void OnTriggerEnter(GameObject*) override { ++enters; }
|
||||
void OnTriggerExit(GameObject*) override { ++exits; }
|
||||
|
||||
int enters{0};
|
||||
int exits{0};
|
||||
};
|
||||
|
||||
void testNonPhysicsChangesKeepBodies()
|
||||
{
|
||||
Scene& scene = SceneManager::GetInstance().CreateScene("physics-refresh");
|
||||
|
||||
GameObject* trigger = scene.CreateGameObject("trigger");
|
||||
trigger->AddComponent<BoxCollider>(glm::vec3{3.0f})->SetTrigger(true);
|
||||
trigger->AddComponent<Rigidbody>()->SetType(RigidbodyType::Static);
|
||||
auto* counter = trigger->AddComponent<TriggerCounter>();
|
||||
|
||||
GameObject* crate = scene.CreateGameObject("crate");
|
||||
crate->AddComponent<BoxCollider>(glm::vec3{0.5f});
|
||||
auto* crateBody = crate->AddComponent<Rigidbody>();
|
||||
crateBody->SetUseGravity(false);
|
||||
crateBody->SetAllowSleep(false);
|
||||
|
||||
GameObject* lamp = scene.CreateGameObject("lamp");
|
||||
auto* light = lamp->AddComponent<LightComponent>();
|
||||
|
||||
scene.CommitPendingAdditions();
|
||||
scene.GetPhysics().RefreshGameObject(*trigger);
|
||||
scene.GetPhysics().RefreshGameObject(*crate);
|
||||
|
||||
const auto step = [&scene] {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
scene.FixedUpdate(1.0f / 60.0f);
|
||||
}
|
||||
};
|
||||
step();
|
||||
check(counter->enters == 1 && counter->exits == 0, "a body inside a trigger must enter it once");
|
||||
|
||||
light->SetEnabled(false);
|
||||
light->SetEnabled(true);
|
||||
crate->AddComponent<LightComponent>()->SetEnabled(false);
|
||||
step();
|
||||
check(counter->enters == 1 && counter->exits == 0,
|
||||
"non physics components must not rebuild physics bodies");
|
||||
|
||||
crateBody->SetMass(5.0f);
|
||||
step();
|
||||
check(counter->enters == 2 && counter->exits == 1,
|
||||
"rebuilding a body inside a trigger must exit the old body and enter the new one");
|
||||
|
||||
SceneManager::GetInstance().Destroy();
|
||||
}
|
||||
|
||||
void testRenderer2DShapes()
|
||||
{
|
||||
auto& r2d = Renderer2D::GetInstance();
|
||||
@@ -1230,6 +1288,7 @@ int main()
|
||||
testPhysicsWorldUnits();
|
||||
testJoltSphereCollisions();
|
||||
testSceneJoltSphereCollisions();
|
||||
testNonPhysicsChangesKeepBodies();
|
||||
testAnimatorAssetReferences();
|
||||
testLightComponentRoundTrip();
|
||||
testModelFileRoundTrip();
|
||||
|
||||
Reference in New Issue
Block a user