/****************************************************************************************

	Tweener.cpp

	Copyright (c)1990 - 1999 MetaCreations. All rights reserved.

	Author:	Jerome Bignon

	Date:	06/21/99

	Revision History

	when		who			what & why
	=========== ===========	=============================================================
	08/20/99	cph			Put in Extension3DInit() and Extension3DCleanup() methods

****************************************************************************************/
#include "Tweener.h"
#include "Math.h"


const MCGUID CLSID_Tweener(R_CLSID_Tweener);


void Extension3DInit(IMCUnknown* utilities)
{
	// Perform your dll initialization here
}

void Extension3DCleanup()
{
	// Perform any nec clean-up here
}


TBasicUnknown* MakeCOMObject(const MCCLSID& classId)	// This method instanciate
{														// the object COMBack
	TBasicUnknown* res = NULL;

	if (classId == CLSID_Tweener) res = new Tweener;

	return res;
}

// Constructor of the C++ Object :
Tweener::Tweener()
{
	fData.fNbOsc = 5;
	fData.fExpCoef = 1.0f;
	fExpCoef = 1.0f;
	fCosCoef = TWO_PI * (fData.fNbOsc+0.25f);
}
  
void* Tweener::GetExtensionDataBuffer()
{
	return &fData; // used by the shell to set the new parameters
}
  
MCCOMErr Tweener::ExtensionDataChanged()
{
	fCosCoef = TWO_PI * ( fData.fNbOsc + 0.25f );
	fExpCoef= (real64)fData.fExpCoef;
	return MC_S_OK;
}

int16 Tweener::GetResID()
{
	return 144; //  This is the view ID in the resource file.
}
  
MCCOMErr Tweener::SimpleTween(real &result, int32 time, int32 time1, int32 time2)
{
	int32 delta = time2 - time1;

	result	= 0;

	if (delta == 0)
	{
		return MC_S_OK;
	}
	
	real t = (1.0f * time - time1) / delta;

	result  = (1.0f - ::cos(t*fCosCoef) * ::exp( -t * fExpCoef));

	return MC_S_OK;
}
