rendered paste body#include <CCatmullRom.h>
using namespace std;
CCatmullRom :: CCatmullRom(double _p, double _t) : CCurve(_p)
{
m_BlendingMatrix[0] = 0.0; m_BlendingMatrix[1] = 2.0 * _t; m_BlendingMatrix[2] = 0.0; m_BlendingMatrix[3] = 0.0;
m_BlendingMatrix[4] = -_t; m_BlendingMatrix[5] = 0.0; m_BlendingMatrix[6] = _t; m_BlendingMatrix[7] = 0.0;
m_BlendingMatrix[8] = 2.0 * _t; m_BlendingMatrix[9] = -5.0 * _t; m_BlendingMatrix[10] = 4.0 * _t; m_BlendingMatrix[11] = -_t;
m_BlendingMatrix[12] = -_t; m_BlendingMatrix[13] = 3.0 * _t; m_BlendingMatrix[14] = -3.0 * _t; m_BlendingMatrix[15] = _t;
}
CCatmullRom :: CCatmullRom(const CCatmullRom & _c) : CCurve(_c)
{
for(int i(0); i < 16; i++) m_BlendingMatrix[i] = _c.m_BlendingMatrix[i];
}
CCatmullRom :: CCatmullRom(const CCurve & _c, double _t) : CCurve(_c)
{
m_BlendingMatrix[0] = 0.0; m_BlendingMatrix[1] = 2.0 * _t; m_BlendingMatrix[2] = 0.0; m_BlendingMatrix[3] = 0.0;
m_BlendingMatrix[4] = -_t; m_BlendingMatrix[5] = 0.0; m_BlendingMatrix[6] = _t; m_BlendingMatrix[7] = 0.0;
m_BlendingMatrix[8] = 2.0 * _t; m_BlendingMatrix[9] = -5.0 * _t; m_BlendingMatrix[10] = 4.0 * _t; m_BlendingMatrix[11] = -_t;
m_BlendingMatrix[12] = -_t; m_BlendingMatrix[13] = 3.0 * _t; m_BlendingMatrix[14] = -3.0 * _t; m_BlendingMatrix[15] = _t;
}
CCatmullRom :: ~CCatmullRom() {}
void CCatmullRom :: compute()
{
m_Points.clear();
if( m_CheckPoints.size() > 3 )
{
CPoint P1, P2, P3, P4, Tmp;
double mT[4], mTT[4];
for(unsigned int i(0); i < m_CheckPoints.size() - 3; i++)
{
P1 = m_CheckPoints[i];
P2 = m_CheckPoints[i+1];
P3 = m_CheckPoints[i+2];
P4 = m_CheckPoints[i+3];
for(double t(0); t < 1.0; t += m_Precision)
{
mT[0] = 1.0;
mT[1] = t;
mT[2] = t * t;
mT[3] = t * t * t;
mTT[0] = m_BlendingMatrix[0] * mT[0] + m_BlendingMatrix[4] * mT[1] + m_BlendingMatrix[8] * mT[2] + m_BlendingMatrix[12] * mT[3];
mTT[1] = m_BlendingMatrix[1] * mT[0] + m_BlendingMatrix[5] * mT[1] + m_BlendingMatrix[9] * mT[2] + m_BlendingMatrix[13] * mT[3];
mTT[2] = m_BlendingMatrix[2] * mT[0] + m_BlendingMatrix[6] * mT[1] + m_BlendingMatrix[10] * mT[2] + m_BlendingMatrix[14] * mT[3];
mTT[3] = m_BlendingMatrix[3] * mT[0] + m_BlendingMatrix[7] * mT[1] + m_BlendingMatrix[11] * mT[2] + m_BlendingMatrix[15] * mT[3];
Tmp.x(mTT[0] * P1.x() + mTT[1] * P2.x() + mTT[2] * P3.x() + mTT[3] * P4.x());
Tmp.y(mTT[0] * P1.y() + mTT[1] * P2.y() + mTT[2] * P3.y() + mTT[3] * P4.y());
Tmp.z(mTT[0] * P1.z() + mTT[1] * P2.z() + mTT[2] * P3.z() + mTT[3] * P4.z());
m_Points.push_back(Tmp);
}
}
}
}