lullaby/tests/physics_system_test.cc
// Test that Dynamic bodies have their transforms updated appropriately based
// on the length of the frame.
Test that Dynamic bodies have their transforms updated appropriately based
on the length of the frame.
Test that Dynamic bodies have their transforms updated appropriately based on the length of the frame .
TEST_F(PhysicsSystemTest, MultipleTimesteps) {
  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 mathfu::vec3 velocity = mathfu::kOnes3f;
  physics_system->SetLinearVelocity(entity, velocity);
  const Sqt* sqt = transform_system->GetSqt(entity);
  mathfu::vec3 next_position = sqt->translation + kFrameSeconds * velocity;
  physics_system->AdvanceFrame(kFrameDuration);
  EXPECT_THAT(sqt->translation, NearMathfuVec3(next_position, kDefaultEpsilon));
  next_position = sqt->translation + (3.f * kFrameSeconds) * velocity;
  physics_system->AdvanceFrame(3 * kFrameDuration);
  EXPECT_THAT(sqt->translation, NearMathfuVec3(next_position, kDefaultEpsilon));
  next_position = sqt->translation + (10.f * kFrameSeconds) * velocity;
  physics_system->AdvanceFrame(10 * kFrameDuration);
  EXPECT_THAT(sqt->translation,
              Not(NearMathfuVec3(next_position, kDefaultEpsilon)));
  const mathfu::vec3 old_position = sqt->translation;
  next_position = sqt->translation + (kFrameSeconds) * velocity;
  physics_system->AdvanceFrame(kFrameDuration / 2);
  EXPECT_THAT(sqt->translation, NearMathfuVec3(old_position, kDefaultEpsilon));
  physics_system->AdvanceFrame(kFrameDuration / 2);
  EXPECT_THAT(sqt->translation, NearMathfuVec3(next_position, kDefaultEpsilon));
}
TEST_F ( PhysicsSystemTest , MultipleTimesteps ) { 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 mathfu :: vec3 velocity = mathfu :: kOnes3f ; physics_system -> SetLinearVelocity ( entity , velocity ) ; const Sqt * sqt = transform_system -> GetSqt ( entity ) ; mathfu :: vec3 next_position = sqt -> translation + kFrameSeconds * velocity ; physics_system -> AdvanceFrame ( kFrameDuration ) ; EXPECT_THAT ( sqt -> translation , NearMathfuVec3 ( next_position , kDefaultEpsilon ) ) ; next_position = sqt -> translation + ( 3.f * kFrameSeconds ) * velocity ; physics_system -> AdvanceFrame ( 3 * kFrameDuration ) ; EXPECT_THAT ( sqt -> translation , NearMathfuVec3 ( next_position , kDefaultEpsilon ) ) ; next_position = sqt -> translation + ( 10.f * kFrameSeconds ) * velocity ; physics_system -> AdvanceFrame ( 10 * kFrameDuration ) ; EXPECT_THAT ( sqt -> translation , Not ( NearMathfuVec3 ( next_position , kDefaultEpsilon ) ) ) ; const mathfu :: vec3 old_position = sqt -> translation ; next_position = sqt -> translation + ( kFrameSeconds ) * velocity ; physics_system -> AdvanceFrame ( kFrameDuration / 2 ) ; EXPECT_THAT ( sqt -> translation , NearMathfuVec3 ( old_position , kDefaultEpsilon ) ) ; physics_system -> AdvanceFrame ( kFrameDuration / 2 ) ; EXPECT_THAT ( sqt -> translation , NearMathfuVec3 ( next_position , kDefaultEpsilon ) ) ; }
Test that Dynamic bodies have their transforms updated appropriately based
on the length of the frame.
Test that Dynamic bodies have their transforms updated appropriately based on the length of the frame .
// Disable gravity. // Create a Dynamic box at the origin. // Give the body a simple linear velocity. // Give the system a typical frame and ensure that the position changes by the // expected amount. // Give the system a longer frame and ensure that the position changes by the // expected amount. // Give the system a really long frame and it will fail to process it all at // once and time will be "lost". // Give the system two really small frames and it will only update when a full // fixed timestep has been reached.