// ----------------------------------------------------------------------------
// Blitz-Irrlicht 1.8.3 Wrapper by Ed Musolino 2015
// Based off of Frank Dodd's Irrlicht 1.7 Freebasic Wrapper (2006-2010)
// ----------------------------------------------------------------------------

//  This software is provided 'as-is', without any express Or implied
//  warranty.  In no event will the authors be held liable For any damages
//  arising from the use of this software.

//  Permission is granted To anyone To use this software For any purpose,
//  including commercial applications, And To alter it And redistribute it
//  freely, subject To the following restrictions:

//  1. The Origin of this software must Not be misrepresented; you must not
//     claim that you wrote the original software. If you use this software
//     in a product, an acknowledgement in the product documentation would be
//     appreciated but is Not required.
//  2. Altered source versions must be clearly marked as such, And must Not be
//     misrepresented as being the original software.
//  3. This notice may Not be removed Or altered from any source distribution.
//
// /////////////////////////////////////////////////////////////////////////////

#include "bIrrlicht.h"


extern IrrlichtDevice*		device;
extern IVideoDriver*		driver;
extern ISceneManager*		smgr;
extern IGUIEnvironment*		guienv;




extern "C"
{
/*
AnimateMD2 md2[,mode][,speed#][,first_frame][,last_frame][,transition#]
Parameters
md2 - md2 handle 

mode (optional) - mode of animation 
0: stop animation 
1: loop animation (default) 
2: ping-pong animation 
3: one-shot animation 

speed# (optional) - speed of animation. Defaults to 1. 
first_frame (optional) - first frame of animation. Defaults to 1. 
last_frame# (optional) - last frame of animation. Defaults to last frame of all md2 animations. 
transition# (optional) - smoothness of transition between last frame shown of previous animation and first frame of next animation. Defaults to 0.  

Description
Animates an md2 entity. 
*/
//AnimateMD2 md2[,mode][,speed#][,first_frame][,last_frame][,transition#]		//ED MUSOLINO
DLL_EXPORT void BBCALL iAnimateNode ( IAnimatedMeshSceneNode* node, int mode, float speed, int first_frame, 
									 int last_frame, float transition )
{
	if(mode = 1)
	{
		node->setLoopMode(true);
	}
	else
	{
		node->setLoopMode(false);
	}
	node->setAnimationSpeed(speed);
	node->setFrameLoop(first_frame, last_frame);
	node->setTransitionTime( transition );
}

/* ----------------------------------------------------------------------------
set the MD2 animation sequence to playback in the animation
*/
DLL_EXPORT void BBCALL iPlayMD2Animation ( IAnimatedMeshSceneNode* node, int iAnimation)
{
    EMD2_ANIMATION_TYPE  animationtable[] = {
        EMAT_STAND,
        EMAT_RUN,
        EMAT_ATTACK,
        EMAT_PAIN_A,
        EMAT_PAIN_B,
        EMAT_PAIN_C,
        EMAT_JUMP,
        EMAT_FLIP,
        EMAT_SALUTE,
        EMAT_FALLBACK,
        EMAT_WAVE,
        EMAT_POINT,
        EMAT_CROUCH_STAND,
        EMAT_CROUCH_WALK,
        EMAT_CROUCH_ATTACK,
        EMAT_CROUCH_PAIN,
        EMAT_CROUCH_DEATH,
        EMAT_DEATH_FALLBACK,
        EMAT_DEATH_FALLFORWARD,
        EMAT_DEATH_FALLBACKSLOW,
        EMAT_BOOM
    };

    // play the selected animation sequence
	node->setMD2Animation(animationtable[iAnimation]);
}



/*
MD2AnimTime ( md2 )
Parameters
md2 - md2 handle  

Description
Returns the animation time of an md2 model. 

The animation time is the exact moment that the md2 is at with regards its frames of animation. For example, if the md2 at a certain moment in time is moving between the third and fourth frames, then MD2AnimTime will return a number in the region 3-4.  
*/



/*
MD2AnimLength ( md2 )
Parameters
md2 - md2 handle  

Description
Returns the animation length of an md2 model. 

The animation length is the total amount of animation frames that consist within the md2 file.  
*/




/*
MD2Animating ( md2 )
Parameters
md2 - md2 handle  

Description
Returns 1 (True) if md2 is currently animating, 0 (False) if not.  
*/

/* ----------------------------------------------------------------------------
set the looping mode
*/
DLL_EXPORT void BBCALL iLoopAnimation ( IAnimatedMeshSceneNode* node, bool playAnimationLooped )
{
    // set the looped status of playback in the animation
    node->setLoopMode(playAnimationLooped);
}

/* ----------------------------------------------------------------------------
get the looping mode
*/
DLL_EXPORT bool BBCALL iAnimationLooped ( IAnimatedMeshSceneNode* node )
{
    // get the looped status of playback in the animation
    return (bool)node->getLoopMode();
}

/* ----------------------------------------------------------------------------
set the playback animation speed
*/
DLL_EXPORT void BBCALL iAnimationSpeed ( IAnimatedMeshSceneNode* node, f32 fSpeed )
{
    // set the speed of playback in the animation
    node->setAnimationSpeed(fSpeed);
}

/* ----------------------------------------------------------------------------
get the current frame number being played in the animation
*/
DLL_EXPORT unsigned int BBCALL iAnimationFrame ( IAnimatedMeshSceneNode* node )
{
    // get the current frame number in the animation
    return (unsigned int)node->getFrameNr();
}

/* ----------------------------------------------------------------------------
set the current frame number being played in the animation
*/
DLL_EXPORT void BBCALL iSetAnimationFrame ( IAnimatedMeshSceneNode* node, f32 fFrame )
{
    // set the current frame in the animation
    node->setCurrentFrame( fFrame );
}

/* ----------------------------------------------------------------------------
Sets the transition time across which two poses of an animated mesh are blended
For example a character in a sitting pose can be switched into a lying down pose
by blending the two animations.
IrrAnimateNode must be called before IrrDrawScene if blending is used
*/
DLL_EXPORT void BBCALL iTransitionTime ( IAnimatedMeshSceneNode* node, float fTime )
{
    // set the time in seconds across which the transition occurs
    node->setTransitionTime( fTime );
}




}


