コード例 #1
0
ファイル: movement_test.cpp プロジェクト: msecret/space-gun
TEST(Moveable, getsetMass) {
  Moveable c;
  float expectedMass = 4.5;
  Vector2d expectedCenter = { 1, 1 };

  c.setMass(expectedMass,
      expectedCenter,
      0);

  auto actual = c.getMass();

  EXPECT_EQ(actual, expectedMass);

  Vector2d g = { 0.0, 0.0 };
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);
  Entity e;

  c.init(w, p, e);

  actual = c.getMass();

  EXPECT_EQ(actual, expectedMass);
}
コード例 #2
0
ファイル: movement_test.cpp プロジェクト: msecret/space-gun
TEST(Moveable, applyForce) {
  Vector2d g = { 0.0, 0.0 };
  Vector2d initV = { 1.0, 1.0 };
  Vector2d initP = { 0.0, 0.0 };
  Vector2d force = { 4.0, 0.0 };
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);

  Moveable m(initV, initP);
  Entity e;

  m.init(w, p, e);

  auto actual = m.getVel();

  EXPECT_EQ(actual, initV);

  m.applyForce(force);
  w.Step(0.8, 8, 2);

  actual = m.getVel();

  // Note: 1.4 value found through trial.
  EXPECT_EQ(actual.x, 1.4f);
  EXPECT_EQ(actual.y, 1);
}
コード例 #3
0
ファイル: thrust_test.cpp プロジェクト: msecret/space-gun
TEST(Thrust, onAddEntity) {
  Vector2d g = { 0.0, 0.0 };
  Vector2d initP = { 0, 0 };
  Vector2d initV = { 0, 0 };
  Vector2d direction = { 1, 1 };
  float factor = 1000;
  EvUserMovement ev(direction);
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);

  Moveable cm(initP, initV);
  Thrustable ct(factor);
  Entity* e = new Entity();
  Thrust s;
  cm.init(w, p, *e);

  e->addComponent(&cm);
  e->addComponent(&ct);

  s.onAddEntity(*e);

  e->emit(EV_USER_MOVEMENT, &ev);
  w.Step(0.8, 8, 2);

  auto actual = cm.getVel();

  EXPECT_FLOAT_EQ(actual.x, 2.5);
  EXPECT_FLOAT_EQ(actual.y, 0.0);
}
コード例 #4
0
ファイル: movement_test.cpp プロジェクト: msecret/space-gun
TEST(Moveable, init) {
  Vector2d g = { 0, 0 };
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);
  Moveable c;
  Entity e;

  c.init(w, p, e);

  auto actual = c.getBody();

  EXPECT_NE(actual, nullptr);
}
コード例 #5
0
ファイル: movement_test.cpp プロジェクト: msecret/space-gun
TEST(Moveable, getAngle) {
  Vector2d g = { 0.0, 0.0 };
  Vector2d vel = { 1, 1 };
  Vector2d initPos = { 1, 1 };
  float expectedAngle = 89.3;
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);
  Entity e;

  Moveable c = Moveable(vel, initPos, expectedAngle);

  auto actual = c.getAngle();
  EXPECT_EQ(actual, expectedAngle);

  c.init(w, p, e);

  actual = c.getAngle();
  EXPECT_EQ(actual, expectedAngle);
}