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