9 #if !defined(__LeapMath_h__)
10 #define __LeapMath_h__
20 static const float PI = 3.1415926536f;
25 static const float DEG_TO_RAD = 0.0174532925f;
30 static const float RAD_TO_DEG = 57.295779513f;
52 Vector(
float _x,
float _y,
float _z) :
53 x(_x),
y(_y),
z(_z) {}
57 x(vector.
x),
y(vector.
y),
z(vector.
z) {}
61 static Vector s_zero(0, 0, 0);
67 static Vector s_xAxis(1, 0, 0);
72 static Vector s_yAxis(0, 1, 0);
77 static Vector s_zAxis(0, 0, 1);
83 static Vector s_left(-1, 0, 0);
92 static Vector s_down(0, -1, 0);
101 static Vector s_forward(0, 0, -1);
118 return std::sqrt(
x*
x +
y*
y +
z*
z);
138 return std::sqrt((
x - other.
x)*(
x - other.
x) +
139 (
y - other.
y)*(
y - other.
y) +
140 (
z - other.
z)*(
z - other.
z));
163 return std::acos(this->
dot(other) / std::sqrt(denom));
180 return std::atan2(
y, -
z);
197 return std::atan2(
x, -
z);
219 return std::atan2(
x, -
y);
234 return (
x * other.
x) + (
y * other.
y) + (
z * other.
z);
252 (
z * other.
x) - (
x * other.
z),
253 (
x * other.
y) - (
y * other.
x));
270 denom = 1.0f / std::sqrt(denom);
271 return Vector(
x * denom,
y * denom,
z * denom);
295 return Vector(
x * scalar,
y * scalar,
z * scalar);
300 return Vector(
x / scalar,
y / scalar,
z / scalar);
306 return Vector(vector.
x * scalar, vector.
y * scalar, vector.
z * scalar);
344 std::stringstream result;
345 result <<
"(" <<
x <<
", " <<
y <<
", " <<
z <<
")";
355 return x == other.
x &&
y == other.
y &&
z == other.
z;
359 return x != other.
x ||
y != other.
y ||
z != other.
z;
367 return (x <= FLT_MAX && x >= -FLT_MAX) &&
368 (y <= FLT_MAX && y >= -FLT_MAX) &&
369 (z <= FLT_MAX && z >= -FLT_MAX);
379 return index < 3 ? (&
x)[index] : 0.0f;
393 template<
typename Vector3Type>
395 return Vector3Type(
x,
y,
z);
406 template<
typename Vector4Type>
408 return Vector4Type(
x,
y,
z, w);
437 operator const float* ()
const {
547 const float s = std::sin(angleRadians);
548 const float c = std::cos(angleRadians);
549 const float C = (1-c);
551 xBasis =
Vector(axis[0]*axis[0]*C + c, axis[0]*axis[1]*C - axis[2]*s, axis[0]*axis[2]*C + axis[1]*s);
552 yBasis =
Vector(axis[1]*axis[0]*C + axis[2]*s, axis[1]*axis[1]*C + c, axis[1]*axis[2]*C - axis[0]*s);
553 zBasis =
Vector(axis[2]*axis[0]*C - axis[1]*s, axis[2]*axis[1]*C + axis[0]*s, axis[2]*axis[2]*C + c);
615 return (*
this) = (*this) * other;
641 template<
typename Matrix3x3Type>
654 template<
typename Matrix4x4Type>
719 std::stringstream result;
742 #endif // __LeapMath_h__