Files
Work/engine/SPACIAL.CPP
2024-08-07 09:16:27 -04:00

50 lines
1.3 KiB
C++

#include <engine/spacial.hpp>
#include <common/array.hpp>
SpacialTransform::~SpacialTransform()
{
}
BOOL SpacialTransform::transform(Array<int> &srcVector,Array<int> &dstVector,WORD sizeFactor)
{
int inverseFactor((100.00/(float)sizeFactor)*100.00);
int outSegment(inverseFactor);
int inSegment(100);
int nextDestIndex(0);
int accumulator(0);
mNextInputIndex=-1;
dstVector.size((srcVector.size()*sizeFactor)/100.00);
if(!nextInput(srcVector))return FALSE;
while(TRUE)
{
if(outSegment<=inSegment)
{
accumulator+=((inSegment*mCurrentValue)+((100-inSegment)*mNextValue))*outSegment;
inSegment-=outSegment;
outSegment=inverseFactor;
accumulator*=(float)sizeFactor*.000001;
if(nextDestIndex>=dstVector.size())break;
dstVector[nextDestIndex++]=accumulator;
accumulator=0;
}
else
{
accumulator+=((inSegment*mCurrentValue)+((100-inSegment)*mNextValue))*inSegment;
outSegment-=inSegment;
inSegment=100;
if(!nextInput(srcVector))break;
}
}
return false;
}
BOOL SpacialTransform::nextInput(Array<int> &srcVector)
{
if(++mNextInputIndex>=srcVector.size())return FALSE;
mCurrentValue=srcVector[mNextInputIndex];
if(mNextInputIndex+1>=srcVector.size())mNextValue=mCurrentValue;
else mNextValue=srcVector[mNextInputIndex+1];
return TRUE;
}