#include "GestureDef.h"
#include <fstream>
#include <math.h>
using namespace std;

namespace GestureDef{
	// utility functions for quaternion
	ORI quatMul(ORI q1, ORI q2)
	{
		ORI res;
		res.x =  q1.x * q2.w + q1.y * q2.z - q1.z * q2.y + q1.w * q2.x;
		res.y = -q1.x * q2.z + q1.y * q2.w + q1.z * q2.x + q1.w * q2.y;
		res.z =  q1.x * q2.y - q1.y * q2.x + q1.z * q2.w + q1.w * q2.z;
		res.w = -q1.x * q2.x - q1.y * q2.y - q1.z * q2.z + q1.w * q2.w;
		return res;
	}

	ORI quatConj(ORI q)
	{
		ORI res;
		res.w =  q.w;
		res.x = -q.x;
		res.y = -q.y;
		res.z = -q.z;
		return res;
	}

	ORI quatNorm(ORI q)
	{		
		float norm = sqrt(q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z);
		q.w /= norm;
		q.x /= norm;
		q.y /= norm;
		q.z /= norm;
		return q;
	}

	// Global function to get the gesture name
	string getGestureName(int gestureIdx)
	{
		string str = "NOT_DEF";
		switch (gestureIdx)
		{
		// swipe eight directions
		case SWIPE_RIGHT:		str = "swipe_right"; break;
		case SWIPE_LEFT:		str = "swipe_left"; break;
		case SWIPE_UP:			str = "swipe_up"; break;
		case SWIPE_DOWN:		str = "swipe_down"; break;
		case SWIPE_UPRIGHT:		str = "swipe_upright"; break;
		case SWIPE_UPLEFT:		str = "swipe_upleft"; break;	
		case SWIPE_DOWNRIGHT:	str = "swipe_downright"; break;	
		case SWIPE_DOWNLEFT:	str = "swipe_downleft"; break;
	
		// back & forth
		case POKE_RIGHT:		str = "poke_right"; break;
		case POKE_LEFT:			str = "poke_left"; break;
		case POKE_UP:			str = "poke_up"; break;
		case POKE_DOWN:			str = "poke_down"; break;

		// others
		case V_SHAPE:			str = "v_shape"; break;
		case X_SHAPE:			str = "x_shape"; break;
		case CIR_HOR_CLK:		str = "cir_hor_clk"; break;
		case CIR_HOR_CCLK:		str = "cir_hor_cclk"; break;
		case CIR_VER_CLK:		str = "cir_ver_clk"; break;
		case CIR_VER_CCLK:		str = "cir_ver_cclk"; break;
		case TWIST_CLK:			str = "twist_clk"; break;
		case TWITS_CCLK:		str = "twist_cclk"; break;		
		}		
		return str;
	}
}