From 9d3b1f708fb6aae37fbdcf528804ab11b3b8e2f3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 19 Sep 2011 13:08:01 +0000 Subject: Move function out of mathutils to: BLI_math_rotation --- single_axis_angle_to_mat3(mat3, axis, angle), copied out from mathutils, axis arg is a char 'X/Y/Z' rather then a vector like axis_angle_to_mat3(). --- source/blender/blenlib/intern/math_rotation.c | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'source/blender/blenlib/intern/math_rotation.c') diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 6800b59c2c7..ef286e1d102 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -771,6 +771,52 @@ void mat4_to_axis_angle(float axis[3], float *angle,float mat[4][4]) quat_to_axis_angle(axis, angle,q); } + + +void single_axis_angle_to_mat3(float mat[3][3], const char axis, const float angle) +{ + const float angle_cos= cosf(angle); + const float angle_sin= sinf(angle); + + switch(axis) { + case 'X': /* rotation around X */ + mat[0][0] = 1.0f; + mat[0][1] = 0.0f; + mat[0][2] = 0.0f; + mat[1][0] = 0.0f; + mat[1][1] = angle_cos; + mat[1][2] = angle_sin; + mat[2][0] = 0.0f; + mat[2][1] = -angle_sin; + mat[2][2] = angle_cos; + break; + case 'Y': /* rotation around Y */ + mat[0][0] = angle_cos; + mat[0][1] = 0.0f; + mat[0][2] = -angle_sin; + mat[1][0] = 0.0f; + mat[1][1] = 1.0f; + mat[1][2] = 0.0f; + mat[2][0] = angle_sin; + mat[2][1] = 0.0f; + mat[2][2] = angle_cos; + break; + case 'Z': /* rotation around Z */ + mat[0][0] = angle_cos; + mat[0][1] = angle_sin; + mat[0][2] = 0.0f; + mat[1][0] = -angle_sin; + mat[1][1] = angle_cos; + mat[1][2] = 0.0f; + mat[2][0] = 0.0f; + mat[2][1] = 0.0f; + mat[2][2] = 1.0f; + break; + default: + assert("invalid axis"); + } +} + /****************************** Vector/Rotation ******************************/ /* TODO: the following calls should probably be depreceated sometime */ -- cgit v1.2.3