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;
58 Vector(
float _x,
float _y,
float _z) :
59 x(_x),
y(_y),
z(_z) {}
67 x(vector.
x),
y(vector.
y),
z(vector.
z) {}
75 static Vector s_zero(0, 0, 0);
85 static Vector s_xAxis(1, 0, 0);
94 static Vector s_yAxis(0, 1, 0);
103 static Vector s_zAxis(0, 0, 1);
113 static Vector s_left(-1, 0, 0);
130 static Vector s_down(0, -1, 0);
147 static Vector s_forward(0, 0, -1);
170 return std::sqrt(
x*
x +
y*
y +
z*
z);
194 return std::sqrt((
x - other.
x)*(
x - other.
x) +
195 (
y - other.
y)*(
y - other.
y) +
196 (
z - other.
z)*(
z - other.
z));
221 return std::acos(this->
dot(other) / std::sqrt(denom));
240 return std::atan2(
y, -
z);
259 return std::atan2(
x, -
z);
283 return std::atan2(
x, -
y);
300 return (
x * other.
x) + (
y * other.
y) + (
z * other.
z);
320 (
z * other.
x) - (
x * other.
z),
321 (
x * other.
y) - (
y * other.
x));
340 denom = 1.0f / std::sqrt(denom);
341 return Vector(
x * denom,
y * denom,
z * denom);
379 return Vector(
x * scalar,
y * scalar,
z * scalar);
388 return Vector(
x / scalar,
y / scalar,
z / scalar);
398 return Vector(vector.
x * scalar, vector.
y * scalar, vector.
z * scalar);
436 std::stringstream result;
437 result <<
"(" <<
x <<
", " <<
y <<
", " <<
z <<
")";
451 return x == other.
x &&
y == other.
y &&
z == other.
z;
459 return x != other.
x ||
y != other.
y ||
z != other.
z;
469 return (x <= FLT_MAX && x >= -FLT_MAX) &&
470 (y <= FLT_MAX && y >= -FLT_MAX) &&
471 (z <= FLT_MAX && z >= -FLT_MAX);
483 return index < 3 ? (&
x)[index] : 0.0f;
501 template<
typename Vector3Type>
503 return Vector3Type(
x,
y,
z);
514 template<
typename Vector4Type>
516 return Vector4Type(
x,
y,
z, w);
545 operator const float* ()
const {
655 const float s = std::sin(angleRadians);
656 const float c = std::cos(angleRadians);
657 const float C = (1-c);
659 xBasis =
Vector(n[0]*n[0]*C + c, n[0]*n[1]*C - n[2]*s, n[0]*n[2]*C + n[1]*s);
660 yBasis =
Vector(n[1]*n[0]*C + n[2]*s, n[1]*n[1]*C + c, n[1]*n[2]*C - n[0]*s);
661 zBasis =
Vector(n[2]*n[0]*C - n[1]*s, n[2]*n[1]*C + n[0]*s, n[2]*n[2]*C + c );
723 return (*
this) = (*this) * other;
749 template<
typename Matrix3x3Type>
762 template<
typename Matrix4x4Type>
827 std::stringstream result;
850 #endif // __LeapMath_h__