tSelection.h

Engine/source/gui/worldEditor/tSelection.h

More...

Classes:

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _TSELECTION_H_
25#define _TSELECTION_H_
26
27#ifndef _TVECTOR_H_
28#include "core/util/tVector.h"
29#endif
30
31#ifndef _MMATRIX_H_
32#include "math/mMatrix.h"
33#endif
34
35
36template <class T>
37class Selection : public Vector<T>
38{
39public:
40
41   // Use explicit specialization to define these for your type.
42   MatrixF getOrientation() { return MatrixF(); }
43   Point3F getOrigin() { return Point3F(); }
44   Point3F getScale() { return Point3F(); }
45
46   void offset( const Point3F &delta );
47   void rotate( const EulerF &delta );
48   void scale( const Point3F &delta );
49
50protected:
51   
52   // Use explicit specialization to define these for your type.
53   virtual void offsetObject( T &object, const Point3F &delta ) {}
54   virtual void rotateObject( T &object, const EulerF &delta, const Point3F &origin ) {}
55   virtual void scaleObject( T &object, const Point3F &delta ) {}
56
57protected:
58
59   //Point3F        mCentroid;
60   //Point3F        mBoxCentroid;
61   //Box3F          mBoxBounds;
62   //bool           mCentroidValid;
63};
64
65
66template<class T> inline void Selection<T>::offset( const Point3F &delta )
67{
68   typename Selection<T>::iterator itr = this->begin();
69
70   for (; itr != this->end(); ++itr)
71      offsetObject( *itr, delta );      
72}
73
74template<class T> inline void Selection<T>::rotate( const EulerF &delta )
75{
76   typename Selection<T>::iterator itr = this->begin();
77   Point3F origin = getOrigin();
78
79   for (; itr != this->end(); ++itr)
80      rotateObject( *itr, delta, origin );
81}
82
83template<class T> inline void Selection<T>::scale( const Point3F &delta )
84{
85   // Can only scale a single selection.
86   if ( this->size() != 1 )
87      return;
88
89   scaleObject( this->mArray[0], delta );   
90}
91
92#endif // _TSELECTION_H_
93