int rate,frac;
sint16 *frmptr[2];
frac = GetFrames(item, frmptr, &rate);
int GetFrames( ITEM_INFO *item, sint16 *frmptr[], int *rate )
{
int first;
int interp;
// frm - current frame (for example 30 fps, its means one frame from 30)
// rat - ratio for current animation for example 4
//get pointer to current frame (start of position and rotation data)
frmptr[0] = frmptr[1] = anim->frame_ptr;
first = frm/rat;
interp = frm%rat;
//take this frame
frmptr[0] += first * frame_size;
//take next frame
frmptr[1] = frmptr[0] + frame_size;
*rate = rat;
//increase frame counter
frm++;
return interp;
}
Get position x1, y1, z1 and rotation xr1, yr1, zr1 from frmptr[0];
Get position x2, y2, z2 and rotation xr2, yr2, zr2 from frmptr[1];
Compose two matrices m1 and m2 correspond to position 1,2 and rotation 1,2.
Then interpolate two matrices. Matrices are colmajor.
sint32 *phd_mxptr; /* matrix pointer....*/
sint32 *IMptr;
enum msoff { M00,M01,M02,M03,
M10,M11,M12,M13,
M20,M21,M22,M23 };
void InterpolateMatrix( void )
{
sint32 *mptr,*iptr;
sint32 frac,rate;
//first matrix for interpolation m1
mptr = phd_mxptr;
//second matrix for interpolation m2
iptr = IMptr;
if ( rate==2 || (frac == 2 && rate == 4)) // If interpolating Odd Frames
{ // then do simple case
*(mptr+M00) = (*(iptr+M00) + *(mptr+M00)) >> 1;
*(mptr+M01) = (*(iptr+M01) + *(mptr+M01)) >> 1;
*(mptr+M02) = (*(iptr+M02) + *(mptr+M02)) >> 1;
*(mptr+M03) = (*(iptr+M03) + *(mptr+M03)) >> 1;
*(mptr+M10) = (*(iptr+M10) + *(mptr+M10)) >> 1;
*(mptr+M11) = (*(iptr+M11) + *(mptr+M11)) >> 1;
*(mptr+M12) = (*(iptr+M12) + *(mptr+M12)) >> 1;
*(mptr+M13) = (*(iptr+M13) + *(mptr+M13)) >> 1;
*(mptr+M20) = (*(iptr+M20) + *(mptr+M20)) >> 1;
*(mptr+M21) = (*(iptr+M21) + *(mptr+M21)) >> 1;
*(mptr+M22) = (*(iptr+M22) + *(mptr+M22)) >> 1;
*(mptr+M23) = (*(iptr+M23) + *(mptr+M23)) >> 1;
}
else if (frac == 1)
{
*(mptr+M00) += (*(iptr+M00) - *(mptr+M00)) >> 2;
*(mptr+M01) += (*(iptr+M01) - *(mptr+M01)) >> 2;
*(mptr+M02) += (*(iptr+M02) - *(mptr+M02)) >> 2;
*(mptr+M03) += (*(iptr+M03) - *(mptr+M03)) >> 2;
*(mptr+M10) += (*(iptr+M10) - *(mptr+M10)) >> 2;
*(mptr+M11) += (*(iptr+M11) - *(mptr+M11)) >> 2;
*(mptr+M12) += (*(iptr+M12) - *(mptr+M12)) >> 2;
*(mptr+M13) += (*(iptr+M13) - *(mptr+M13)) >> 2;
*(mptr+M20) += (*(iptr+M20) - *(mptr+M20)) >> 2;
*(mptr+M21) += (*(iptr+M21) - *(mptr+M21)) >> 2;
*(mptr+M22) += (*(iptr+M22) - *(mptr+M22)) >> 2;
*(mptr+M23) += (*(iptr+M23) - *(mptr+M23)) >> 2;
}
else
{
*(mptr+M00) = *(iptr+M00) - ((*(iptr+M00) - *(mptr+M00)) >> 2);
*(mptr+M01) = *(iptr+M01) - ((*(iptr+M01) - *(mptr+M01)) >> 2);
*(mptr+M02) = *(iptr+M02) - ((*(iptr+M02) - *(mptr+M02)) >> 2);
*(mptr+M03) = *(iptr+M03) - ((*(iptr+M03) - *(mptr+M03)) >> 2);
*(mptr+M10) = *(iptr+M10) - ((*(iptr+M10) - *(mptr+M10)) >> 2);
*(mptr+M11) = *(iptr+M11) - ((*(iptr+M11) - *(mptr+M11)) >> 2);
*(mptr+M12) = *(iptr+M12) - ((*(iptr+M12) - *(mptr+M12)) >> 2);
*(mptr+M13) = *(iptr+M13) - ((*(iptr+M13) - *(mptr+M13)) >> 2);
*(mptr+M20) = *(iptr+M20) - ((*(iptr+M20) - *(mptr+M20)) >> 2);
*(mptr+M21) = *(iptr+M21) - ((*(iptr+M21) - *(mptr+M21)) >> 2);
*(mptr+M22) = *(iptr+M22) - ((*(iptr+M22) - *(mptr+M22)) >> 2);
*(mptr+M23) = *(iptr+M23) - ((*(iptr+M23) - *(mptr+M23)) >> 2);
}
}
In this example used fixed point math.
I dont understand process interpolation of matrices - 3 cases from InterpolateMatrix() function. Please explain.
InterpolateMatrix
Variablesfrac
andrate
are not initialized! Depending on compilation setting, the code could randomly execute any of the 3 statement blocks (init not set), or only the last block (init to zero). I would consider the function, broken. Also this is not the way to interpolate a matrix as the uniformity (aspex between x, y, z axis) will not be constant (unless you want that effect?) \$\endgroup\$InterpolateMatrix
they are not the same variables. c++ is block scoped. \$\endgroup\$