/* * Copyright (C) 2008 * Robert Bosch LLC * Research and Technology Center North America * Palo Alto, California * * All rights reserved. * *------------------------------------------------------------------------------ * project ....: Autonomous Technologies * file .......: Vec3.h * authors ....: Benjamin Pitzer * organization: Robert Bosch LLC * creation ...: 08/16/2006 * modified ...: $Date: 2009-01-21 18:19:16 -0800 (Wed, 21 Jan 2009) $ * changed by .: $Author: benjaminpitzer $ * revision ...: $Revision: 14 $ */ #ifndef RTC_VEC3_H #define RTC_VEC3_H //== INCLUDES ================================================================== #include "rtcMath.h" #include "rtcVec.h" //== NAMESPACES ================================================================ namespace rtc { // Forward declarations template class Vec; // M-d vector template class Vec3; // 3d Vector template class SMat3; // 3x3 square matrix /** * A 3-D vector. */ template class Vec3: public Vec { public: // Constructors Vec3(); Vec3(const T* d); Vec3(const T a); Vec3(const T x0, const T x1, const T x2); Vec3(const Vec& v); // Cast Operation template Vec3(const Vec& v); // Mutators void set(const T x0, const T x1, const T x2); // Cross Product Vec3 cross(const Vec3& v) const; // Cross Product operator inline Vec3 operator%(const Vec3& v) const; // inherit member data and functions of parent using Vec::x; using Vec::set; }; // Declare a few common typdefs typedef Vec3 Vec3b; typedef Vec3 Vec3c; typedef Vec3 Vec3uc; typedef Vec3 Vec3s; typedef Vec3 Vec3us; typedef Vec3 Vec3i; typedef Vec3 Vec3ui; typedef Vec3 Vec3f; typedef Vec3 Vec3d; //============================================================================== // Vec3 //============================================================================== // Constructors /** Ctor that doesn't initialize. */ template inline Vec3::Vec3() {} /** Ctor that intalizes from array. */ template inline Vec3::Vec3(const T* d) : Vec(d) {} /** Ctor that intalizes all elements from a scalar. */ template inline Vec3::Vec3(const T a) : Vec(a) {} /** Ctor that initializes vector with given values. */ template inline Vec3::Vec3(const T x0, const T x1, const T x2) { set(x0,x1,x2); } /** Ctor that initializes an Vec3 with an Vec. */ template inline Vec3::Vec3(const Vec& v) : Vec(v){} // Casting Operation /** Casting Ctor that initializes an Vec3 with a Vec. */ template template inline Vec3::Vec3(const Vec& v) : Vec(v) {} // Mutators /** Set vector. */ template inline void Vec3::set(const T x0, const T x1, const T x2) { x[0] = x0; x[1] = x1; x[2] = x2; } // Cross Product /** Calculate the cross product. * @param v a 3-vector * @return the cross product: "this" cross "v" */ template inline Vec3 Vec3::cross(const Vec3& v) const { return Vec3(x[1]*v.x[2]-x[2]*v.x[1], x[2]*v.x[0]-x[0]*v.x[2], x[0]*v.x[1]-x[1]*v.x[0]); } /// cross product: only defined for Vec3* as specialization /// \see Vec3::cross template inline Vec3 Vec3::operator%(const Vec3& v) const { return cross(v); } //============================================================================== } // NAMESPACE rtc //============================================================================== #endif // RTC_VEC3_H defined //==============================================================================