source: projectionDesigner/tag/ProjectionDesigner_1.1.5/projdesigner/include/gmtl/Vec.h @ 2

Last change on this file since 2 was 2, checked in by Torben Dannhauer, 14 years ago
File size: 4.4 KB
Line 
1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          Vec.h,v
10 * Date modified: 2004/11/12 01:34:49
11 * Version:       1.21
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_VEC_H_
36#define _GMTL_VEC_H_
37
38#include <gmtl/Defines.h>
39#include <gmtl/Config.h>
40#include <gmtl/VecBase.h>
41#include <gmtl/Util/StaticAssert.h>
42
43namespace gmtl
44{
45
46/**
47 * A representation of a vector with SIZE components using DATA_TYPE as the data
48 * type for each component.
49 *
50 * @param DATA_TYPE     the datatype to use for the components
51 * @param SIZE          the number of components this VecBase has
52 * @see Vec3f
53 * @see Vec4f
54 * @see Vec3d
55 * @see Vec4f
56 * @ingroup Types
57 */
58template<class DATA_TYPE, unsigned SIZE>
59#ifdef GMTL_NO_METAPROG
60class Vec : public VecBase<DATA_TYPE, SIZE>
61#else
62class Vec : public VecBase<DATA_TYPE, SIZE, meta::DefaultVecTag>
63#endif
64{
65public:
66   /// The datatype used for the components of this Vec.
67   typedef DATA_TYPE DataType;
68
69   /// The number of components this Vec has.
70   enum Params { Size = SIZE };
71
72   /// The superclass type.
73   typedef VecBase<DATA_TYPE, SIZE> BaseType;
74   typedef Vec<DATA_TYPE, SIZE> VecType;
75
76public:
77   /**
78    * Default constructor. All components are initialized to zero.
79    */
80   Vec()
81   {
82      for (unsigned i = 0; i < SIZE; ++i)
83         this->mData[i] = (DATA_TYPE)0;
84   }
85
86   /// @name Value constructors
87   //@{
88   /**
89    * Make an exact copy of the given Vec object.
90    * @pre  Vector should be the same size and type as the one copied
91    * @param rVec    the Vec object to copy
92    */
93   /*
94   Vec( const Vec<DATA_TYPE, SIZE>& rVec )
95      : BaseType( static_cast<BaseType>( rVec ) )
96   {;}
97   */
98
99#ifdef GMTL_NO_METAPROG
100   Vec( const VecBase<DATA_TYPE, SIZE>& rVec )
101      : BaseType( rVec )
102   {
103   }
104#else
105   template<typename REP2>
106   Vec( const VecBase<DATA_TYPE, SIZE, REP2>& rVec )
107      : BaseType( rVec )
108   {
109   }
110#endif
111
112   /**
113    * Creates a new Vec initialized to the given values.
114    */
115   Vec(const DATA_TYPE& val0,const DATA_TYPE& val1)
116   : BaseType(val0, val1)
117   {
118      GMTL_STATIC_ASSERT( SIZE == 2, Out_Of_Bounds_Element_Access_In_Vec );
119   }
120
121   Vec(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2)
122   : BaseType(val0, val1, val2)
123   {
124      GMTL_STATIC_ASSERT( SIZE == 3, Out_Of_Bounds_Element_Access_In_Vec );
125   }
126
127   Vec(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2,const DATA_TYPE& val3)
128   : BaseType(val0, val1, val2, val3)
129   {
130      GMTL_STATIC_ASSERT( SIZE == 4, Out_Of_Bounds_Element_Access_In_Vec );
131   }
132   //@}
133
134   /** Assign from different rep. */
135#ifdef GMTL_NO_METAPROG
136   inline VecType& operator=(const VecBase<DATA_TYPE,SIZE>& rhs)
137   {
138      BaseType::operator=(rhs);
139      return *this;
140   }
141#else
142   template<typename REP2>
143   inline VecType& operator=(const VecBase<DATA_TYPE,SIZE,REP2>& rhs)
144   {
145      BaseType::operator=(rhs);
146      return *this;
147   }
148#endif
149};
150
151// --- helper types --- //
152typedef Vec<int, 2> Vec2i;
153typedef Vec<float,2> Vec2f;
154typedef Vec<double,2> Vec2d;
155typedef Vec<int, 3> Vec3i;
156typedef Vec<float,3> Vec3f;
157typedef Vec<double,3> Vec3d;
158typedef Vec<int, 4> Vec4i;
159typedef Vec<float,4> Vec4f;
160typedef Vec<double,4> Vec4d;
161
162}
163
164#endif
Note: See TracBrowser for help on using the repository browser.