{I+=codeWee;}
[C++] Math: Quaternion Lerp and SLerp (Linear Interpolation)
This is Pseudo Code:

struct Quaternion
{
	float x, y, z, w;


Quaternion LERP(const Quaternion& a, const Quaternion& b, const float t)
{
	Quaternion r;
	float t_ = 1 - t;
	r.x = t_*a.x + t*b.x;
	r.y = t_*a.y + t*b.y;
	r.z = t_*a.z + t*b.z;
	r.w = t_*a.w + t*b.w;
	r.Normalize();
	return r;
}

Quaternion SLERP(const Quaternion& a, const Quaternion& b, const float t)
{
	Quaternion r;
	float t_ = 1 - t;
	float Wa, Wb;
	float theta = acos(a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w);
	float sn = sin(theta);
	Wa = sin(t_*theta) / sn;
	Wb = sin(t*theta) / sn;
	r.x = Wa*a.x + Wb*b.x;
	r.y = Wa*a.y + Wb*b.y;
	r.z = Wa*a.z + Wb*b.z;
	r.w = Wa*a.w + Wb*b.w;
	r.Normalize();
	return r;
}

};
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.