TEST_F(QuaternionTest, creating_matrix_from_quaternion_gives_correct_matrix) { const auto quat = create_random_quaternion(); const auto res = quaternion_to_matrix(quat); const auto correct = make_matrix_from_quaternion(quat); for (auto i = 0; i < 16; ++i) { EXPECT_EQ(correct[i], res[i]); } }
/*! Interpolates between camera orientations \pre p_up2, p_dir2 != NULL; *p_up2 is the target up vector; *p_dir2 is the target view direction \arg \c up1 original up vector \arg \c dir1 original view direction \arg \c p_up2 pointer to target up vector; is overwritten with interpolated up vector \arg \c p_dir2 pointer to target view direction; is overwritten with interpolated view direction \arg \c dt time step \arg \c time_constant interpolation time constant \return none \author jfpatry \date Created: 2000-08-26 \date Modified: 2000-08-26 */ void interpolate_view_frame( vector_t up1, vector_t dir1, vector_t *p_up2, vector_t *p_dir2, scalar_t dt, scalar_t time_constant ) { quaternion_t q1, q2; scalar_t alpha; vector_t x1, y1, z1; vector_t x2, y2, z2; matrixgl_t cob_mat1, inv_cob_mat1; matrixgl_t cob_mat2, inv_cob_mat2; /* Now interpolate between camera orientations */ z1 = scale_vector( -1.0, dir1 ); normalize_vector( &z1 ); y1 = project_into_plane( z1, up1 ); normalize_vector( &y1 ); x1 = cross_product( y1, z1 ); make_change_of_basis_matrix( cob_mat1, inv_cob_mat1, x1, y1, z1 ); q1 = make_quaternion_from_matrix( cob_mat1 ); z2 = scale_vector( -1.0, *p_dir2 ); normalize_vector( &z2 ); y2 = project_into_plane( z2, *p_up2 ); normalize_vector( &y2 ); x2 = cross_product( y2, z2 ); make_change_of_basis_matrix( cob_mat2, inv_cob_mat2, x2, y2, z2 ); q2 = make_quaternion_from_matrix( cob_mat2 ); alpha = min( MAX_INTERPOLATION_VALUE, 1.0 - exp( -dt / time_constant ) ); q2 = interpolate_quaternions( q1, q2, alpha ); make_matrix_from_quaternion( cob_mat2, q2 ); p_up2->x = cob_mat2[1][0]; p_up2->y = cob_mat2[1][1]; p_up2->z = cob_mat2[1][2]; p_dir2->x = -cob_mat2[2][0]; p_dir2->y = -cob_mat2[2][1]; p_dir2->z = -cob_mat2[2][2]; }