lullaby/tests/physics_system_test.cc
// Test the center of mass translation.
Test the center of mass translation.
Test the center of mass translation .
TEST_F(PhysicsSystemTest, CenterOfMassTranslation) {
  auto* physics_system = registry_->Get<PhysicsSystem>();
  auto* transform_system = registry_->Get<TransformSystem>();
  auto* entity_factory = registry_->Get<EntityFactory>();
  const Entity origin = CreateBasicRigidBody(
      mathfu::kZeros3f, RigidBodyType::RigidBodyType_Static,
      ColliderType::ColliderType_Trigger);
  EXPECT_THAT(origin, Ne(kNullEntity));
  Blueprint blueprint(512);
  {
    TransformDefT transform;
    transform.aabb.min = -mathfu::kOnes3f;
    transform.aabb.max = mathfu::kOnes3f;
    blueprint.Write(&transform);
    RigidBodyDefT rigid_body;
    rigid_body.type = RigidBodyType::RigidBodyType_Kinematic;
    rigid_body.collider_type = ColliderType::ColliderType_Trigger;
    rigid_body.center_of_mass_translation = mathfu::vec3(0.f, 3.f, 0.f);
    blueprint.Write(&rigid_body);
  }
  const Entity kinematic = entity_factory->Create(&blueprint);
  EXPECT_THAT(kinematic, Ne(kNullEntity));
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  transform_system->SetLocalTranslation(kinematic,
                                        mathfu::vec3(0.f, -3.f, 0.f));
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_TRUE(physics_system->AreInContact(origin, kinematic));
  transform_system->SetLocalTranslation(kinematic, mathfu::kZeros3f);
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_FALSE(physics_system->AreInContact(origin, kinematic));
  EXPECT_THAT(transform_system->GetLocalTranslation(kinematic),
              Eq(transform_system->GetLocalTranslation(origin)));
}
TEST_F ( PhysicsSystemTest , CenterOfMassTranslation ) { auto * physics_system = registry_ -> Get < PhysicsSystem > ( ) ; auto * transform_system = registry_ -> Get < TransformSystem > ( ) ; auto * entity_factory = registry_ -> Get < EntityFactory > ( ) ; const Entity origin = CreateBasicRigidBody ( mathfu :: kZeros3f , RigidBodyType :: RigidBodyType_Static , ColliderType :: ColliderType_Trigger ) ; EXPECT_THAT ( origin , Ne ( kNullEntity ) ) ; Blueprint blueprint ( 512 ) ; { TransformDefT transform ; transform . aabb . min = - mathfu :: kOnes3f ; transform . aabb . max = mathfu :: kOnes3f ; blueprint . Write ( & transform ) ; RigidBodyDefT rigid_body ; rigid_body . type = RigidBodyType :: RigidBodyType_Kinematic ; rigid_body . collider_type = ColliderType :: ColliderType_Trigger ; rigid_body . center_of_mass_translation = mathfu :: vec3 ( 0.f , 3.f , 0.f ) ; blueprint . Write ( & rigid_body ) ; } const Entity kinematic = entity_factory -> Create ( & blueprint ) ; EXPECT_THAT ( kinematic , Ne ( kNullEntity ) ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; transform_system -> SetLocalTranslation ( kinematic , mathfu :: vec3 ( 0.f , -3.f , 0.f ) ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_TRUE ( physics_system -> AreInContact ( origin , kinematic ) ) ; transform_system -> SetLocalTranslation ( kinematic , mathfu :: kZeros3f ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_FALSE ( physics_system -> AreInContact ( origin , kinematic ) ) ; EXPECT_THAT ( transform_system -> GetLocalTranslation ( kinematic ) , Eq ( transform_system -> GetLocalTranslation ( origin ) ) ) ; }
Test the center of mass translation.
Test the center of mass translation .
// Create a Static Trigger box at the origin. // Create a 2x2x2 Kinematic Trigger box also at the origin, but give it a // center of mass translation. // Advance the PhysicsSystem and confirm they are not in contact. // Move the kinematic object down to offset its center of mass translation and // verify that it is in contact due to said translation (even though based on // its position and AABB, it shouldn't be). // Move it back out of contact. Confirm that the Entity positions are indeed // the same.