Home

hersto:  Library/Chaser.h

Source of Library/Chaser.h:

Here is a link for right-clicking and downloading the file: Library/Chaser.h (3.03 K Byte),

and below is its content to view online.



/*
  Chaser.h
 
  A C++ implementation of a Chaser.

  Author:
      Herbert Stocker

  Underlying Paper:
      "Linear Filters - Animating Objects in a
      Flexible and Pleasing Way" by Herbert Stocker

  HomePage:
      http://www.hersto.net/Followers
      (various resources there)

  License:
      You may use this file in any project and
      modify it as long as you keep this comment
      block unchanged.

  Accompanying Files:
      Chaser.cpp
      Chaser_impl.h

  Required Files:
      Follower_Trait.h
      Follower_Trait.cpp
      Follower_Trait_impl.h
      TimeDependent.h
      TimeDependent.cpp

  Documentation:
      See http://www.hersto.net/Followers

 */



#pragma once

#include "Follower_Trait.h" // for specifying the behviour of the dampered variable.

#include "TimeDependent.h"

#define This (*this)
// if you don't like this, replace do a text replacement and remove this line.




template<class Type>
class CTChaser
:   public CTimeDependent
{
public:
    typedef const Type cType;

    explicit CTChaser(double Duration, bool bStartWithFirstInput= false);
   ~CTChaser();





   // TBD: Implement!

   



    void set_destination(cType& Dest);
    void set_value(cType& Val);

    cType& get_destination();
    cType& get_value();

    void set_tau(double Tau);
    double get_tau();

    void set_eps(double Eps);
    double get_eps();

    bool get_isActive();

    // C-Style callback:
    // NOTE: There is no standard mechanism for callbacks, like in other
    // languages, where there are delegates or closures. Therefore this
    // provides just plain C callbacks, and you may want to replace it
    // with your preferred mechanism.
    // However, maybe the FastDelegates from CodeProject (http://www.code-
    // project.com/cpp/FastDelegate.asp) or Boost::function are good can-
    // didates for a replacement.
    void SetReceivers( void* pvContext
                     , void (*pfValueReceiver)   (void* pvContext, cType& Value)
                     , void (*pfIsActiveReceiver)(void* pvContext, bool bIsActive)
                     );
    
    void Tick(double DeltaT, double Now);

    void SetNeedTickCB(void* pvContext, double (*pfNeedTickCB) (void* pvContext, CTimeDependent* pCaller, bool bNeedTick));


protected:

    void* mpvRcvContext;
    void (*mpfValueReceiver)(void* pvContext, cType& Value);
    void (*mpfIsActiveReceiver)(void* pvContext, bool bIsActive);

    void mfCallValueRcv(cType& Value)
      { if(mpfValueReceiver)    mpfValueReceiver(mpvRcvContext, Value); }

    void mfCallIsActiveRcv(bool bIsActive)
      { if(mpfIsActiveReceiver) mpfIsActiveReceiver(mpvRcvContext, bIsActive); }

    void mfUpdateReached(double Dist)
      {} // currently 'reached' is not implemented.

    void mfUpdateReached()
      { /*mfUpdateReached(mfGetDist());*/ }


    void mfSetNeedTick(bool bNeedTick);
    // sets mbNeedTick and calls the need-tick callback. 

};



#include "Chaser_impl.h"



__.-.__
end of document