{I+=codeWee;}
[C++] Math: Quaternion to Direction Vector
This is Pseudo Code:

struct Quaternion
{

	float x, y, z, w;

bool ToDirectionVector(_Out_ Vector3* dir, _Out_ Vector3* up, _Out_ Vector3* right)
{
	if (Normalize() == FALSE)
		return false;
	if (dir == NULL || up == NULL || right == NULL)
		return false;
	float xx = x * x;
	float xy = x * y;
	float xz = x * z;
	float xw = x * w;

	float yy = y * y;
	float yz = y * z;
	float yw = y * w;

	float zz = z * z;
	float zw = z * w;

	right->Set(1 - 2 * (yy + zz), 2 * (xy - zw), 2 * (xz + yw));
	up->Set(2 * (xy + zw), 1 - 2 * (xx + zz), 2 * (yz - xw));
	dir->Set(2 * (xz - yw), 2 * (yz + xw), 1 - 2 * (xx + yy));

	return true;
}

}
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.