Over a million developers have joined DZone.

SmoothMove.h

·
// 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 &start, 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:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}