00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00026 #pragma once
00027 #endif
00028
00029
00030
00031
00032
00033 #ifndef _ROTATION_H_
00034 #define _ROTATION_H_
00035
00036
00037
00038
00039
00040 #include "SIBCMathLib.h"
00041
00042
00043
00044
00045
00046
00056 double F3DArcSinCos( double dSinus, double dCosinus );
00057
00063 void F3DLimit( double& io_dVal, double in_dMin, double in_dMax );
00064
00069 void F3DQuatToMat( const CSIBCQuaterniond& in_quat, CSIBCRotMatd& out_mat );
00070
00075 void F3DMatToQuat( const CSIBCRotMatd& in_mat, CSIBCQuaterniond& out_quat );
00076
00081 void F3DEulerToQuat( const CSIBCVector3Dd& in_vct, CSIBCQuaterniond& out_quat );
00082
00087 void F3DEulerToMat( const CSIBCVector3Dd& in_vct, CSIBCRotMatd& out_mat );
00088
00093 void F3DMatToEuler( const CSIBCRotMatd& in_mat, CSIBCVector3Dd& out_vct );
00094
00104 void F3DMatToEulerUsingTarget( const CSIBCRotMatd& in_mat, CSIBCVector3Dd& inout_vct );
00105
00111 void F3DQuatToAxisAngle( const CSIBCQuaterniond& in_quat, CSIBCVector3Dd& out_vctAxis, double& out_dAngle );
00112
00118 void F3DAxisAngleToQuat( const CSIBCVector3Dd& in_vctAxis, const double& in_dAngle, CSIBCQuaterniond& out_quat );
00119
00120
00121
00127 double F3DBoundAngleInMinus2PITo2PI( double in_dDesiredAngle);
00128
00134 void F3DBoundAngleInZeroToTwoPI( double& in_dAngle );
00135
00141 void F3DBoundAngleInMinusPIToPI( double& in_dAngle );
00142
00150 double F3DGetUnboundedAngle( double in_dDesiredAngle, double in_dRefAngle );
00151
00160 void F3DBoundAnglesInMatrixInMinus2PITo2PI( CSIBCMatrixMNd &io_matMN, int in_nFirstRow, int in_nLastRow );
00161
00170 double F3DGetClosestAngle( double in_dAngle, double in_dFirstAngle, double in_dSecondAngle );
00171
00174
00175
00176
00177
00178
00179 #define MASK_ORIGREP 0x03
00180 #define BITVAL_ORIGREP_QUATERNION 0x00
00181 #define BITVAL_ORIGREP_ROTATION_MATRIX 0x01
00182 #define BITVAL_ORIGREP_EULER_ANGLES 0x02
00183
00184 #define MASK_ISQUAT_DIRTY (1 << 2 ) // 00000100
00185 #define MASK_ISMAT_DIRTY (1 << 3 ) // 00001000
00186 #define MASK_ISANGLES_DIRTY (1 << 4 ) // 00010000
00187
00188
00189 typedef enum tagE3DROTREPTYPE
00190 {
00191 QUATERNION_REP = BITVAL_ORIGREP_QUATERNION,
00192 ROTATION_MATRIX_REP = BITVAL_ORIGREP_ROTATION_MATRIX,
00193 EULER_ANGLES_REP = BITVAL_ORIGREP_EULER_ANGLES
00194 } E3DRotRepType;
00195
00196
00197
00198
00199
00200
00202
00214 class XSICOREEXPORT CSIBCRotationd
00215 {
00216
00217 public:
00218
00219
00220
00221
00226 CSIBCRotationd();
00227
00232 CSIBCRotationd( const CSIBCQuaterniond& in_quat );
00233
00238 CSIBCRotationd( const CSIBCRotMatd& in_matRot );
00239
00245 CSIBCRotationd( const CSIBCVector3Dd& in_vctXYZAngles );
00246
00253 CSIBCRotationd( double in_dX, double in_dY, double in_dZ );
00254
00260 CSIBCRotationd( const E3DAxisType in_axis, const double in_dAngle );
00261
00267 CSIBCRotationd( const CSIBCVector3Dd& in_vctAxis,
00268 const double in_dAngle );
00269
00276 CSIBCRotationd( const CSIBCVector3Dd& in_vctFrom,
00277 const CSIBCVector3Dd& in_vctTo );
00278
00279 ~CSIBCRotationd();
00280
00286 CSIBCRotationd& SetIdentity();
00287
00295 bool IsIdentity();
00296
00306 bool IsAlmostIdentity(const double& in_rdTolerance = PICO_EPS) const;
00307
00315 CSIBCQuaterniond& GetQuat( CSIBCQuaterniond& out_quat );
00316
00326 const CSIBCRotMatd* GetMatrix();
00327
00337 CSIBCRotMatd& GetMatrix( CSIBCRotMatd& out_matRot );
00338
00349 CSIBCVector3Dd& GetXYZAngles( CSIBCVector3Dd& out_vctXYZAngles );
00350
00361 void GetXYZAngles( double& out_dX, double& out_dY, double& out_dZ );
00362
00371 void GetAxisAngle( CSIBCVector3Dd& out_vctAxis, double& out_dAngle );
00372
00378 CSIBCRotationd& Set( const CSIBCRotationd& in_rot );
00379
00385 CSIBCRotationd& Set( const CSIBCQuaterniond& in_quat );
00386
00392 CSIBCRotationd& Set( const CSIBCRotMatd& in_matRot );
00393
00401 CSIBCRotationd& Set( const CSIBCVector3Dd& in_vctXYZAngles );
00402
00411 CSIBCRotationd& Set( double in_dX, double in_dY, double in_dZ );
00412
00421 CSIBCRotationd& Set( const E3DAxisType in_axis, const double in_dAngle );
00422
00431 CSIBCRotationd& Set( const CSIBCVector3Dd& in_vctAxis, const double in_dAngle );
00432
00433
00446 bool Set( const CSIBCVector3Dd& in_vctFrom, const CSIBCVector3Dd& in_vctTo, int& out_bFlip );
00447
00455 CSIBCRotationd& Set( const CSIBCVector3Dd& in_vctX, const CSIBCVector3Dd& in_vctY,
00456 const CSIBCVector3Dd& in_vctZ );
00457
00471 bool MinAlignToX( const CSIBCVector3Dd& in_vct, int& out_bFlip );
00472
00486 bool MinAlignToY( const CSIBCVector3Dd& in_vct, int& out_bFlip );
00487
00501 bool MinAlignToZ( const CSIBCVector3Dd& in_vct, int& out_bFlip );
00502
00515 bool AlignToX( const CSIBCVector3Dd& in_vct, int& out_bFlip );
00516
00529 bool AlignToY( const CSIBCVector3Dd& in_vct, int& out_bFlip );
00530
00543 bool AlignToZ( const CSIBCVector3Dd& in_vct, int& out_bFlip );
00544
00563 bool AlignAxesToVct( const E3DAxisType in_eFirstAxis,
00564 const CSIBCVector3Dd& in_vct1,
00565 const E3DAxisType in_eSecondAxis,
00566 const CSIBCVector3Dd& in_vct2,
00567 int& out_bFlip );
00568
00579 CSIBCRotationd& Mul( CSIBCRotationd& in_rot1, CSIBCRotationd& in_rot2 );
00580
00590 CSIBCRotationd& Mul( CSIBCRotationd& in_rot );
00591
00601 CSIBCRotationd& LeftMul( CSIBCRotationd& in_rot );
00602
00616 CSIBCRotationd& MulUsingEulerAnglesTarget( CSIBCRotationd& in_rot1,
00617 CSIBCRotationd& in_rot2,
00618 CSIBCVector3Dd& in_oEulerAngles );
00619
00620
00635 CSIBCRotationd& MulAndUpdateEulerAngles( CSIBCRotationd& in_rot1,
00636 CSIBCRotationd& in_rot2,
00637 ULONG in_ulUseRot1OrUseRot2AsTarget);
00638
00639
00645 CSIBCRotationd& Invert( CSIBCRotationd& in_rot );
00646
00651 CSIBCRotationd& Invert();
00652
00660 CSIBCRotationd& Interpolate( CSIBCRotationd& in_rot1,
00661 CSIBCRotationd& in_rot2,
00662 const double in_dU );
00663
00671 CSIBCVector3Dd& RotateVct( const CSIBCVector3Dd& in_vct, CSIBCVector3Dd& out_vct );
00672
00680 void RotateVct( const CSIBCVector3Dd *in_vcts,
00681 const LONG in_lNbVcts,
00682 CSIBCVector3Dd *out_vcts );
00683
00691 CSIBCVector3Dd& InvRotateVct( const CSIBCVector3Dd& in_vct, CSIBCVector3Dd& out_vct );
00692
00700 void InvRotateVct( const CSIBCVector3Dd *in_vcts,
00701 const LONG in_lNbVcts,
00702 CSIBCVector3Dd *out_vcts );
00703
00715 friend CSIBCVector3Dd& MapDirSpaceToWorld(
00716 CSIBCRotationd& in_rotFrom,
00717 const CSIBCVector3Dd& in_vctDir,
00718 CSIBCVector3Dd& out_vctDir );
00719
00730 friend CSIBCVector3Dd& MapDirWorldToSpace(
00731 CSIBCRotationd& in_rotTo,
00732 const CSIBCVector3Dd& in_vctDir,
00733 CSIBCVector3Dd& out_vctDir );
00734
00747 friend CSIBCVector3Dd& MapDirSpaceToSpace(
00748 CSIBCRotationd& in_rotFrom,
00749 CSIBCRotationd& in_rotTo,
00750 const CSIBCVector3Dd& in_vctDir,
00751 CSIBCVector3Dd& out_vctDir );
00752
00754
00756
00757
00758
00759
00760
00762 friend bool AreAlmostEqual( const CSIBCRotationd& in_rot1,
00763 const CSIBCRotationd& in_rot2,
00764 const double in_dEpsilon = PICO_EPS );
00765
00766
00768 bool operator ==( const CSIBCRotationd& in_rot ) const;
00769
00770
00772 bool operator !=( const CSIBCRotationd& in_rot ) const;
00773
00774
00775
00776 protected:
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786 void SetQuatRep();
00787
00788
00789
00790
00791 void SetMatrixRep();
00792
00793
00794
00795
00796 void SetXYZAnglesRep();
00797
00798
00799
00800 void UpdateQuat();
00801
00802
00803
00804 void UpdateMatrix();
00805
00806
00807
00808 void UpdateXYZAngles();
00809
00810
00811
00812 int NextAxis( int in_nAxis );
00813
00814
00815 private:
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 CSIBCQuaterniond m_quat;
00829 CSIBCRotMatd m_matRot;
00830 CSIBCVector3Dd m_vctXYZAngles;
00831 double m_dAngle;
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845 unsigned char m_oRotationInfo;
00846
00847 void _SetQuatDirty(bool in_bIsDirty );
00848 void _SetMatDirty(bool in_bIsDirty );
00849 void _SetAnglesDirty(bool in_bIsDirty );
00850 void _SetOrigRep(E3DRotRepType in_eOrigRep );
00851
00852 bool _IsQuatDirty () const;
00853 bool _IsMatDirty () const;
00854 bool _AreAnglesDirty () const;
00855 E3DRotRepType _GetOrigRep() const;
00856
00857
00858 CSIBCRotationd( const CSIBCRotationd& in_rot );
00859 CSIBCRotationd& operator =( const CSIBCRotationd& in_rot );
00860 };
00861
00862 #endif