Blender  V2.59
BLI_math_rotation.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BLI_math_rotation.h 35954 2011-04-02 03:05:49Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: some of this file.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  * */
00027 
00028 #ifndef BLI_MATH_ROTATION_H
00029 #define BLI_MATH_ROTATION_H
00030 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 #define RAD2DEG(_rad) ((_rad)*(180.0/M_PI))
00040 #define DEG2RAD(_deg) ((_deg)*(M_PI/180.0))
00041 
00042 
00043 #define RAD2DEGF(_rad) ((_rad)*(float)(180.0/M_PI))
00044 #define DEG2RADF(_deg) ((_deg)*(float)(M_PI/180.0))
00045 
00046 /******************************** Quaternions ********************************/
00047 /* stored in (w, x, y, z) order                                              */
00048 
00049 /* init */
00050 void unit_axis_angle(float axis[3], float *angle);
00051 void unit_qt(float q[4]);
00052 void copy_qt_qt(float q[4], const float a[4]);
00053 
00054 /* arithmetic */
00055 void mul_qt_qtqt(float q[4], const float a[4], const float b[4]);
00056 void mul_qt_v3(const float q[4], float r[3]);
00057 void mul_qt_fl(float q[4], const float f);
00058 void mul_fac_qt_fl(float q[4], const float f);
00059 
00060 void sub_qt_qtqt(float q[4], const float a[4], const float b[4]);
00061 
00062 void invert_qt(float q[4]);
00063 void invert_qt_qt(float q1[4], const float q2[4]);
00064 void conjugate_qt(float q[4]);
00065 float dot_qtqt(const float a[4], const float b[4]);
00066 float normalize_qt(float q[4]);
00067 float normalize_qt_qt(float q1[4], const float q2[4]);
00068 
00069 /* comparison */
00070 int is_zero_qt(float q[4]);
00071 
00072 /* interpolation */
00073 void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t);
00074 void add_qt_qtqt(float q[4], const float a[4], const float b[4], const float t);
00075 
00076 /* conversion */
00077 void quat_to_mat3(float mat[3][3], const float q[4]);
00078 void quat_to_mat4(float mat[4][4], const float q[4]);
00079 
00080 void mat3_to_quat(float q[4], float mat[3][3]);
00081 void mat4_to_quat(float q[4], float mat[4][4]);
00082 void tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3]);
00083 void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag);
00084 /* note: v1 and v2 must be normalized */
00085 void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3]);
00086 void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4]);
00087 
00088 /* TODO: don't what this is, but it's not the same as mat3_to_quat */
00089 void mat3_to_quat_is_ok(float q[4], float mat[3][3]);
00090 
00091 /* other */
00092 void print_qt(const char *str, const float q[4]);
00093 
00094 /******************************** Axis Angle *********************************/
00095 
00096 /* conversion */
00097 void axis_angle_to_quat(float r[4], const float axis[3], float angle);
00098 void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle);
00099 void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle);
00100 
00101 void quat_to_axis_angle(float axis[3], float *angle, const float q[4]);
00102 void mat3_to_axis_angle(float axis[3], float *angle, float M[3][3]);
00103 void mat4_to_axis_angle(float axis[3], float *angle, float M[4][4]);
00104 
00105 /****************************** Vector/Rotation ******************************/
00106 /* old axis angle code                                                       */
00107 /* TODO: the following calls should probably be depreceated sometime         */
00108 
00109 /* conversion */
00110 void mat3_to_vec_rot(float vec[3], float *phi, float mat[3][3]);
00111 void mat4_to_vec_rot(float vec[3], float *phi, float mat[4][4]);
00112 
00113 void vec_rot_to_quat(float quat[4], const float vec[3], const float phi);
00114 void vec_rot_to_mat3(float mat[3][3], const float vec[3], const float phi);
00115 void vec_rot_to_mat4(float mat[4][4], const float vec[3], const float phi);
00116 
00117 /******************************** XYZ Eulers *********************************/
00118 
00119 void eul_to_quat(float quat[4], const float eul[3]);
00120 void eul_to_mat3(float mat[3][3], const float eul[3]);
00121 void eul_to_mat4(float mat[4][4], const float eul[3]);
00122 
00123 void quat_to_eul(float eul[3], const float quat[4]);
00124 void mat3_to_eul(float eul[3], float mat[3][3]);
00125 void mat4_to_eul(float eul[3], float mat[4][4]);
00126 
00127 void compatible_eul(float eul[3], const float old[3]);
00128 void mat3_to_compatible_eul(float eul[3], const float old[3], float mat[3][3]);
00129 
00130 void rotate_eul(float eul[3], const char axis, const float angle);
00131 
00132 /************************** Arbitrary Order Eulers ***************************/
00133 
00134 /* warning: must match the eRotationModes in DNA_action_types.h
00135  * order matters - types are saved to file. */
00136 
00137 typedef enum eEulerRotationOrders {
00138         EULER_ORDER_DEFAULT = 1, /* blender classic = XYZ */
00139         EULER_ORDER_XYZ = 1,
00140         EULER_ORDER_XZY,
00141         EULER_ORDER_YXZ,
00142         EULER_ORDER_YZX,
00143         EULER_ORDER_ZXY,
00144         EULER_ORDER_ZYX
00145         /* there are 6 more entries with dulpicate entries included */
00146 } eEulerRotationOrders;
00147 
00148 void eulO_to_quat(float quat[4], const float eul[3], const short order);
00149 void eulO_to_mat3(float mat[3][3], const float eul[3], const short order);
00150 void eulO_to_mat4(float mat[4][4], const float eul[3], const short order);
00151 void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order);
00152 void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order);
00153  
00154 void quat_to_eulO(float eul[3], const short order, const float quat[4]);
00155 void mat3_to_eulO(float eul[3], const short order, float mat[3][3]);
00156 void mat4_to_eulO(float eul[3], const short order, float mat[4][4]);
00157 void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle);
00158 
00159 void mat3_to_compatible_eulO(float eul[3], float old[3], short order, float mat[3][3]);
00160 void mat4_to_compatible_eulO(float eul[3], float old[3], short order, float mat[4][4]);
00161 
00162 void rotate_eulO(float eul[3], short order, char axis, float angle);
00163 
00164 /******************************* Dual Quaternions ****************************/
00165 
00166 typedef struct DualQuat {
00167         float quat[4];
00168         float trans[4];
00169 
00170         float scale[4][4];
00171         float scale_weight;
00172 } DualQuat;
00173 
00174 void copy_dq_dq(DualQuat *r, DualQuat *dq);
00175 void normalize_dq(DualQuat *dq, float totw);
00176 void add_weighted_dq_dq(DualQuat *r, DualQuat *dq, float weight);
00177 void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq);
00178 
00179 void mat4_to_dquat(DualQuat *r, float base[4][4], float M[4][4]);
00180 void dquat_to_mat4(float R[4][4], DualQuat *dq);
00181 
00182 void quat_apply_track(float quat[4], short axis, short upflag);
00183 void vec_apply_track(float vec[3], short axis);
00184 
00185 float lens_to_angle(float lens);
00186 float angle_to_lens(float angle);
00187 
00188 float angle_wrap_rad(float angle);
00189 float angle_wrap_deg(float angle);
00190 
00191 #ifdef __cplusplus
00192 }
00193 #endif
00194 
00195 #endif /* BLI_MATH_ROTATION_H */
00196