Code:
#ifndef __VECTOR3D_H_INCLUDED__
#define __VECTOR3D_H_INCLUDED__
#include <cmath>
#include "matrix.h"
#include "euler.h"
#include "quaternion.h"
using namespace std;
class Matrix3X3;
class Quaternion;
class EulerAngle;
class Vector3D {
public:
float x, y, z;
/*Constructors / Deconstructors:
Vector3D v: x, y, and z are all undefined.
Vector3D v2(1, 2, 3): x, y, and z are set to 1, 2, and 3, respectivly.
Vector3D v3(Vector3D v4): v3.x, v3.y, and v3.z are all set to v4.x, v4.y, and v4.z, respectivly.
~Vector3D(): Deconstructs the vector.
*/
Vector3D() {}
Vector3D(float a, float b, float c) : x(a), y(b), z(c) {}
Vector3D(const Vector3D &v) : x(v.x), y(v.y), z(v.z) {}
~Vector3D() {}
/*Operator overloadings:
Vector3D operator+(const Vector3D &v): x, y, and z are added to v.x, v.y, and v.z, respectivly.
Vector3D operator-(const Vector3D &v): x, y, and z are subtracted from v.x, v.y, and v.z, respectivly.
Vector3D operator*(float w): x, y, and z are all multiplied by w.
Vector3D operator/(float w): x, y, and z are all divided by w.
Vector3D operator-(): negate the vector - x, y, and z are set to -x, -y, and -z, respectivly
Vector3D &operator+=(const Vector3D &v): x, y, and z are added to v.x, v.y, and v.z, respectivly, and vector is set with new values.
Vector3D &operator-=(const Vector3D &v): x, y, and z are subtracted from v.x, v.y, and v.z, respectivly, and vector is set with new values.
Vector3D &operator*=(float w): x, y, and z are all multiplied by w, and vector is set with new values.
Vector3D &operator/=(float w): x, y, and z are all divided by w, and vector is set with new values.
Vector3D &operator=(const Vector3D &v): this vector is set to v.
bool operator==(const Vector3D &v): returns true if Vector3Ds' are equal, false otherwise.
bool operator!=(const Vector3D &v): returns true if Vector3Ds' are not equal, false otherwise.
*/
const Vector3D operator+(const Vector3D &v) const;
const Vector3D operator-(const Vector3D &v) const;
const Vector3D operator*(float w) const;
const Vector3D operator/(float w) const;
Vector3D operator-() const;
Vector3D &operator+=(const Vector3D &v);
Vector3D &operator-=(const Vector3D &v);
Vector3D &operator*=(float w);
Vector3D &operator/=(float w);
Vector3D &operator=(const Vector3D &v);
bool operator==(const Vector3D &v) const;
bool operator!=(const Vector3D &v) const;
/*Other functions:
float length(): returns the length of the vector.
Vector3D normalize(): normalize the vector, vector / length of vector
float dotProduct(const Vector3D &v): returns the dotProduct, x * v.x + y * v.y + z * v.z
Vector3D crossProduct(const Vector3D &v): returns cross product between this vector and v.
float distance(const Vector3D &v): returns distance between this vector and v.
float angleBetween(const Vector3D &v): returns the angle (in radians) between the 2 vectors.
*/
float length() const;
Vector3D normalize() const;
float dotProduct(const Vector3D &v) const;
Vector3D crossProduct(const Vector3D &v) const;
float distance(const Vector3D &v) const;
float angleBetween(const Vector3D &v) const;
};
#endif