Math Lib: rotate matrix cleanup

- Remove 'rotate_m2', unlike 'rotate_m4' it created a new matrix
  duplicating 'angle_to_mat2' - now used instead.
  (better avoid matching functions having different behavior).

- Add 'axis_angle_to_mat4_single',
  convenience wrapper for 'axis_angle_to_mat3_single'.

- Replace 'unit_m4(), rotate_m4()' with a single call to 'axis_angle_to_mat4_single'.
This commit is contained in:
Campbell Barton 2016-11-25 16:20:30 +11:00
parent d30a0239a2
commit e1e49fd1a8
Notes: blender-bot 2023-10-04 09:42:55 +02:00
Referenced by commit cc1a64be36, Math lib: Fix use function of wrong dimension
15 changed files with 32 additions and 36 deletions

View File

@ -92,8 +92,7 @@ void AbcTransformWriter::do_write()
/* Only apply rotation to root camera, parenting will propagate it. */
if (m_object->type == OB_CAMERA && !has_parent_camera(m_object)) {
float rot_mat[4][4];
unit_m4(rot_mat);
rotate_m4(rot_mat, 'X', -M_PI_2);
axis_angle_to_mat4_single(rot_mat, 'X', -M_PI_2);
mul_m4_m4m4(mat, mat, rot_mat);
}

View File

@ -221,8 +221,7 @@ void convert_matrix(const Imath::M44d &xform, Object *ob,
if (ob->type == OB_CAMERA) {
float cam_to_yup[4][4];
unit_m4(cam_to_yup);
rotate_m4(cam_to_yup, 'X', M_PI_2);
axis_angle_to_mat4_single(cam_to_yup, 'X', M_PI_2);
mul_m4_m4m4(r_mat, r_mat, cam_to_yup);
}

View File

@ -642,8 +642,7 @@ static void make_duplis_font(const DupliContext *ctx)
float rmat[4][4];
zero_v3(obmat[3]);
unit_m4(rmat);
rotate_m4(rmat, 'Z', -ct->rot);
axis_angle_to_mat4_single(rmat, 'Z', -ct->rot);
mul_m4_m4m4(obmat, obmat, rmat);
}

View File

@ -587,7 +587,7 @@ static void compensate_rotation_center(const int size, float aspect,
copy_v2_v2(intended_pivot, pivot);
copy_v2_v2(rotated_pivot, pivot);
rotate_m2(rotation_mat, +angle);
angle_to_mat2(rotation_mat, +angle);
sub_v2_v2(rotated_pivot, origin);
mul_m2v2(rotation_mat, rotated_pivot);
mul_v2_fl(rotated_pivot, scale);
@ -967,7 +967,7 @@ static void initialize_track_for_stabilization(StabContext *ctx,
pos[0] *= aspect;
angle = average_angle - atan2f(pos[1],pos[0]);
rotate_m2(local_data->stabilization_rotation_base, angle);
angle_to_mat2(local_data->stabilization_rotation_base, angle);
/* Per track baseline value for zoom. */
len = len_v2(pos) + SCALE_ERROR_LIMIT_BIAS;

View File

@ -219,7 +219,6 @@ void mat4_to_size(float r[3], float M[4][4]);
void translate_m4(float mat[4][4], float tx, float ty, float tz);
void rotate_m4(float mat[4][4], const char axis, const float angle);
void rotate_m2(float mat[2][2], const float angle);
void transform_pivot_set_m4(float mat[4][4], const float pivot[3]);
void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]);

View File

@ -122,8 +122,9 @@ void mat3_to_axis_angle(float axis[3], float *angle, float M[3][3]);
void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]);
void quat_to_axis_angle(float axis[3], float *angle, const float q[4]);
void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle);
void angle_to_mat2(float R[2][2], const float angle);
void axis_angle_to_mat3_single(float R[3][3], const char axis, const float angle);
void axis_angle_to_mat4_single(float R[4][4], const char axis, const float angle);
void axis_angle_to_quat_single(float q[4], const char axis, const float angle);

View File

@ -3917,10 +3917,9 @@ void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py
float sine, cosine, hyp, hyp1, dx, dy, dz;
float mat1[4][4];
unit_m4(mat);
unit_m4(mat1);
rotate_m4(mat, 'Z', -twist);
axis_angle_to_mat3_single(mat, 'Z', -twist);
dx = px - vx;
dy = py - vy;

View File

