Example #1
0
void TestApp::test_rotate_and_get_euler(clan::EulerOrder order)
{
	for (int ax = 0; ax < 360; ax += 10)
	{
		for (int ay = 0; ay < 360; ay += 10)
		{
			for (int az = 0; az < 360; az += 10)
			{
				Angle angle_x(ax, angle_degrees);
				Angle angle_y(ay, angle_degrees);
				Angle angle_z(az, angle_degrees);

				Mat4f test_matrix;
				test_matrix = Mat4f::rotate(angle_x, angle_y, angle_z, order);

				Vec3f angles = test_matrix.get_euler(order);

				Mat4f test_matrix2;
				test_matrix2 = Mat4f::rotate(Angle(angles.x, angle_radians), Angle(angles.y, angle_radians), Angle(angles.z, angle_radians), order);

				// Note, since euler angles can have alternative forms, we compare by recreating as a rotation matrix
				if (!test_matrix.is_equal(test_matrix2, 0.00001f))
					fail();

				//check_float(angles.x, angle_x.to_radians());
				//check_float(angles.y, angle_y.to_radians());
				//check_float(angles.z, angle_z.to_radians());
			}
		}
	}
}
Example #2
0
void go_spheres(spheres *s, int i, int j,  int k, double t, vector_field field){
  vector v, v0;
  double mod;

  v0.x = (*s).all[i][j][k].x;
  v0.y = (*s).all[i][j][k].y;
  v0.z = (*s).all[i][j][k].z;

  v = trilinear_interpolation(v0, field);
  mod = module(v);
	
  if( v.x != 0.0 ) 
    (*s).all[i][j][k].x += t*mod*cos(angle_x(v)*PI/180);
  if( (*s).all[i][j][k].x > field.n_x/2 )
   (*s).all[i][j][k].x = field.n_x/2;
  else if( (*s).all[i][j][k].x < -(field.n_x)/2 )
   (*s).all[i][j][k].x = -(field.n_x)/2;

  if( v.y != 0.0 )
    (*s).all[i][j][k].y += t*mod*cos(angle_y(v)*PI/180);
  if( (*s).all[i][j][k].y > field.n_y/2 )
   (*s).all[i][j][k].y = field.n_y/2;
  else if( (*s).all[i][j][k].y < -field.n_y/2 )
   (*s).all[i][j][k].y = -(field.n_y)/2;

  if( v.z != 0.0 )
    (*s).all[i][j][k].z += t*mod*cos(angle_z(v)*PI/180);
  if( (*s).all[i][j][k].z > field.n_z/2 )
   (*s).all[i][j][k].z = field.n_z/2;
  else if( (*s).all[i][j][k].z < -(field.n_z)/2 )
   (*s).all[i][j][k].z = -(field.n_z)/2;
}
Example #3
0
void TestApp::test_matrix_mat4()
{
	Console::write_line("  Class: Mat4");

	Console::write_line("   Function: inverse()");
	{

		Mat4f test_src = Mat4f::rotate((Angle(30, angle_degrees)), 1.0, 0.0, 0.0, true);
		Mat4f test_inv;
		Mat4f test_dest;
		Mat4f test_ident = Mat4f::identity();

		test_dest = test_src;
		test_dest.inverse();
		test_dest = test_dest * test_src;

		if (test_ident != test_dest) fail();

	}

	static int test_a_values[] = {3, 1, 2, 4, 5 ,6, 4, 2, 1, 4, 6, 7, 6, 3, 7, 2};
	static int test_b_values[] = {4, 7, 2, 5, 3, 5, 2, 9, 3, 3, 6, 9, 2, 4, 6, 2};

	Mat4i test_a(test_a_values);
	Mat4i test_b(test_b_values);

	Console::write_line("   Function: add() and operator");
	{
		int answer_values[] = {7, 8, 4, 9, 8, 11, 6, 11, 4, 7, 12, 16, 8, 7, 13, 4};
		Mat4i answer(answer_values);

		Mat4i result = test_a + test_b;
		if (result != answer) fail();

		result = Mat4i::add(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: subtract() and operator");
	{
		int answer_values[] = {-1, -6, 0, -1, 2, 1, 2, -7, -2, 1, 0, -2, 4, -1, 1, 0};
		Mat4i answer(answer_values);

		Mat4i result = test_a - test_b;
		if (result != answer) fail();

		result = Mat4i::subtract(test_a, test_b);
		if (result != answer) fail();

	}

	Console::write_line("   Function: translate()");
	{
		int answer_values[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, 4, 1};
		Mat4i answer(answer_values);

		Mat4i result = Mat4i::translate(2, 3, 4);
		if (result != answer) fail();
	}

	Console::write_line("   Function: translate_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::translate(2, 3, 4);

		Mat4i result2 = test_a;
		result2.translate_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: scale_self()");
	{
		Mat4i answer(test_a);

		Mat4i result = test_a;
		result = result * Mat4i::scale(2, 3, 4);

		Mat4i result2 = test_a;
		result2.scale_self(2,3,4);

		if (result != result2) fail();
	}

	Console::write_line("   Function: rotate (using euler angles) and get_euler");
	{
		Angle angle_x(20, angle_degrees);
		Angle angle_y(30, angle_degrees);
		Angle angle_z(40, angle_degrees);

		Mat4f test_matrix;
		test_matrix = Mat4f::rotate(angle_x, angle_y, angle_z, order_YXZ);

		Vec3f angles = test_matrix.get_euler(order_YXZ);

		check_float(angles.x, angle_x.to_radians());
		check_float(angles.y, angle_y.to_radians());
		check_float(angles.z, angle_z.to_radians());
	}
}