00001 /**************************************************************************** 00002 00003 This file is part of the GLC-lib library. 00004 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net) 00005 http://glc-lib.sourceforge.net 00006 00007 GLC-lib is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 GLC-lib is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with GLC-lib; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 *****************************************************************************/ 00022 00024 00025 #include "glc_interpolator.h" 00026 00027 using namespace glc; 00029 // Construction/Destruction 00031 00032 // Contructeur par défaut Interpolation Linéaire 00033 GLC_Interpolator::GLC_Interpolator() 00034 : m_InterpolType(INTERPOL_LINEAIRE) 00035 , m_nNbrPas(1) 00036 { 00037 00038 } 00039 00041 // Fonction Set 00043 // Défini la matrice d'interpolation 00044 void GLC_Interpolator::SetInterpolMat(int NbrPas, const GLC_Vector3d &VectDepart, const GLC_Vector3d &VectArrive 00045 , INTERPOL_TYPE Interpolation) 00046 { 00047 // Mise à jour des données membre 00048 m_InterpolType= Interpolation; 00049 if (!NbrPas) 00050 { 00051 //TRACE("GLC_Interpolator::SetInterpolMat -> NbrPas == 0 \n"); 00052 } 00053 else m_nNbrPas= NbrPas; 00054 00055 m_VectDepart= VectDepart; 00056 m_VectArrive= VectArrive; 00057 // Calcul de la matrice d'interpolation 00058 CalcInterpolMat(); 00059 } 00060 // Type d'interpolation 00061 void GLC_Interpolator::SetType(INTERPOL_TYPE Interpolation) 00062 { 00063 if (m_InterpolType != Interpolation) 00064 { 00065 m_InterpolType= Interpolation; 00066 // Calcul de la matrice d'interpolation 00067 CalcInterpolMat(); 00068 } 00069 } 00070 // Nombre de pas 00071 void GLC_Interpolator::SetNbrPas(int NbrPas) 00072 { 00073 if (!NbrPas) 00074 { 00075 //TRACE("GLC_Interpolator::SetNbrPas -> NbrPas == 0 \n"); 00076 return; 00077 } 00078 00079 if (m_nNbrPas != NbrPas) 00080 { 00081 m_nNbrPas= NbrPas; 00082 // Calcul de la matrice d'interpolation 00083 CalcInterpolMat(); 00084 } 00085 } 00086 // Vecteur d'arrivée et de depart 00087 void GLC_Interpolator::SetVecteurs(const GLC_Vector3d &VectDepart, const GLC_Vector3d &VectArrive) 00088 { 00089 m_VectDepart= VectDepart; 00090 m_VectArrive= VectArrive; 00091 00092 // Calcul de la matrice d'interpolation 00093 CalcInterpolMat(); 00094 00095 } 00096 00098 // Fonction Get 00100 00102 // Fonctions de Service privée 00104 // Calcul La matrice d'interpolation 00105 bool GLC_Interpolator::CalcInterpolMat(void) 00106 { 00107 // Verifie que les vecteur d'arrivé et de départ sont différent 00108 if (m_VectDepart == m_VectArrive) 00109 { 00110 //TRACE("GLC_Interpolator::CalcInterpolMat : Depart == Arrive\n"); 00111 return false; 00112 } 00113 00114 switch (m_InterpolType) 00115 { 00116 case INTERPOL_LINEAIRE: 00117 return CalcInterpolLineaireMat(); 00118 break; 00119 00120 case INTERPOL_ANGULAIRE: 00121 return CalcInterpolAngulaireMat(); 00122 break; 00123 00124 case INTERPOL_HOMOTETIE: 00125 return false; 00126 break; 00127 00128 default: 00129 //TRACE("GLC_Interpolator::CalcInterpolMat : Type d'interpolation non valide\n"); 00130 return false; 00131 } 00132 } 00133 00134 // Calcul la matrice d'interpolation linéaire 00135 bool GLC_Interpolator::CalcInterpolLineaireMat(void) 00136 { 00137 00138 // Calcul la matrice de translation 00139 const GLC_Vector3d VectTrans= (m_VectArrive - m_VectDepart) * (1.0 / m_nNbrPas); 00140 if(VectTrans.isNull()) 00141 { 00142 //TRACE("GLC_Interpolator::CalcInterpolLineaireMat -> Translation NULL\n"); 00143 m_InterpolMat.setToIdentity(); 00144 return false; 00145 } 00146 else 00147 { 00148 m_InterpolMat.setMatTranslate(VectTrans); 00149 return true; 00150 } 00151 } 00152 00153 // Calcul la matrice d'interpolation angulaire 00154 bool GLC_Interpolator::CalcInterpolAngulaireMat(void) 00155 { 00156 // Calcul de l'axe de rotation 00157 const GLC_Vector3d AxeRot(m_VectDepart ^ m_VectArrive); 00158 // Calcul de l'angle entre les vecteurs 00159 const double Angle= m_VectArrive.angleWithVect(m_VectDepart) / m_nNbrPas; 00160 // Calcul de la matrice de rotation 00161 if (qFuzzyCompare(Angle, 0.0)) 00162 { 00163 //TRACE("GLC_Interpolator::CalcInterpolAngulaireMat -> Rotation NULL\n"); 00164 m_InterpolMat.setToIdentity(); 00165 return false; 00166 } 00167 else 00168 { 00169 m_InterpolMat.setMatRot( AxeRot, Angle); 00170 return true; 00171 } 00172 } 00173 00174 00175