Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-09-19 17:08:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-09-19 17:08:01 +0400
commit9d3b1f708fb6aae37fbdcf528804ab11b3b8e2f3 (patch)
treea23865d416cbc736d31ae1c0a28f9480b21aa742
parentf157a543c6a11e072b9bd36218f97f869d525eb1 (diff)
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().
-rw-r--r--source/blender/blenlib/BLI_math_rotation.h2
-rw-r--r--source/blender/blenlib/intern/math_rotation.c46
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c43
3 files changed, 58 insertions, 33 deletions
diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h
index ef20408a37e..d7ca03243df 100644
--- a/source/blender/blenlib/BLI_math_rotation.h
+++ b/source/blender/blenlib/BLI_math_rotation.h
@@ -102,6 +102,8 @@ void quat_to_axis_angle(float axis[3], float *angle, const float q[4]);
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 single_axis_angle_to_mat3(float R[3][3], const char axis, const float angle);
+
/****************************** Vector/Rotation ******************************/
/* old axis angle code */
/* TODO: the following calls should probably be depreceated sometime */
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 */
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 3953171f263..2da96dc62e6 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -266,42 +266,19 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
axis_angle_to_mat3((float (*)[3])mat, tvec, angle);
}
- else if(matSize == 2) {
+ else if (matSize == 2) {
+ const float angle_cos= cosf(angle);
+ const float angle_sin= sinf(angle);
+
//2D rotation matrix
- mat[0] = (float) cos (angle);
- mat[1] = (float) sin (angle);
- mat[2] = -((float) sin(angle));
- mat[3] = (float) cos(angle);
- }
- else if(strcmp(axis, "X") == 0) {
- //rotation around X
- mat[0] = 1.0f;
- mat[4] = (float) cos(angle);
- mat[5] = (float) sin(angle);
- mat[7] = -((float) sin(angle));
- mat[8] = (float) cos(angle);
- }
- else if(strcmp(axis, "Y") == 0) {
- //rotation around Y
- mat[0] = (float) cos(angle);
- mat[2] = -((float) sin(angle));
- mat[4] = 1.0f;
- mat[6] = (float) sin(angle);
- mat[8] = (float) cos(angle);
- }
- else if(strcmp(axis, "Z") == 0) {
- //rotation around Z
- mat[0] = (float) cos(angle);
- mat[1] = (float) sin(angle);
- mat[3] = -((float) sin(angle));
- mat[4] = (float) cos(angle);
- mat[8] = 1.0f;
+ mat[0] = angle_cos;
+ mat[1] = angle_sin;
+ mat[2] = -angle_sin;
+ mat[3] = angle_cos;
}
else {
- /* should never get here */
- PyErr_SetString(PyExc_ValueError,
- "mathutils.RotationMatrix(): unknown error");
- return NULL;
+ /* valid axis checked above */
+ single_axis_angle_to_mat3((float (*)[3])mat, axis[0], angle);
}
if(matSize == 4) {