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