ManaPlus
Public Member Functions | Data Fields
Vector Class Reference

#include <vector.h>

Public Member Functions

 Vector ()
 
 Vector (const float x0, const float y0, const float z0)
 
 Vector (const Vector &v)
 
bool isNull () const
 
Vectoroperator= (const Vector &v)
 
Vector operator* (const float c) const
 
Vectoroperator*= (const float c)
 
Vector operator/ (const float c) const
 
Vectoroperator/= (const float c)
 
Vector operator+ (const Vector &v) const
 
Vectoroperator+= (const Vector &v)
 
Vector operator- (const Vector &v) const
 
Vectoroperator-= (const Vector &v)
 
float length () const
 
float squaredLength () const
 
float manhattanLength () const
 
Vector normalized () const
 

Data Fields

float x
 
float y
 
float z
 

Detailed Description

Vector class. Represents either a 3D point in space, a velocity or a force. Provides several convenient operator overloads.

Definition at line 39 of file vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/3]

Vector::Vector ( )
inline

Constructor.

Definition at line 45 of file vector.h.

45  :
46  x(0.0F),
47  y(0.0F),
48  z(0.0F)
49  {}
float z
Definition: vector.h:209
float y
Definition: vector.h:209
float x
Definition: vector.h:209

Referenced by normalized(), operator*(), operator+(), operator-(), and operator/().

◆ Vector() [2/3]

Vector::Vector ( const float  x0,
const float  y0,
const float  z0 
)
inline

Constructor.

Definition at line 54 of file vector.h.

56  :
57  x(x0),
58  y(y0),
59  z(z0)
60  {}

◆ Vector() [3/3]

Vector::Vector ( const Vector v)
inline

Copy constructor.

Definition at line 65 of file vector.h.

65  :
66  x(v.x),
67  y(v.y),
68  z(v.z)
69  {}

Member Function Documentation

◆ isNull()

bool Vector::isNull ( ) const
inline

Returns true if all coordinates are set to 0, otherwise returns false.

Definition at line 77 of file vector.h.

78  {
79  return x == 0.0F && y == 0.0F && z == 0.0F;
80  }

References x, y, and z.

◆ length()

float Vector::length ( ) const
inline

Returns the length of this vector. This method does a relatively slow square root.

Definition at line 178 of file vector.h.

179  {
180  return sqrtf(x * x + y * y + z * z);
181  }

References x, y, and z.

Referenced by normalized().

◆ manhattanLength()

float Vector::manhattanLength ( ) const
inline

Returns the manhattan length of this vector.

Definition at line 194 of file vector.h.

195  {
196  return fabsf(x) + fabsf(y) + fabsf(z);
197  }

References x, y, and z.

◆ normalized()

Vector Vector::normalized ( ) const
inline

Returns a normalized version of this vector. This is a unit vector running parallel to it.

Definition at line 203 of file vector.h.

204  {
205  const float len = length();
206  return Vector(x / len, y / len, z / len);
207  }
float length() const
Definition: vector.h:178
Vector()
Definition: vector.h:45

References length(), Vector(), x, y, and z.

◆ operator*()

Vector Vector::operator* ( const float  c) const
inline

Scale vector operator.

Definition at line 93 of file vector.h.

94  {
95  return Vector(x * c,
96  y * c,
97  z * c);
98  }

References Vector(), x, y, and z.

◆ operator*=()

Vector& Vector::operator*= ( const float  c)
inline

In-place scale vector operator.

Definition at line 103 of file vector.h.

104  {
105  x *= c;
106  y *= c;
107  z *= c;
108  return *this;
109  }

References x, y, and z.

◆ operator+()

Vector Vector::operator+ ( const Vector v) const
inline

Add vector operator.

Definition at line 135 of file vector.h.

136  {
137  return Vector(x + v.x,
138  y + v.y,
139  z + v.z);
140  }

References Vector(), x, y, and z.

◆ operator+=()

Vector& Vector::operator+= ( const Vector v)
inline

In-place add vector operator.

Definition at line 145 of file vector.h.

146  {
147  x += v.x;
148  y += v.y;
149  z += v.z;
150  return *this;
151  }

References x, y, and z.

◆ operator-()

Vector Vector::operator- ( const Vector v) const
inline

Subtract vector operator.

Definition at line 156 of file vector.h.

157  {
158  return Vector(x - v.x,
159  y - v.y,
160  z - v.z);
161  }

References Vector(), x, y, and z.

◆ operator-=()

Vector& Vector::operator-= ( const Vector v)
inline

In-place subtract vector operator.

Definition at line 166 of file vector.h.

167  {
168  x -= v.x;
169  y -= v.y;
170  z -= v.z;
171  return *this;
172  }

References x, y, and z.

◆ operator/()

Vector Vector::operator/ ( const float  c) const
inline

Scale vector operator.

Definition at line 114 of file vector.h.

115  {
116  return Vector(x / c,
117  y / c,
118  z / c);
119  }

References Vector(), x, y, and z.

◆ operator/=()

Vector& Vector::operator/= ( const float  c)
inline

In-place scale vector operator.

Definition at line 124 of file vector.h.

125  {
126  x /= c;
127  y /= c;
128  z /= c;
129  return *this;
130  }

References x, y, and z.

◆ operator=()

Vector& Vector::operator= ( const Vector v)
inline

Definition at line 82 of file vector.h.

83  {
84  x = v.x;
85  y = v.y;
86  z = v.z;
87  return *this;
88  }

References x, y, and z.

◆ squaredLength()

float Vector::squaredLength ( ) const
inline

Returns the squared length of this vector. Avoids the square root.

Definition at line 186 of file vector.h.

187  {
188  return x * x + y * y + z * z;
189  }

References x, y, and z.

Field Documentation

◆ x

float Vector::x

◆ y

float Vector::y

◆ z

float Vector::z

The documentation for this class was generated from the following file: