source: projectionDesigner/trunk/projdesigner/include/gmtl/Point.h @ 373

Last change on this file since 373 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 4.4 KB
RevLine 
[4]1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          Point.h,v
10 * Date modified: 2004/10/30 18:24:33
11 * Version:       1.18
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_POINT_H_
36#define _GMTL_POINT_H_
37
38#include <gmtl/Defines.h>
39#include <gmtl/VecBase.h>
40
41namespace gmtl
42{
43
44/** Point
45 *  Use points when you need to represent a position.  Don't use points to
46 *  represent a Vector.  One difference you should note is that
47 *  ceratain matrix operations are different between Point and Vec such as
48 *  xform and operator*.  A Vec xform by matrix is simply a rotation,
49 *  while a Point xformed by a matrix is a full matrix transform
50 *  (rotation, skew, translation, scale).
51 *
52 * @see Point3f
53 * @see Point4f
54 * @see Point3d
55 * @see Point4f
56 * @ingroup Types
57 */
58template<class DATA_TYPE, unsigned SIZE>
59class Point : public VecBase<DATA_TYPE, SIZE>
60{
61public:
62   typedef DATA_TYPE DataType;
63   enum Params { Size = SIZE };
64
65   /** Placeholder for the base type */
66   typedef VecBase<DATA_TYPE, SIZE> BaseType;
67   typedef Point<DATA_TYPE, SIZE> VecType;
68
69public:
70   /** Default constructor
71    */
72   Point()
73   {
74      for (unsigned i = 0; i < SIZE; ++i)
75         this->mData[i] = (DATA_TYPE)0;
76   }
77
78   /** @name Value constructors
79    * Construct with copy of rVec
80    */
81   //@{
82   /*
83   Point(const Point<DATA_TYPE, SIZE>& rVec)
84      : BaseType(static_cast<BaseType>(rVec))
85   {;}
86   */
87
88#ifdef GMTL_NO_METAPROG
89   Point(const VecBase<DATA_TYPE, SIZE>& rVec)
90      : BaseType(rVec)
91   {;}
92#else
93   template<typename REP2>
94   Point( const VecBase<DATA_TYPE, SIZE, REP2>& rVec )
95      : BaseType( rVec )
96   {
97   }
98#endif
99
100   /**
101    * Construct a 2-D point with 2 given values
102    */
103   Point(const DATA_TYPE& val0,const DATA_TYPE& val1)
104   : BaseType(val0, val1)
105   {
106      // @todo need compile time assert
107      gmtlASSERT( SIZE == 2 && "out of bounds element access in Point" );
108   }
109
110   /**
111    * Construct a 3-D point with 2 given values
112    */
113   Point(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2)
114   : BaseType(val0, val1, val2)
115   {
116      // @todo need compile time assert
117      gmtlASSERT( SIZE == 3 && "out of bounds element access in Point" );
118   }
119
120   /**
121    * Construct a 4-D point with 2 given values
122    */
123   Point(const DATA_TYPE& val0,const DATA_TYPE& val1,const DATA_TYPE& val2,const DATA_TYPE& val3)
124   : BaseType(val0, val1, val2, val3)
125   {
126      // @todo need compile time assert
127      gmtlASSERT( SIZE == 4 && "out of bounds element access in Point" );
128   }
129   //@}
130
131   /** Assign from different rep. */
132#ifdef GMTL_NO_METAPROG
133   inline VecType& operator=(const VecBase<DATA_TYPE,SIZE>& rhs)
134   {
135      BaseType::operator=(rhs);
136      return *this;
137   }
138#else
139   template<typename REP2>
140   inline VecType& operator=(const VecBase<DATA_TYPE,SIZE,REP2>& rhs)
141   {
142      BaseType::operator=(rhs);
143      return *this;
144   }
145#endif
146
147};
148
149// --- helper types --- //
150typedef Point<int,2> Point2i;
151typedef Point<float,2> Point2f;
152typedef Point<double,2> Point2d;
153typedef Point<int, 3> Point3i;
154typedef Point<float,3> Point3f;
155typedef Point<double,3> Point3d;
156typedef Point<int, 4> Point4i;
157typedef Point<float,4> Point4f;
158typedef Point<double,4> Point4d;
159
160
161};
162
163#endif
Note: See TracBrowser for help on using the repository browser.