2014-08-08 20:44:43 -07:00
|
|
|
/* vector.hh
|
|
|
|
* vim: set tw=80:
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BASICS_VECTOR_HH__
|
|
|
|
#define __BASICS_VECTOR_HH__
|
|
|
|
|
2014-08-09 11:55:10 -07:00
|
|
|
#include <ostream>
|
|
|
|
|
2014-08-08 20:44:43 -07:00
|
|
|
#include "basics/matrix.hh"
|
|
|
|
#include "basics/types.hh"
|
|
|
|
|
|
|
|
|
|
|
|
namespace charles {
|
|
|
|
namespace basics {
|
|
|
|
|
2014-08-08 21:47:44 -07:00
|
|
|
template<UInt N>
|
2014-08-08 20:44:43 -07:00
|
|
|
struct Vector
|
|
|
|
: public Matrix<N,1>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
|
2014-08-08 21:12:37 -07:00
|
|
|
struct Vector4
|
|
|
|
: public Vector<4>
|
|
|
|
{
|
2014-08-09 10:08:44 -07:00
|
|
|
Vector4(const Double& x = 0.0, const Double& y = 0.0, const Double& z = 0.0);
|
2014-08-10 09:42:02 -07:00
|
|
|
Vector4(const Matrix<4,1>& m);
|
2014-08-08 21:12:37 -07:00
|
|
|
|
|
|
|
Double& X();
|
2014-08-09 09:01:52 -07:00
|
|
|
const Double& X() const;
|
2014-08-08 21:12:37 -07:00
|
|
|
Double& Y();
|
2014-08-09 09:01:52 -07:00
|
|
|
const Double& Y() const;
|
2014-08-08 21:12:37 -07:00
|
|
|
Double& Z();
|
2014-08-09 09:01:52 -07:00
|
|
|
const Double& Z() const;
|
2014-08-08 23:05:38 -07:00
|
|
|
|
2014-08-10 09:42:02 -07:00
|
|
|
#if 0
|
2014-08-09 09:32:48 -07:00
|
|
|
Vector4 operator*(const Double& rhs) const;
|
2014-08-10 09:42:02 -07:00
|
|
|
#endif
|
2014-08-09 09:32:48 -07:00
|
|
|
|
|
|
|
Vector4 operator+(const Vector4& rhs) const;
|
|
|
|
Vector4& operator+=(const Vector4& rhs);
|
|
|
|
Vector4 operator-(const Vector4& rhs) const;
|
|
|
|
Vector4& operator-=(const Vector4& rhs);
|
|
|
|
|
|
|
|
Vector4 operator-() const;
|
|
|
|
|
2014-08-08 23:05:38 -07:00
|
|
|
/** Get the length-squared of this vector. */
|
|
|
|
Double Length2() const;
|
|
|
|
|
|
|
|
/** Get the length of this vector. */
|
|
|
|
Double Length() const;
|
|
|
|
|
|
|
|
/** Get the dot product of `this` and `rhs`. */
|
|
|
|
Double Dot(const Vector4& rhs) const;
|
|
|
|
|
|
|
|
/** Get the cross product of `this` and `rhs`. */
|
|
|
|
Vector4 Cross(const Vector4& rhs) const;
|
|
|
|
|
|
|
|
/** Normalize this vector. */
|
|
|
|
Vector4& Normalize();
|
2014-08-08 21:12:37 -07:00
|
|
|
};
|
2014-08-08 20:44:43 -07:00
|
|
|
|
2014-08-08 23:05:38 -07:00
|
|
|
|
2014-08-09 09:32:48 -07:00
|
|
|
/** Scalar multiplication of vectors, with the scalar factor on the left. */
|
|
|
|
Vector4 operator*(const Double& lhs, const Vector4& rhs);
|
|
|
|
|
|
|
|
|
2014-08-08 23:05:38 -07:00
|
|
|
/** Normalize the given vector and return a copy of it. */
|
2014-08-09 11:55:10 -07:00
|
|
|
Vector4 Normalized(const Vector4& v);
|
|
|
|
|
|
|
|
|
|
|
|
Vector4 LinearCombination(const Double k1, const Vector4& v1,
|
|
|
|
const Double k2, const Vector4& v2,
|
|
|
|
const Double k3, const Vector4& v3);
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& ost, const Vector4& v);
|
2014-08-08 23:05:38 -07:00
|
|
|
|
2014-08-08 20:44:43 -07:00
|
|
|
} /* namespace basics */
|
|
|
|
} /* namespace charles */
|
|
|
|
|
|
|
|
#endif /* __BASICS_VECTOR_HH__ */
|
|
|
|
|