charles/src/basics/vector.hh

85 lines
1.8 KiB
C++
Raw Normal View History

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__
#include <ostream>
2014-08-08 20:44:43 -07:00
#include "basics/matrix.hh"
#include "basics/types.hh"
namespace charles {
namespace basics {
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>
{
Vector4(const Double& x = 0.0, const Double& y = 0.0, const Double& z = 0.0);
Vector4(const Matrix<4,1>& m);
2014-08-08 21:12:37 -07:00
Double& X();
const Double& X() const;
2014-08-08 21:12:37 -07:00
Double& Y();
const Double& Y() const;
2014-08-08 21:12:37 -07:00
Double& Z();
const Double& Z() const;
#if 0
Vector4 operator*(const Double& rhs) const;
#endif
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;
/** 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
/** Scalar multiplication of vectors, with the scalar factor on the left. */
Vector4 operator*(const Double& lhs, const Vector4& rhs);
/** Normalize the given vector and return a copy of it. */
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 20:44:43 -07:00
} /* namespace basics */
} /* namespace charles */
#endif /* __BASICS_VECTOR_HH__ */