| 
									
										
										
										
											2011-02-18 13:58:08 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: some of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-17 18:59:41 +00:00
										 |  |  | #ifndef __BLI_MATH_ROTATION_H__
 | 
					
						
							|  |  |  | #define __BLI_MATH_ROTATION_H__
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-18 13:58:08 +00:00
										 |  |  | /** \file BLI_math_rotation.h
 | 
					
						
							|  |  |  |  *  \ingroup bli | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 20:39:39 +00:00
										 |  |  | #define RAD2DEG(_rad) ((_rad) * (180.0 / M_PI))
 | 
					
						
							|  |  |  | #define DEG2RAD(_deg) ((_deg) * (M_PI / 180.0))
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-27 14:52:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-12 20:39:39 +00:00
										 |  |  | #define RAD2DEGF(_rad) ((_rad) * (float)(180.0 / M_PI))
 | 
					
						
							|  |  |  | #define DEG2RADF(_deg) ((_deg) * (float)(M_PI / 180.0))
 | 
					
						
							| 
									
										
										
										
											2011-03-27 14:52:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | /******************************** Quaternions ********************************/ | 
					
						
							|  |  |  | /* stored in (w, x, y, z) order                                              */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* init */ | 
					
						
							| 
									
										
										
										
											2011-02-02 00:40:55 +00:00
										 |  |  | void unit_axis_angle(float axis[3], float *angle); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | void unit_qt(float q[4]); | 
					
						
							| 
									
										
										
										
											2010-07-26 00:11:14 +00:00
										 |  |  | void copy_qt_qt(float q[4], const float a[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* arithmetic */ | 
					
						
							| 
									
										
										
										
											2010-07-26 00:11:14 +00:00
										 |  |  | void mul_qt_qtqt(float q[4], const float a[4], const float b[4]); | 
					
						
							| 
									
										
										
										
											2010-08-02 00:08:01 +00:00
										 |  |  | void mul_qt_v3(const float q[4], float r[3]); | 
					
						
							|  |  |  | void mul_qt_fl(float q[4], const float f); | 
					
						
							|  |  |  | void mul_fac_qt_fl(float q[4], const float f); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void sub_qt_qtqt(float q[4], const float a[4], const float b[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void invert_qt(float q[4]); | 
					
						
							| 
									
										
										
										
											2010-12-07 01:56:32 +00:00
										 |  |  | void invert_qt_qt(float q1[4], const float q2[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | void conjugate_qt(float q[4]); | 
					
						
							| 
									
										
										
										
											2012-08-25 17:42:15 +00:00
										 |  |  | void conjugate_qt_qt(float q1[4], const float q2[4]); | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | float dot_qtqt(const float a[4], const float b[4]); | 
					
						
							| 
									
										
										
										
											2010-12-07 01:56:32 +00:00
										 |  |  | float normalize_qt(float q[4]); | 
					
						
							|  |  |  | float normalize_qt_qt(float q1[4], const float q2[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* comparison */ | 
					
						
							|  |  |  | int is_zero_qt(float q[4]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* interpolation */ | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void interp_qt_qtqt(float q[4], const float a[4], const float b[4], const float t); | 
					
						
							|  |  |  | void add_qt_qtqt(float q[4], const float a[4], const float b[4], const float t); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* conversion */ | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void quat_to_mat3(float mat[3][3], const float q[4]); | 
					
						
							|  |  |  | void quat_to_mat4(float mat[4][4], const float q[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void mat3_to_quat(float q[4], float mat[3][3]); | 
					
						
							|  |  |  | void mat4_to_quat(float q[4], float mat[4][4]); | 
					
						
							| 
									
										
										
										
											2012-09-25 00:20:42 +00:00
										 |  |  | void tri_to_quat_ex(float quat[4], const float v1[3], const float v2[3], const float v3[3], | 
					
						
							|  |  |  |                     const float no_orig[3]); | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void tri_to_quat(float q[4], const float a[3], const float b[3], const float c[3]); | 
					
						
							|  |  |  | void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag); | 
					
						
							| 
									
										
										
										
											2009-12-27 01:32:58 +00:00
										 |  |  | /* note: v1 and v2 must be normalized */ | 
					
						
							|  |  |  | void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2[3]); | 
					
						
							| 
									
										
										
										
											2010-07-26 00:11:14 +00:00
										 |  |  | void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:40:18 +00:00
										 |  |  | /* TODO: don't what this is, but it's not the same as mat3_to_quat */ | 
					
						
							|  |  |  | void mat3_to_quat_is_ok(float q[4], float mat[3][3]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | /* other */ | 
					
						
							| 
									
										
										
										
											2011-03-08 07:31:42 +00:00
										 |  |  | void print_qt(const char *str, const float q[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /******************************** Axis Angle *********************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* conversion */ | 
					
						
							| 
									
										
										
										
											2012-07-22 17:49:56 +00:00
										 |  |  | void axis_angle_to_quat(float r[4], const float axis[3], const float angle); | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle); | 
					
						
							|  |  |  | void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void quat_to_axis_angle(float axis[3], float *angle, const float q[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 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]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 13:08:01 +00:00
										 |  |  | void single_axis_angle_to_mat3(float R[3][3], const char axis, const float angle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | /****************************** Vector/Rotation ******************************/ | 
					
						
							|  |  |  | /* old axis angle code                                                       */ | 
					
						
							| 
									
										
										
										
											2012-09-26 20:05:38 +00:00
										 |  |  | /* TODO: the following calls should probably be deprecated sometime         */ | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* conversion */ | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void vec_rot_to_mat3(float mat[3][3], const float vec[3], const float phi); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /******************************** XYZ Eulers *********************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void eul_to_quat(float quat[4], const float eul[3]); | 
					
						
							|  |  |  | void eul_to_mat3(float mat[3][3], const float eul[3]); | 
					
						
							|  |  |  | void eul_to_mat4(float mat[4][4], const float eul[3]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void quat_to_eul(float eul[3], const float quat[4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | void mat3_to_eul(float eul[3], float mat[3][3]); | 
					
						
							|  |  |  | void mat4_to_eul(float eul[3], float mat[4][4]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void compatible_eul(float eul[3], const float old[3]); | 
					
						
							|  |  |  | void mat3_to_compatible_eul(float eul[3], const float old[3], float mat[3][3]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void rotate_eul(float eul[3], const char axis, const float angle); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /************************** Arbitrary Order Eulers ***************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* warning: must match the eRotationModes in DNA_action_types.h
 | 
					
						
							|  |  |  |  * order matters - types are saved to file. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum eEulerRotationOrders { | 
					
						
							|  |  |  | 	EULER_ORDER_DEFAULT = 1, /* blender classic = XYZ */ | 
					
						
							|  |  |  | 	EULER_ORDER_XYZ = 1, | 
					
						
							|  |  |  | 	EULER_ORDER_XZY, | 
					
						
							|  |  |  | 	EULER_ORDER_YXZ, | 
					
						
							|  |  |  | 	EULER_ORDER_YZX, | 
					
						
							|  |  |  | 	EULER_ORDER_ZXY, | 
					
						
							| 
									
										
										
										
											2010-12-03 01:52:28 +00:00
										 |  |  | 	EULER_ORDER_ZYX | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 	/* there are 6 more entries with dulpicate entries included */ | 
					
						
							|  |  |  | } eEulerRotationOrders; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void eulO_to_quat(float quat[4], const float eul[3], const short order); | 
					
						
							|  |  |  | void eulO_to_mat3(float mat[3][3], const float eul[3], const short order); | 
					
						
							|  |  |  | void eulO_to_mat4(float mat[4][4], const float eul[3], const short order); | 
					
						
							|  |  |  | void eulO_to_axis_angle(float axis[3], float *angle, const float eul[3], const short order); | 
					
						
							|  |  |  | void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2010-10-22 03:56:50 +00:00
										 |  |  | void quat_to_eulO(float eul[3], const short order, const float quat[4]); | 
					
						
							|  |  |  | void mat3_to_eulO(float eul[3], const short order, float mat[3][3]); | 
					
						
							|  |  |  | void mat4_to_eulO(float eul[3], const short order, float mat[4][4]); | 
					
						
							|  |  |  | void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-25 12:55:14 +00:00
										 |  |  | void mat3_to_compatible_eulO(float eul[3], float old[3], const short order, float mat[3][3]); | 
					
						
							|  |  |  | void mat4_to_compatible_eulO(float eul[3], float old[3], const short order, float mat[4][4]); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-25 12:55:14 +00:00
										 |  |  | void rotate_eulO(float eul[3], const short order, char axis, float angle); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /******************************* Dual Quaternions ****************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct DualQuat { | 
					
						
							|  |  |  | 	float quat[4]; | 
					
						
							|  |  |  | 	float trans[4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float scale[4][4]; | 
					
						
							|  |  |  | 	float scale_weight; | 
					
						
							|  |  |  | } DualQuat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void copy_dq_dq(DualQuat *r, DualQuat *dq); | 
					
						
							|  |  |  | void normalize_dq(DualQuat *dq, float totw); | 
					
						
							|  |  |  | void add_weighted_dq_dq(DualQuat *r, DualQuat *dq, float weight); | 
					
						
							| 
									
										
										
										
											2013-03-26 07:29:01 +00:00
										 |  |  | void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-26 07:29:01 +00:00
										 |  |  | void mat4_to_dquat(DualQuat *r, float base[4][4], float M[4][4]); | 
					
						
							|  |  |  | void dquat_to_mat4(float R[4][4], DualQuat *dq); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-08 07:29:08 +00:00
										 |  |  | void quat_apply_track(float quat[4], short axis, short upflag); | 
					
						
							| 
									
										
										
										
											2010-10-08 02:08:11 +00:00
										 |  |  | void vec_apply_track(float vec[3], short axis); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-04 14:36:06 +00:00
										 |  |  | float focallength_to_fov(float focal_length, float sensor); | 
					
						
							|  |  |  | float fov_to_focallength(float fov, float sensor); | 
					
						
							| 
									
										
										
										
											2010-04-17 08:55:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-02 03:05:49 +00:00
										 |  |  | float angle_wrap_rad(float angle); | 
					
						
							|  |  |  | float angle_wrap_deg(float angle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-19 04:37:28 +00:00
										 |  |  | float angle_compat_rad(float angle, float angle_compat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | int mat3_from_axis_conversion(int from_forward, int from_up, int to_forward, int to_up, | 
					
						
							|  |  |  |                               float r_mat[3][3]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-17 18:59:41 +00:00
										 |  |  | #endif /* __BLI_MATH_ROTATION_H__ */
 | 
					
						
							| 
									
										
										
										
											2009-11-09 22:42:41 +00:00
										 |  |  | 
 |