/******************************************************************************/ /*! \file vec3f.hpp \date 6/14/2005 \brief This is the interface file for the Vec3f class, a 3-element, single-precision(float) vector class. *******************************************************************************/ #ifndef FUEL_VEC3F_H #define FUEL_VEC3F_H #include <math.h> namespace Fuel { namespace Math { class Vec3f; inline bool operator==(const Vec3f &lhs, const Vec3f &rhs); inline bool operator!=(const Vec3f &lhs, const Vec3f &rhs); inline Vec3f operator *(const Vec3f &lhs, const Vec3f &rhs); inline Vec3f operator /(const Vec3f &lhs, const Vec3f &rhs); inline Vec3f operator +(const Vec3f &lhs, const Vec3f &rhs); inline Vec3f operator -(const Vec3f &lhs, const Vec3f &rhs); inline Vec3f operator *(const Vec3f &lhs, const float rhs); inline Vec3f operator /(const Vec3f &lhs, const float rhs); inline Vec3f operator -(const Vec3f &src); /******************************************************************************/ /*! \class Vec3f \brief The Vec3f class impliments a 3-element, single-precision(float) vector class. Operations include: - Default and Copy constructors - Parameterized constructor (X, Y, Z) - Parameterized constructor (from v1 to v2) - Equality and inequality operators - Assignment operator - Multiplication, Division, Addition and subtraction of vectors. - Multiplication and Division by scalars. - Cross product - Dot product - Length^2 and length functions - unitization functions *******************************************************************************/ class Vec3f { public: Vec3f() { } Vec3f(float x, float y, float z) : X(x), Y(y), Z(z) { } Vec3f(const Vec3f &src); Vec3f(const Vec3f &from, const Vec3f &to); // equality operators friend bool operator==(const Vec3f &lhs, const Vec3f &rhs); friend bool operator!=(const Vec3f &lhs, const Vec3f &rhs); // self-modifying operators inline void operator =(const Vec3f &rhs); inline void operator*=(const Vec3f &rhs); inline void operator/=(const Vec3f &rhs); inline void operator+=(const Vec3f &rhs); inline void operator-=(const Vec3f &rhs); inline void operator*=(const float rhs); inline void operator/=(const float rhs); inline void normalize(); // three-opperand methods static inline void mul(Vec3f &res, const Vec3f &lhs, const Vec3f &rhs); static inline void div(Vec3f &res, const Vec3f &lhs, const Vec3f &rhs); static inline void add(Vec3f &res, const Vec3f &lhs, const Vec3f &rhs); static inline void sub(Vec3f &res, const Vec3f &lhs, const Vec3f &rhs); static inline void add(Vec3f &res, const Vec3f &lhs, const float rhs); static inline void sub(Vec3f &res, const Vec3f &lhs, const float rhs); static inline void cross(Vec3f &res, const Vec3f &lhs, const float rhs); static inline Vec3f cross(const Vec3f &lhs, const Vec3f &rhs); static inline float dot(const Vec3f &lhs, const Vec3f &rhs); static inline float rad(const Vec3f &src); // Length^2 static inline float abs(const Vec3f &src); // Length static inline Vec3f norm() const; // temp-modifying operators friend Vec3f operator*(const Vec3f &lhs, const Vec3f &rhs); friend Vec3f operator/(const Vec3f &lhs, const Vec3f &rhs); friend Vec3f operator+(const Vec3f &lhs, const Vec3f &rhs); friend Vec3f operator-(const Vec3f &lhs, const Vec3f &rhs); friend Vec3f operator*(const Vec3f &lhs, const float rhs); friend Vec3f operator/(const Vec3f &lhs, const float rhs); friend Vec3f operator-(const Vec3f &src); // usefull constants static const Vec3f ZEROVECTOR; static const Vec3f UNIT_POS_X; static const Vec3f UNIT_POS_Y; static const Vec3f UNIT_POS_Z; static const Vec3f UNIT_NEG_X; static const Vec3f UNIT_NEG_Y; static const Vec3f UNIT_NEG_Z; float X, Y, Z; };