Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

DZone's Guide to

# SmoothMove.h

·
Free Resource

Comment (0)

Save
{{ articles[0].views | formatCount}} Views
```// description of your code here
It uses Ogre, but only for the Vector3 class.

```
#ifndef SMOOTHMOVE_H
#define SMOOTHMOVE_H
#include

#include

using namespace Ogre;

// Class to interpolate the points in a path defined by 2 points (start and end)
// There are several methods to do the interpolation (linear, spherical, halfsinus, etc)
// You can add methods just by definig another method in this class. The only requirements
// are that they take a float parameter, return a float, and that for x=0 they return 0, and
// for x=1 they return 1

class SmoothMove
{
private:
Vector3 mStart;
Vector3 mEnd;
float mTotalTime;

float mCurrentTime;
Vector3 mCurrent;
float (*mCurrentMethod)(float);
float CalculatePos(float start, float end,float currentTime, float totalTime);
static bool isEqual(float x, float y);

public:
SmoothMove(const Vector3 ☆t, const Vector3 &end,const float time,float (*smoothMethod)(float));
Vector3 IterateFrame(const float time);
Vector3 CalculateCurrentPos();
void SetNewTarget(const Vector3 &end,const float time);

static float LinearMethod(float x) { return x; }
static float AscQuadraticMethod(float x){ return x*x; }
static float DescQuadraticMethod(float x){ return 1-(x-1)*(x-1); }
static float HalfSinusMethod(float x){ return sin(x*M_PI/2); }
static float SphericalMethod(float x){ return sqrt(1-(x-1)*(x-1)); }
static float SmoothSinus(float x){ return sin(M_PI*(x-0.5))*3/2; }
};

#endif

``````
Topics:

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Opinions expressed by DZone contributors are their own.