lullaby/tests/physics_system_test.cc
// Test that rigid bodies are added and removed to the world at the right time.
// Use contact to determine if both bodies are in the world.
Test that rigid bodies are added and removed to the world at the right time.
Use contact to determine if both bodies are in the world.
Test that rigid bodies are added and removed to the world at the right time . Use contact to determine if both bodies are in the world .
TEST_F(PhysicsSystemTest, RigidBodyInSimulation) {
  auto* physics_system = registry_->Get<PhysicsSystem>();
  auto* transform_system = registry_->Get<TransformSystem>();
  const Entity origin = CreateBasicRigidBody(
      mathfu::kZeros3f, RigidBodyType::RigidBodyType_Static,
      ColliderType::ColliderType_Trigger);
  EXPECT_THAT(origin, Ne(kNullEntity));
  const Entity kinematic = CreateBasicRigidBody(
      mathfu::kZeros3f, RigidBodyType::RigidBodyType_Kinematic,
      ColliderType::ColliderType_Trigger);
  EXPECT_THAT(kinematic, Ne(kNullEntity));
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_TRUE(physics_system->AreInContact(origin, kinematic));
  physics_system->DisablePhysics(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  physics_system->EnablePhysics(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_TRUE(physics_system->AreInContact(origin, kinematic));
  transform_system->Disable(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  transform_system->Enable(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_TRUE(physics_system->AreInContact(origin, kinematic));
  physics_system->DisablePhysics(origin);
  transform_system->Disable(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  physics_system->EnablePhysics(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  physics_system->DisablePhysics(origin);
  transform_system->Enable(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  transform_system->Disable(origin);
  physics_system->EnablePhysics(origin);
  transform_system->Enable(origin);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_TRUE(physics_system->AreInContact(origin, kinematic));
}
TEST_F ( PhysicsSystemTest , RigidBodyInSimulation ) { auto * physics_system = registry_ -> Get < PhysicsSystem > ( ) ; auto * transform_system = registry_ -> Get < TransformSystem > ( ) ; const Entity origin = CreateBasicRigidBody ( mathfu :: kZeros3f , RigidBodyType :: RigidBodyType_Static , ColliderType :: ColliderType_Trigger ) ; EXPECT_THAT ( origin , Ne ( kNullEntity ) ) ; const Entity kinematic = CreateBasicRigidBody ( mathfu :: kZeros3f , RigidBodyType :: RigidBodyType_Kinematic , ColliderType :: ColliderType_Trigger ) ; EXPECT_THAT ( kinematic , Ne ( kNullEntity ) ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_TRUE ( physics_system -> AreInContact ( origin , kinematic ) ) ; physics_system -> DisablePhysics ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; physics_system -> EnablePhysics ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_TRUE ( physics_system -> AreInContact ( origin , kinematic ) ) ; transform_system -> Disable ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; transform_system -> Enable ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_TRUE ( physics_system -> AreInContact ( origin , kinematic ) ) ; physics_system -> DisablePhysics ( origin ) ; transform_system -> Disable ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; physics_system -> EnablePhysics ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; physics_system -> DisablePhysics ( origin ) ; transform_system -> Enable ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; transform_system -> Disable ( origin ) ; physics_system -> EnablePhysics ( origin ) ; transform_system -> Enable ( origin ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_TRUE ( physics_system -> AreInContact ( origin , kinematic ) ) ; }
Test that rigid bodies are added and removed to the world at the right time.
Test that rigid bodies are added and removed to the world at the right time .
// Create a Static Trigger box at the origin. // Create a 2x2x2 Kinematic Trigger box also at the origin, meanign the two // will always be in contact if both are in the simulation. // Advance the PhysicsSystem and confirm they in contact. // Disabling physics on one of the Entities results in no contact. // Re-enabling it will trigger contact events. // Likewise, disabling one of Entities entirely will result in no contact. // Re-enabling it will trigger contact events. // Disable physics and disable the Entity itself, then confirm no contact. // Just enabling physics doesn't result in contact. // Just enabling the Entity doesn't result in contact. // Enabling physics and the Entity results in contact.