Newer
Older
Import / projects / Gameloft / bne_lib / code / Utils / TransformLerper.h
#ifndef _TRANSFORMLERPER_H_
#define _TRANSFORMLERPER_H_

#include "RKVector.h"
#include "RKQuaternion.h"

namespace CasualCore
{
  class Object;
};

class RKTransformObject;

// Small class to lerp position/rotation of a transform object
class TransformLerper
{
public:
  typedef void(*LerpEndCallback)(void*);

  TransformLerper();
  ~TransformLerper();

  bool IsLerping() const { return m_lerping; }

  // Uses the position and rotation of the object passed in for the start position/rotation
  void Init(RKTransformObject* a_pLerpObj, RKVector a_posEnd, RKQuaternion a_rotEnd, float a_lerpLength = 1.0f);
  void Init(RKTransformObject* a_pLerpObj, RKVector a_posStart, RKVector a_posEnd, RKQuaternion a_rotStart, RKQuaternion a_rotEnd, 
            float a_lerpLength = 1.0f, float easeInPercentage = 0.0f, float easeOutPercentage = 0.0f);

  void StartLerp();
  void StopLerp();
  void PauseLerp() { m_lerping = false; }
  void ContinueLerp() { m_lerping = true; }

  void Update(float a_dt);
  void SetCallback(LerpEndCallback a_pCallback, void* a_pOwner = NULL);

protected:

private:
  bool m_lerping;
  RKVector m_posStart;
  RKVector m_posEnd;
  RKQuaternion m_rotStart;
  RKQuaternion m_rotEnd;
  float m_lerpTime;
  float m_maxLerpTime;
  float m_easeInPercentage;
  float m_easeOutPercentage;

  LerpEndCallback m_pCallback;

  RKTransformObject* m_pObject;
  void* m_pCallbackOwner;
};

#endif // _TRANSFORMLERPER_H_