tSelection.h 2.9 KB

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