//-*-c++-*- #ifndef VEC4_H #define VEC4_H /** * @file vec4.h * @brief Basic static 4d vector type, templated in type * @author James R. Diebel, Stanford University * * - History: * - 31 July 2005 - Started (JD) * - 30 Aug 2005 - Commented and tested (KH) * - 30 Aug 2005 forked off from matmath.h */ #include #include /** * @namespace sla * @brief Simple Linear Algebra - library of matrix and vector classes */ namespace sla { ///////////////////////////////////////////////////////////////////////////// // DECLARATIONS ///////////////////////////////////////////////////////////////////////////// // Forward declarations template class Vec; // M-d vector template class Vec4; // 4d Vector //////////////////// Vec4 //////////////////// /** * A 4-D vector. */ template class Vec4: public Vec { public: // inherit member data and functions of parent using Vec::x; using Vec::set; // Constructors Vec4(); Vec4(const T* d); Vec4(const T a); Vec4(const T x0, const T x1, const T x2, const T x3); Vec4(const Vec& v); // Cast Operation template Vec4(const Vec& v); // Mutators void set(const T x0, const T x1, const T x2, const T x3); }; // Declare a few common typdefs typedef Vec4 Vec4b; typedef Vec4 Vec4c; typedef Vec4 Vec4uc; typedef Vec4 Vec4i; typedef Vec4 Vec4f; typedef Vec4 Vec4d; //////////////////////////////////////////////////////////////////////////// // DEFINITIONS //////////////////////////////////////////////////////////////////////////// //////////////////// Vec4 //////////////////// // Constructors /** Ctor that doesn't initialize. */ template inline Vec4::Vec4() {} /** Ctor that intalizes from array. */ template inline Vec4::Vec4(const T* d) : Vec(d) {} /** Ctor that intalizes all elements from a scalar. */ template inline Vec4::Vec4(const T a) : Vec(a) {} /** Ctor that initializes vector with given values. */ template inline Vec4::Vec4(const T x0, const T x1, const T x2, const T x3) { set(x0,x1,x2,x3); } /** Ctor that initializes an Vec4 with an Vec. */ template inline Vec4::Vec4(const Vec& v) : Vec(v) {} // Casting Operation /** Casting Ctor that initializes an Vec4 with a Vec. */ template template inline Vec4::Vec4(const Vec& v) : Vec(v) {} // Mutators /** Set vector. */ template inline void Vec4::set(const T x0, const T x1, const T x2, const T x3) { x[0] = x0; x[1] = x1; x[2] = x2; x[3] = x3; } } // end namespace sla #endif