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=0.0F)
 
 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 38 of file vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/3]

Vector::Vector ( )
inline

Constructor.

Definition at line 44 of file vector.h.

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

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

◆ Vector() [2/3]

Vector::Vector ( const float  x0,
const float  y0,
const float  z0 = 0.0F 
)
inline

Constructor.

Definition at line 53 of file vector.h.

55  :
56  x(x0),
57  y(y0),
58  z(z0)
59  {}
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ Vector() [3/3]

Vector::Vector ( const Vector v)
inline

Copy constructor.

Definition at line 64 of file vector.h.

References A_DEFAULT_COPY.

64  :
65  x(v.x),
66  y(v.y),
67  z(v.z)
68  {}
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

Member Function Documentation

◆ isNull()

bool Vector::isNull ( ) const
inline

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

Definition at line 76 of file vector.h.

References x, y, and z.

77  {
78  return x == 0.0F && y == 0.0F && z == 0.0F;
79  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ length()

float Vector::length ( ) const
inline

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

Definition at line 177 of file vector.h.

References x, y, and z.

Referenced by normalized().

178  {
179  return sqrtf(x * x + y * y + z * z);
180  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ manhattanLength()

float Vector::manhattanLength ( ) const
inline

Returns the manhattan length of this vector.

Definition at line 193 of file vector.h.

References x, y, and z.

194  {
195  return fabsf(x) + fabsf(y) + fabsf(z);
196  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ 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 202 of file vector.h.

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

203  {
204  const float len = length();
205  return Vector(x / len, y / len, z / len);
206  }
Vector()
Definition: vector.h:44
float length() const
Definition: vector.h:177
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator*()

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

Scale vector operator.

Definition at line 92 of file vector.h.

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

93  {
94  return Vector(x * c,
95  y * c,
96  z * c);
97  }
Vector()
Definition: vector.h:44
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator*=()

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

In-place scale vector operator.

Definition at line 102 of file vector.h.

References x, y, and z.

103  {
104  x *= c;
105  y *= c;
106  z *= c;
107  return *this;
108  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator+()

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

Add vector operator.

Definition at line 134 of file vector.h.

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

135  {
136  return Vector(x + v.x,
137  y + v.y,
138  z + v.z);
139  }
Vector()
Definition: vector.h:44
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator+=()

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

In-place add vector operator.

Definition at line 144 of file vector.h.

References x, y, and z.

145  {
146  x += v.x;
147  y += v.y;
148  z += v.z;
149  return *this;
150  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator-()

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

Subtract vector operator.

Definition at line 155 of file vector.h.

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

156  {
157  return Vector(x - v.x,
158  y - v.y,
159  z - v.z);
160  }
Vector()
Definition: vector.h:44
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator-=()

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

In-place subtract vector operator.

Definition at line 165 of file vector.h.

References x, y, and z.

166  {
167  x -= v.x;
168  y -= v.y;
169  z -= v.z;
170  return *this;
171  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator/()

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

Scale vector operator.

Definition at line 113 of file vector.h.

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

114  {
115  return Vector(x / c,
116  y / c,
117  z / c);
118  }
Vector()
Definition: vector.h:44
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator/=()

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

In-place scale vector operator.

Definition at line 123 of file vector.h.

References x, y, and z.

124  {
125  x /= c;
126  y /= c;
127  z /= c;
128  return *this;
129  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ operator=()

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

Definition at line 81 of file vector.h.

References x, y, and z.

82  {
83  x = v.x;
84  y = v.y;
85  z = v.z;
86  return *this;
87  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

◆ squaredLength()

float Vector::squaredLength ( ) const
inline

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

Definition at line 185 of file vector.h.

References x, y, and z.

186  {
187  return x * x + y * y + z * z;
188  }
float x
Definition: vector.h:208
float y
Definition: vector.h:208
float z
Definition: vector.h:208

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: