Esempio n. 1
0
TEST(VectorBase, Addition) {
  float fv[2] = {1.1f, 3.2f};
  FasTC::VectorBase<float, 2> v2f (fv);

  int uv[2] = {5, 2};
  FasTC::VectorBase<int, 2> v2u (uv);

  FasTC::VectorBase<int, 2> au = v2u + v2f;
  EXPECT_EQ(au[0], 6);
  EXPECT_EQ(au[1], 5);

  au = v2u + fv + uv;
  EXPECT_EQ(au[0], 11);
  EXPECT_EQ(au[1], 7);

  FasTC::VectorBase<float, 2> af = v2f + v2u;
  EXPECT_NEAR(af[0], 6.1f, kEpsilon);
  EXPECT_NEAR(af[1], 5.2f, kEpsilon);

  au = v2u - v2f;
  EXPECT_EQ(au[0], 4);
  EXPECT_EQ(au[1], -1);

  af = v2f - v2u;
  EXPECT_NEAR(af[0], -3.9f, kEpsilon);
  EXPECT_NEAR(af[1], 1.2f, kEpsilon);  
}
Esempio n. 2
0
TEST(VectorBase, Scaling) {
  float fv[2] = {1.0f, 3.0f};
  FasTC::VectorBase<float, 2> v2f (fv);
  FasTC::VectorBase<float, 2> v2fd = v2f * 3.0f;
  EXPECT_NEAR(v2fd[0], 3.0f, kEpsilon);
  EXPECT_NEAR(v2fd[1], 9.0f, kEpsilon);

  v2fd = -1.0 * v2f;
  EXPECT_NEAR(v2fd[0], -1.0f, kEpsilon);
  EXPECT_NEAR(v2fd[1], -3.0f, kEpsilon);

  v2fd = v2f / 3;
  EXPECT_NEAR(v2fd[0], 1.0f / 3.0f, kEpsilon);
  EXPECT_NEAR(v2fd[1], 1.0f, kEpsilon);

  unsigned uv[2] = {1, 3};
  FasTC::VectorBase<unsigned, 2> v2u (uv);
  FasTC::VectorBase<unsigned, 2> v2ud = v2u * 0.5;
  EXPECT_EQ(v2ud[0], static_cast<unsigned>(0));
  EXPECT_EQ(v2ud[1], static_cast<unsigned>(1));

  v2ud = v2u / 0.5f;
  EXPECT_EQ(v2ud[0], static_cast<unsigned>(2));
  EXPECT_EQ(v2ud[1], static_cast<unsigned>(6));  
}
Esempio n. 3
0
void Game::render () {
	CNTRL ("game_render");
	window.clear ();
	if (v2u (R_WIND_WIDTH, R_WIND_HEIGHT) != window.getSize ()) {
		R_WIND_WIDTH = window.getSize ().x;
		R_WIND_HEIGHT = window.getSize ().y;
	}
	all_spaces["MAIN"]->render ();

	window.display ();
}
Esempio n. 4
0
TEST(VectorBase, Normalization) {
  float fv[2] = {1, 0};
  FasTC::VectorBase<float, 2> v2f (fv);
  v2f.Normalize();
  EXPECT_NEAR(v2f[0], 1, kEpsilon);
  EXPECT_NEAR(v2f[1], 0, kEpsilon);

  // Normalized vector should be sqrt(2) for each axis, although
  // this can't be represented as integers...
  unsigned uv[2] = {2, 2};
  FasTC::VectorBase<unsigned, 2> v2u (uv);
  v2u.Normalize();
  EXPECT_EQ(v2u[0], static_cast<unsigned>(1));
  EXPECT_EQ(v2u[1], static_cast<unsigned>(1));

  const double sqrt2 = sqrt(2.0f)/2.0f;
  for(int i = 2; i < 10; i++) {
    v2f[0] = static_cast<float>(i);
    v2f[1] = static_cast<float>(i);
    v2f.Normalize();
    EXPECT_NEAR(v2f[0], sqrt2, kEpsilon);
    EXPECT_NEAR(v2f[1], sqrt2, kEpsilon);
  }
}