diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-09-12 09:06:28 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-09-12 09:06:28 +0400 |
commit | 83074d0b3758c1b2d2811974726d4dd33f3034da (patch) | |
tree | 6ef4208631de9435d71cdd29637ee9ca329f6e68 /source/blender/blenlib | |
parent | f0eb02a36b5a04d18a1a587b1e36419daa6a6f23 (diff) |
2.5 - More work on Axis-Angle Rotations
* Added a few new methods for axis-angle conversions, and used these instead of manually performing those steps elsewhere
* Axis-angles to other representations now get their axes normalised to make sure that odd scaling doesn't occur.
* Made a few more tools work with axis-angles properly
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_arithb.h | 21 | ||||
-rw-r--r-- | source/blender/blenlib/intern/arithb.c | 89 |
2 files changed, 102 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index 71604758b80..8eb4d5972e3 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -342,8 +342,6 @@ void Mat4AddMat4(float m1[][4], float m2[][4], float m3[][4]); void VecUpMat3old(float *vec, float mat[][3], short axis); void VecUpMat3(float *vec, float mat[][3], short axis); -void VecRotToMat3(float *vec, float phi, float mat[][3]); -void VecRotToMat4(float *vec, float phi, float mat[][4]); void VecCopyf(float *v1, float *v2); int VecLen(int *v1, int *v2); @@ -376,10 +374,23 @@ void Vec2Subf(float *v, float *v1, float *v2); void Vec2Copyf(float *v1, float *v2); void Vec2Lerpf(float *target, float *a, float *b, float t); -void AxisAngleToQuat(float *q, float *axis, float angle); -void QuatToAxisAngle(float *q, float *axis, float *angle); +void AxisAngleToQuat(float q[4], float axis[3], float angle); +void QuatToAxisAngle(float q[4], float axis[3], float *angle); +void AxisAngleToEulO(float axis[3], float angle, float eul[3], short order); +void EulOToAxisAngle(float eul[3], short order, float axis[3], float *angle); +void AxisAngleToMat3(float axis[3], float angle, float mat[3][3]); +void AxisAngleToMat4(float axis[3], float angle, float mat[4][4]); +void Mat3ToAxisAngle(float mat[3][3], float axis[3], float *angle); +void Mat4ToAxisAngle(float mat[4][4], float axis[3], float *angle); + +void Mat3ToVecRot(float mat[3][3], float axis[3], float *angle); +void Mat4ToVecRot(float mat[4][4], float axis[3], float *angle); +void VecRotToMat3(float *vec, float phi, float mat[][3]); +void VecRotToMat4(float *vec, float phi, float mat[][4]); + void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]); void vectoquat(float *vec, short axis, short upflag, float *q); +void Mat3ToQuat_is_ok(float wmat[][3], float *q); void VecReflect(float *out, float *v1, float *v2); void VecBisect3(float *v, float *v1, float *v2, float *v3); @@ -460,8 +471,6 @@ void VecStar(float mat[][3],float *vec); short EenheidsMat(float mat[][3]); -void Mat3ToQuat_is_ok(float wmat[][3], float *q); - void i_ortho(float left, float right, float bottom, float top, float nearClip, float farClip, float matrix[][4]); void i_polarview(float dist, float azimuth, float incidence, float twist, float Vm[][4]); void i_translate(float Tx, float Ty, float Tz, float mat[][4]); diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index 96056ba7783..1839380f953 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -3278,7 +3278,7 @@ void Mat3ToCompatibleEul(float mat[][3], float *eul, float *oldrot) /* ************ AXIS ANGLE *************** */ /* Axis angle to Quaternions */ -void AxisAngleToQuat(float *q, float *axis, float angle) +void AxisAngleToQuat(float q[4], float axis[3], float angle) { float nor[3]; float si; @@ -3315,6 +3315,90 @@ void QuatToAxisAngle(float q[4], float axis[3], float *angle) axis[2]= q[3] / si; } +/* Axis Angle to Euler Rotation */ +void AxisAngleToEulO(float axis[3], float angle, float eul[3], short order) +{ + float q[4]; + + /* use quaternions as intermediate representation for now... */ + AxisAngleToQuat(q, axis, angle); + QuatToEulO(q, eul, order); +} + +/* Euler Rotation to Axis Angle */ +void EulOToAxisAngle(float eul[3], short order, float axis[3], float *angle) +{ + float q[4]; + + /* use quaternions as intermediate representation for now... */ + EulOToQuat(eul, order, q); + QuatToAxisAngle(q, axis, angle); +} + +/* axis angle to 3x3 matrix - safer version (normalisation of axis performed) */ +void AxisAngleToMat3(float axis[3], float angle, float mat[3][3]) +{ + float nor[3]; + + /* normalise the axis first (to remove unwanted scaling) */ + VecCopyf(nor, axis); + Normalize(nor); + + /* now convert this to a 3x3 matrix */ + VecRotToMat3(nor, angle, mat); +} + +/* axis angle to 4x4 matrix - safer version (normalisation of axis performed) */ +void AxisAngleToMat4(float axis[3], float angle, float mat[4][4]) +{ + float nor[3]; + + /* normalise the axis first (to remove unwanted scaling) */ + VecCopyf(nor, axis); + Normalize(nor); + + /* now convert this to a 4x4 matrix */ + VecRotToMat4(nor, angle, mat); +} + +/* 3x3 matrix to axis angle (alias around the other call) */ +void Mat3ToAxisAngle(float mat[3][3], float axis[3], float *angle) +{ + /* note different order of calling args... */ + Mat3ToVecRot(axis, angle, mat); +} + +/* 4x4 matrix to axis angle (alias around the other call) */ +void Mat4ToAxisAngle(float mat[4][4], float axis[3], float *angle) +{ + /* note different order of calling args... */ + Mat4ToVecRot(axis, angle, mat); +} + +/* ************ AXIS ANGLE (unchecked) *************** */ + +/* 3x3 matrix to axis angle */ +void Mat3ToVecRot(float mat[3][3], float axis[3], float *angle) +{ + float q[4]; + + /* use quaternions as intermediate representation */ + // TODO: it would be nicer to go straight there... + Mat3ToQuat(mat, q); + QuatToAxisAngle(q, axis, angle); +} + +/* 4x4 matrix to axis angle */ +void Mat4ToVecRot(float mat[4][4], float axis[3], float *angle) +{ + float q[4]; + + /* use quaternions as intermediate representation */ + // TODO: it would be nicer to go straight there... + Mat4ToQuat(mat, q); + QuatToAxisAngle(q, axis, angle); +} + /* axis angle to 3x3 matrix */ void VecRotToMat3(float *vec, float phi, float mat[][3]) { @@ -3339,7 +3423,6 @@ void VecRotToMat3(float *vec, float phi, float mat[][3]) mat[2][0]= vz*vx*(1.0f-co)+vy*si; mat[2][1]= vy*vz*(1.0f-co)-vx*si; mat[2][2]= vz2+co*(1.0f-vz2); - } /* axis angle to 4x4 matrix */ @@ -3374,6 +3457,8 @@ void VecRotToQuat(float *vec, float phi, float *quat) } } +/* ************ VECTORS *************** */ + /* Returns a vector bisecting the angle at v2 formed by v1, v2 and v3 */ void VecBisect3(float *out, float *v1, float *v2, float *v3) { |