@ -1625,6 +1625,13 @@ void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
mat[3][2] += (Tx * mat[0][2] + Ty * mat[1][2] + Tz * mat[2][2]);
}
/**
* Rotate a matrix in-place.
*
* \note To create a new rotation matrix see:
* #axis_angle_to_mat4_single, #axis_angle_to_mat3_single, #angle_to_mat2
* (axis & angle args are compatible).
*/
void rotate_m4(float mat[4][4], const char axis, const float angle)
{
int col;
@ -1665,13 +1672,6 @@ void rotate_m4(float mat[4][4], const char axis, const float angle)
}
}
void rotate_m2(float mat[2][2], const float angle)
{
mat[0][0] = mat[1][1] = cosf(angle);
mat[0][1] = sinf(angle);
mat[1][0] = -mat[0][1];
}
/**
* Scale or rotate around a pivot point,
* a convenience function to avoid having to do inline.

View File

@ -1009,6 +1009,13 @@ void mat4_to_axis_angle(float axis[3], float *angle, float mat[4][4])
quat_to_axis_angle(axis, angle, q);
}
void axis_angle_to_mat4_single(float mat[4][4], const char axis, const float angle)
{
float mat3[3][3];
axis_angle_to_mat3_single(mat3, axis, angle);
copy_m4_m3(mat, mat3);
}
/* rotation matrix from a single axis */
void axis_angle_to_mat3_single(float mat[3][3], const char axis, const float angle)
{

View File

@ -33,11 +33,8 @@
UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP)
{
unit_m4(x_up_mat4);
rotate_m4(x_up_mat4, 'Y', -0.5 * M_PI);
unit_m4(y_up_mat4);
rotate_m4(y_up_mat4, 'X', 0.5 * M_PI);
axis_angle_to_mat4_single(x_up_mat4, 'Y', -0.5 * M_PI);
axis_angle_to_mat4_single(y_up_mat4, 'X', 0.5 * M_PI);
unit_m4(z_up_mat4);
unit_m4(scale_mat4);

View File

@ -2140,7 +2140,7 @@ static float snap_v2_angle(float r[2], const float v[2], const float v_ref[2], f
normalize_v2_v2(v_unit, v);
angle = angle_signed_v2v2(v_unit, v_ref);
angle_delta = (roundf(angle / angle_snap) * angle_snap) - angle;
rotate_m2(m2, angle_delta);
angle_to_mat2(m2, angle_delta);
mul_v2_m2v2(r, m2, v);
return angle + angle_delta;

View File

@ -53,8 +53,7 @@ static void object_warp_calc_view_matrix(float r_mat_view[4][4], float r_center_
float viewmat_roll[4][4];
/* apply the rotation offset by rolling the view */
unit_m4(mat_offset);
rotate_m4(mat_offset, 'Z', offset_angle);
axis_angle_to_mat4_single(mat_offset, 'Z', offset_angle);
mul_m4_m4m4(viewmat_roll, mat_offset, viewmat);
/* apply the view and the object matrix */

View File

@ -821,10 +821,9 @@ static float calc_overlap(StrokeCache *cache, const char symm, const char axis,
flip_v3_v3(mirror, cache->true_location, symm);
if (axis != 0) {
float mat[4][4];
unit_m4(mat);
rotate_m4(mat, axis, angle);
mul_m4_v3(mat, mirror);
float mat[3][3];
axis_angle_to_mat3_single(mat, axis, angle);
mul_m3_v3(mat, mirror);
}
/* distsq = len_squared_v3v3(mirror, cache->traced_location); */

View File

@ -459,7 +459,7 @@ static void stitch_calculate_island_snapping(
island_stitch_data[i].num_rot_elements_neg) / totelem;
}
rotate_m2(rotation_mat, rotation);
angle_to_mat2(rotation_mat, rotation);
numOfIslandUVs = getNumOfIslandUvs(state->element_map, i);
element = &state->element_map->buf[state->element_map->islandIndices[i]];
for (j = 0; j < numOfIslandUVs; j++, element++) {

View File

@ -798,13 +798,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if (ltmd->ob_axis) {
axis_angle_normalized_to_mat3(mat3, axis_vec, step_angle);
copy_m4_m3(mat, mat3);
}
else {
unit_m4(mat);
rotate_m4(mat, axis_char, step_angle);
copy_m3_m4(mat3, mat);
axis_angle_to_mat3_single(mat3, axis_char, step_angle);
}
copy_m4_m3(mat, mat3);
if (screw_ofs)
madd_v3_v3fl(mat[3], axis_vec, screw_ofs * ((float)step / (float)(step_tot - 1)));