GRAPHENE_TEST_UNIT_END GRAPHENE_TEST_UNIT_BEGIN (ray_closest_point_to_point) { graphene_point3d_t tmp = GRAPHENE_POINT3D_INIT (0.f, 0.f, 50.f); graphene_point3d_t check = GRAPHENE_POINT3D_INIT (1.f, 1.f, 50.f); graphene_point3d_t res; graphene_ray_t r; graphene_ray_init (&r, &one3, graphene_vec3_z_axis ()); if (g_test_verbose ()) g_test_message ("Behind the ray..."); graphene_ray_get_closest_point_to_point (&r, &zero3, &res); g_assert_true (graphene_point3d_near (&res, &one3, 0.00001f)); if (g_test_verbose ()) g_test_message ("Front of the ray..."); graphene_ray_get_closest_point_to_point (&r, &tmp, &res); g_assert_true (graphene_point3d_near (&res, &check, 0.00001f)); if (g_test_verbose ()) g_test_message ("On the ray..."); graphene_ray_get_closest_point_to_point (&r, &one3, &res); g_assert_true (graphene_point3d_near (&res, &one3, 0.00001f)); }
GRAPHENE_TEST_UNIT_END GRAPHENE_TEST_UNIT_BEGIN (ray_get_position_at) { graphene_ray_t r; graphene_point3d_t tmp; graphene_ray_init (&r, &one3, graphene_vec3_z_axis ()); if (g_test_verbose ()) g_test_message ("On the ray's origin..."); graphene_ray_get_position_at (&r, 0.f, &tmp); g_assert_true (graphene_point3d_equal (&tmp, &one3)); if (g_test_verbose ()) g_test_message ("Behind the ray..."); graphene_ray_get_position_at (&r, -1.f, &tmp); graphene_assert_fuzzy_equals (tmp.x, 1.f, 0.0001); graphene_assert_fuzzy_equals (tmp.y, 1.f, 0.0001); graphene_assert_fuzzy_equals (tmp.z, 0.f, 0.0001); if (g_test_verbose ()) g_test_message ("On the ray..."); graphene_ray_get_position_at (&r, 1.f, &tmp); graphene_assert_fuzzy_equals (tmp.x, 1.f, 0.0001); graphene_assert_fuzzy_equals (tmp.y, 1.f, 0.0001); graphene_assert_fuzzy_equals (tmp.z, 2.f, 0.0001); }
GRAPHENE_TEST_UNIT_END GRAPHENE_TEST_UNIT_BEGIN (ray_matrix_transform) { graphene_ray_t r, res; graphene_matrix_t m; if (g_test_verbose ()) g_test_message ("Identity matrix..."); graphene_ray_init (&r, &one3, graphene_vec3_z_axis ()); graphene_matrix_init_identity (&m); graphene_matrix_transform_ray (&m, &r, &res); g_assert_true (graphene_ray_equal (&r, &res)); if (g_test_verbose ()) g_test_message ("Rotation matrix: rotateZ(90deg)"); graphene_ray_init (&r, &zero3, graphene_vec3_z_axis ()); graphene_matrix_init_rotate (&m, 90, graphene_vec3_z_axis ()); graphene_matrix_transform_ray (&m, &r, &res); g_assert_true (graphene_ray_equal (&r, &res)); }
static void gst_gl_transformation_build_mvp (GstGLTransformation * transformation) { graphene_point3d_t translation_vector = GRAPHENE_POINT3D_INIT (transformation->xtranslation * 2.0 * transformation->aspect, transformation->ytranslation * 2.0, transformation->ztranslation * 2.0); graphene_matrix_t model_matrix; graphene_matrix_t projection_matrix; graphene_matrix_t view_matrix; graphene_matrix_t vp_matrix; graphene_vec3_t eye; graphene_vec3_t center; graphene_vec3_t up; graphene_vec3_init (&eye, 0.f, 0.f, 1.f); graphene_vec3_init (¢er, 0.f, 0.f, 0.f); graphene_vec3_init (&up, 0.f, 1.f, 0.f); graphene_matrix_init_scale (&model_matrix, transformation->xscale, transformation->yscale, 1.0f); graphene_matrix_rotate (&model_matrix, transformation->xrotation, graphene_vec3_x_axis ()); graphene_matrix_rotate (&model_matrix, transformation->yrotation, graphene_vec3_y_axis ()); graphene_matrix_rotate (&model_matrix, transformation->zrotation, graphene_vec3_z_axis ()); graphene_matrix_translate (&model_matrix, &translation_vector); if (transformation->ortho) { graphene_matrix_init_ortho (&projection_matrix, -transformation->aspect, transformation->aspect, -1, 1, transformation->znear, transformation->zfar); } else { graphene_matrix_init_perspective (&projection_matrix, transformation->fov, transformation->aspect, transformation->znear, transformation->zfar); } graphene_matrix_init_look_at (&view_matrix, &eye, ¢er, &up); graphene_matrix_multiply (&view_matrix, &projection_matrix, &vp_matrix); graphene_matrix_multiply (&model_matrix, &vp_matrix, &transformation->mvp_matrix); }
GRAPHENE_TEST_UNIT_END GRAPHENE_TEST_UNIT_BEGIN (ray_get_distance_to_point) { graphene_ray_t r; graphene_point3d_t tmp = GRAPHENE_POINT3D_INIT (0, 0, 50); graphene_ray_init (&r, &one3, graphene_vec3_z_axis ()); if (g_test_verbose ()) g_test_message ("On the ray's origin..."); graphene_assert_fuzzy_equals (graphene_ray_get_distance_to_point (&r, &one3), 0.f, 0.00001); if (g_test_verbose ()) g_test_message ("Behind the ray..."); graphene_assert_fuzzy_equals (graphene_ray_get_distance_to_point (&r, &zero3), sqrtf (3.f), 0.00001); if (g_test_verbose ()) g_test_message ("On the ray..."); graphene_assert_fuzzy_equals (graphene_ray_get_distance_to_point (&r, &tmp), sqrtf (2.f), 0.00001); }