Nxna2
 All Classes Namespaces Functions Enumerations Enumerator Pages
Vector3.h
1 #ifndef MATH_VECTOR3_H
2 #define MATH_VECTOR3_H
3 
4 #include "MathBase.h"
5 
6 namespace Nxna
7 {
8  struct Quaternion;
9  struct Matrix;
10 
11  struct Vector3
12  {
13  Vector3()
14  {
15  X = 0; Y = 0; Z = 0;
16  }
17 
18  Vector3(float x, float y, float z)
19  : X(x), Y(y), Z(z)
20  {
21  }
22 
23  Vector3 operator *(float s) const
24  {
25  return Vector3(X * s, Y * s, Z * s);
26  }
27 
28  Vector3 operator *(const Vector3& v) const
29  {
30  return Vector3(X * v.X, Y * v.Y, Z * v.Z);
31  }
32 
33  Vector3 operator /(float s) const
34  {
35  return Vector3(X / s, Y / s, Z / s);
36  }
37 
38  Vector3 operator -(const Vector3& v) const
39  {
40  return Vector3(X - v.X, Y - v.Y, Z - v.Z);
41  }
42 
43  Vector3 operator-() const
44  {
45  return Vector3(-X, -Y, -Z);
46  }
47 
48  Vector3 operator +(const Vector3& v) const
49  {
50  return Vector3(X + v.X, Y + v.Y, Z + v.Z);
51  }
52 
53  void operator +=(const Vector3& v)
54  {
55  X += v.X;
56  Y += v.Y;
57  Z += v.Z;
58  }
59 
60  void operator -=(const Vector3& v)
61  {
62  X -= v.X;
63  Y -= v.Y;
64  Z -= v.Z;
65  }
66 
67  void operator *=(float s)
68  {
69  X *= s;
70  Y *= s;
71  Z *= s;
72  }
73 
74  void operator /=(float s)
75  {
76  X /= s;
77  Y /= s;
78  Z /= s;
79  }
80 
81  float Length() const
82  {
83  return sqrtf(X * X + Y * Y + Z * Z);
84  }
85 
86  float LengthSquared() const
87  {
88  return X * X + Y * Y + Z * Z;
89  }
90 
91  void Normalize();
92 
93  union
94  {
95  struct
96  {
97  float X, Y, Z;
98  };
99  float C[3];
100  };
101 
102  static const Vector3 Up;
103  static const Vector3 Forward;
104  static const Vector3 Zero;
105  static const Vector3 Right;
106 
107  static const Vector3 UnitX;
108  static const Vector3 UnitY;
109  static const Vector3 UnitZ;
110 
111  static void Multiply(const Vector3& v, float scaleFactor, Vector3& result)
112  {
113  result.X = v.X * scaleFactor;
114  result.Y = v.Y * scaleFactor;
115  result.Z = v.Z * scaleFactor;
116  }
117 
118  static void Dot(const Vector3& v1, const Vector3& v2, float& result);
119  static Vector3 Cross(const Vector3& v1, const Vector3& v2);
120  static void Cross(const Vector3& v1, const Vector3& v2, Vector3& result);
121  static Vector3 Normalize(const Vector3& v);
122  static void Normalize(const Vector3& v, Vector3& result);
123  static Vector3 Transform(const Vector3& v, const Matrix& matrix) { Vector3 result; Transform(v, matrix, result); return result; }
124  static void Transform(const Vector3& v, const Matrix& matrix, Vector3& result);
125  static void Transform(const Vector3& v, const Quaternion& quat, Vector3& result);
126  static Vector3 TransformNormal(const Vector3& normal, const Matrix& matrix) { Vector3 v; TransformNormal(normal, matrix, v); return v; }
127  static void TransformNormal(const Vector3& normal, const Matrix& matrix, Vector3& result);
128 
129  static float Distance(const Vector3& v1, const Vector3& v2);
130  static float DistanceSquared(const Vector3& v1, const Vector3& v2);
131  };
132 }
133 
134 #endif // MATH_VECTOR3_H
Definition: Quaternion.h:6
Definition: Vector3.h:11
Definition: Matrix.h:8