lullaby/tests/physics_system_test.cc
// Test that Dynamic bodies have their transform updated.
Test that Dynamic bodies have their transform updated.
Test that Dynamic bodies have their transform updated .
TEST_F(PhysicsSystemTest, DynamicBody) {
  auto* physics_system = registry_->Get<PhysicsSystem>();
  auto* transform_system = registry_->Get<TransformSystem>();
  physics_system->SetGravity(mathfu::kZeros3f);
  const Entity entity = CreateBasicRigidBody(
      mathfu::kZeros3f, RigidBodyType::RigidBodyType_Dynamic);
  EXPECT_THAT(entity, Ne(kNullEntity));
  const Sqt first_sqt = *transform_system->GetSqt(entity);
  physics_system->AdvanceFrame(kFrameDuration);
  const Sqt second_sqt = *transform_system->GetSqt(entity);
  EXPECT_THAT(second_sqt.translation,
              NearMathfuVec3(first_sqt.translation, kDefaultEpsilon));
  EXPECT_THAT(second_sqt.rotation,
              NearMathfuQuat(first_sqt.rotation, kDefaultEpsilon));
  physics_system->SetLinearVelocity(entity, mathfu::kOnes3f);
  physics_system->AdvanceFrame(kFrameDuration);
  const Sqt third_sqt = *transform_system->GetSqt(entity);
  EXPECT_THAT(third_sqt.translation,
              Not(NearMathfuVec3(second_sqt.translation, kDefaultEpsilon)));
  EXPECT_THAT(third_sqt.rotation,
              NearMathfuQuat(second_sqt.rotation, kDefaultEpsilon));
  physics_system->SetAngularVelocity(entity, mathfu::kOnes3f);
  physics_system->AdvanceFrame(kFrameDuration);
  const Sqt fourth_sqt = *transform_system->GetSqt(entity);
  EXPECT_THAT(fourth_sqt.translation,
              Not(NearMathfuVec3(third_sqt.translation, kDefaultEpsilon)));
  EXPECT_THAT(fourth_sqt.rotation,
              Not(NearMathfuQuat(third_sqt.rotation, kDefaultEpsilon)));
  physics_system->SetLinearVelocity(entity, mathfu::kZeros3f);
  physics_system->SetAngularVelocity(entity, mathfu::kZeros3f);
  physics_system->AdvanceFrame(kFrameDuration);
  const Sqt fifth_sqt = *transform_system->GetSqt(entity);
  EXPECT_THAT(fifth_sqt.translation,
              NearMathfuVec3(fourth_sqt.translation, kDefaultEpsilon));
  EXPECT_THAT(fifth_sqt.rotation,
              NearMathfuQuat(fourth_sqt.rotation, kDefaultEpsilon));
  physics_system->SetGravity(mathfu::vec3(0.f, -10.f, 0.f));
  physics_system->AdvanceFrame(kFrameDuration);
  const Sqt sixth_sqt = *transform_system->GetSqt(entity);
  EXPECT_THAT(sixth_sqt.translation,
              Not(NearMathfuVec3(fifth_sqt.translation, kDefaultEpsilon)));
  EXPECT_THAT(sixth_sqt.rotation,
              NearMathfuQuat(fifth_sqt.rotation, kDefaultEpsilon));
}
TEST_F ( PhysicsSystemTest , DynamicBody ) { auto * physics_system = registry_ -> Get < PhysicsSystem > ( ) ; auto * transform_system = registry_ -> Get < TransformSystem > ( ) ; physics_system -> SetGravity ( mathfu :: kZeros3f ) ; const Entity entity = CreateBasicRigidBody ( mathfu :: kZeros3f , RigidBodyType :: RigidBodyType_Dynamic ) ; EXPECT_THAT ( entity , Ne ( kNullEntity ) ) ; const Sqt first_sqt = * transform_system -> GetSqt ( entity ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; const Sqt second_sqt = * transform_system -> GetSqt ( entity ) ; EXPECT_THAT ( second_sqt . translation , NearMathfuVec3 ( first_sqt . translation , kDefaultEpsilon ) ) ; EXPECT_THAT ( second_sqt . rotation , NearMathfuQuat ( first_sqt . rotation , kDefaultEpsilon ) ) ; physics_system -> SetLinearVelocity ( entity , mathfu :: kOnes3f ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; const Sqt third_sqt = * transform_system -> GetSqt ( entity ) ; EXPECT_THAT ( third_sqt . translation , Not ( NearMathfuVec3 ( second_sqt . translation , kDefaultEpsilon ) ) ) ; EXPECT_THAT ( third_sqt . rotation , NearMathfuQuat ( second_sqt . rotation , kDefaultEpsilon ) ) ; physics_system -> SetAngularVelocity ( entity , mathfu :: kOnes3f ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; const Sqt fourth_sqt = * transform_system -> GetSqt ( entity ) ; EXPECT_THAT ( fourth_sqt . translation , Not ( NearMathfuVec3 ( third_sqt . translation , kDefaultEpsilon ) ) ) ; EXPECT_THAT ( fourth_sqt . rotation , Not ( NearMathfuQuat ( third_sqt . rotation , kDefaultEpsilon ) ) ) ; physics_system -> SetLinearVelocity ( entity , mathfu :: kZeros3f ) ; physics_system -> SetAngularVelocity ( entity , mathfu :: kZeros3f ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; const Sqt fifth_sqt = * transform_system -> GetSqt ( entity ) ; EXPECT_THAT ( fifth_sqt . translation , NearMathfuVec3 ( fourth_sqt . translation , kDefaultEpsilon ) ) ; EXPECT_THAT ( fifth_sqt . rotation , NearMathfuQuat ( fourth_sqt . rotation , kDefaultEpsilon ) ) ; physics_system -> SetGravity ( mathfu :: vec3 ( 0.f , -10.f , 0.f ) ) ; physics_system -> AdvanceFrame ( kFrameDuration ) ; const Sqt sixth_sqt = * transform_system -> GetSqt ( entity ) ; EXPECT_THAT ( sixth_sqt . translation , Not ( NearMathfuVec3 ( fifth_sqt . translation , kDefaultEpsilon ) ) ) ; EXPECT_THAT ( sixth_sqt . rotation , NearMathfuQuat ( fifth_sqt . rotation , kDefaultEpsilon ) ) ; }
Test that Dynamic bodies have their transform updated.
Test that Dynamic bodies have their transform updated .
// Disable gravity. // Create a Dynamic box at the origin. // Advance the PhysicsSystem and confirm that there no changes in transform. // Set a linear velocity, then check that translation changes. Don't worry // about the exact difference. // Set an angular velocity, then check that rotation changes. Don't worry // about the exact difference. // Zero out the velocities and check that nothing changes. // Re-enable gravity and check that the position changes.