Files
2025-03-05 08:37:43 +01:00

74 lines
2.2 KiB
C

/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "pvvmud.H"
#include "keyframe.H"
CInterpolate::CInterpolate(){
}
void CInterpolate::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < controlVector.size(); index++){
keyFrame->addControlVector(controlVector[index]);
}
}
CVector CInterpolate::interpolate(double time, ControlVector_t * controlVector){
int size = (*controlVector).size();
if (size == 0) return CVector(0.0,0.0,0.0);
if (size == 1) return (*controlVector)[0];
int start = (int)floor((size-1) * time);
int stop = start + 1;
time = (size-1)*time-start;
return interpolate(start,time,controlVector);
}
CVector CInterpolate::interpolate(int start, double time,
ControlVector_t * controlVector)
{
return (*controlVector)[start]
+ ((*controlVector)[start+1]-(*controlVector)[start])*time;
}
CKeyFrame::CKeyFrame(CInterpolate * interpolate){
m_controlVector = new ControlVector_t();
m_interpolate = interpolate;
}
CKeyFrame::~CKeyFrame(){
delete m_controlVector;
delete m_interpolate;
}
void CKeyFrame::addControlVector(const CVector & vector){
m_controlVector->push_back(vector);
}
void CKeyFrame::addControlVector(const ControlVector_t & controlVector){
m_interpolate->addControlVector(this,controlVector);
}
CVector CKeyFrame::interpolate(double time){
return m_interpolate->interpolate(time, m_controlVector);
}