glc_interpolator.cpp

Go to the documentation of this file.
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;
00028 
00029 GLC_Interpolator::GLC_Interpolator()
00030 : m_InterpolType(INTERPOL_LINEAIRE)
00031 , m_StepCount(1)
00032 {
00033 
00034 }
00035 
00037 // Set Function
00039 void GLC_Interpolator::SetInterpolMat(int NbrPas, const GLC_Vector3d &VectDepart, const GLC_Vector3d &VectArrive
00040                                                                    , INTERPOL_TYPE Interpolation)
00041 {
00042         m_InterpolType= Interpolation;
00043         if (NbrPas != 0)
00044         m_StepCount= NbrPas;
00045 
00046         m_StartPoint= VectDepart;
00047         m_EndPoint= VectArrive;
00048 
00049         CalcInterpolMat();
00050 }
00051 
00052 void GLC_Interpolator::SetType(INTERPOL_TYPE Interpolation)
00053 {
00054         if (m_InterpolType != Interpolation)
00055         {
00056                 m_InterpolType= Interpolation;
00057 
00058                 CalcInterpolMat();
00059         }
00060 }
00061 
00062 void GLC_Interpolator::SetNbrPas(int NbrPas)
00063 {
00064 
00065         if ((NbrPas != 0) && (m_StepCount != NbrPas))
00066         {
00067                 m_StepCount= NbrPas;
00068 
00069                 CalcInterpolMat();
00070         }
00071 }
00072 
00073 void GLC_Interpolator::SetVecteurs(const GLC_Vector3d &VectDepart, const GLC_Vector3d &VectArrive)
00074 {
00075         m_StartPoint= VectDepart;
00076         m_EndPoint= VectArrive;
00077 
00078 
00079         CalcInterpolMat();
00080 
00081 }
00082 
00084 // Private sevices functions
00086 
00087 bool GLC_Interpolator::CalcInterpolMat(void)
00088 {
00089 
00090         if (m_StartPoint != m_EndPoint)
00091         {
00092                 switch (m_InterpolType)
00093                 {
00094                 case INTERPOL_LINEAIRE:
00095                         return CalcInterpolLineaireMat();
00096                         break;
00097 
00098                 case INTERPOL_ANGULAIRE:
00099                         return CalcInterpolAngulaireMat();
00100                         break;
00101 
00102                 case INTERPOL_HOMOTETIE:
00103                         return false;
00104                         break;
00105 
00106                 default:
00107                         return false;
00108                 }
00109         }
00110         else return false;
00111 
00112 }
00113 
00114 
00115 bool GLC_Interpolator::CalcInterpolLineaireMat(void)
00116 {
00117 
00118         const GLC_Vector3d VectTrans= (m_EndPoint - m_StartPoint) * (1.0 / m_StepCount);
00119         if(VectTrans.isNull())
00120         {
00121                 m_InterpolMat.setToIdentity();
00122                 return false;
00123         }
00124         else
00125         {
00126                 m_InterpolMat.setMatTranslate(VectTrans);
00127                 return true;
00128         }
00129 }
00130 
00131 bool GLC_Interpolator::CalcInterpolAngulaireMat(void)
00132 {
00133 
00134         const GLC_Vector3d AxeRot(m_StartPoint ^ m_EndPoint);
00135 
00136         const double Angle= m_EndPoint.angleWithVect(m_StartPoint) / m_StepCount;
00137 
00138         if (qFuzzyCompare(Angle, 0.0))
00139         {
00140                 m_InterpolMat.setToIdentity();
00141                 return false;
00142         }
00143         else
00144         {
00145                 m_InterpolMat.setMatRot( AxeRot, Angle);
00146                 return true;
00147         }
00148 }
00149 
00150 
00151 

SourceForge.net Logo

©2005-2011 Laurent Ribon