Vec3ui 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSG_VEC3UI
  14. #define OSG_VEC3UI 1
  15. namespace osg {
  16. /** General purpose integer triple
  17. **/
  18. class Vec3ui
  19. {
  20. public:
  21. /** Type of Vec class.*/
  22. typedef unsigned int value_type;
  23. /** Number of vector components. */
  24. enum { num_components = 3 };
  25. /** Vec member variable. */
  26. value_type _v[3];
  27. Vec3ui() { _v[0]=0; _v[1]=0; _v[2]=0; }
  28. Vec3ui(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
  29. inline bool operator == (const Vec3ui& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
  30. inline bool operator != (const Vec3ui& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
  31. inline bool operator < (const Vec3ui& v) const
  32. {
  33. if (_v[0]<v._v[0]) return true;
  34. else if (_v[0]>v._v[0]) return false;
  35. else if (_v[1]<v._v[1]) return true;
  36. else if (_v[1]>v._v[1]) return false;
  37. else return (_v[2]<v._v[2]);
  38. }
  39. inline value_type* ptr() { return _v; }
  40. inline const value_type* ptr() const { return _v; }
  41. inline void set(value_type r, value_type g, value_type b)
  42. {
  43. _v[0]=r; _v[1]=g; _v[2]=b;
  44. }
  45. inline void set( const Vec3ui& rhs)
  46. {
  47. _v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
  48. }
  49. inline value_type& operator [] (unsigned int i) { return _v[i]; }
  50. inline value_type operator [] (unsigned int i) const { return _v[i]; }
  51. inline value_type& x() { return _v[0]; }
  52. inline value_type& y() { return _v[1]; }
  53. inline value_type& z() { return _v[2]; }
  54. inline value_type x() const { return _v[0]; }
  55. inline value_type y() const { return _v[1]; }
  56. inline value_type z() const { return _v[2]; }
  57. inline value_type& r() { return _v[0]; }
  58. inline value_type& g() { return _v[1]; }
  59. inline value_type& b() { return _v[2]; }
  60. inline value_type r() const { return _v[0]; }
  61. inline value_type g() const { return _v[1]; }
  62. inline value_type b() const { return _v[2]; }
  63. /** Multiply by scalar. */
  64. inline Vec3ui operator * (value_type rhs) const
  65. {
  66. return Vec3ui(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
  67. }
  68. inline Vec3ui operator / (value_type rhs) const
  69. {
  70. return Vec3ui(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
  71. }
  72. inline Vec3ui operator + (value_type rhs) const
  73. {
  74. return Vec3ui(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
  75. }
  76. inline Vec3ui operator - (value_type rhs) const
  77. {
  78. return Vec3ui(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
  79. }
  80. inline Vec3ui operator + (const Vec3ui& rhs) const
  81. {
  82. return Vec3ui(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
  83. }
  84. inline Vec3ui operator - (const Vec3ui& rhs) const
  85. {
  86. return Vec3ui(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
  87. }
  88. inline Vec3ui operator * (const Vec3ui& rhs) const
  89. {
  90. return Vec3ui(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
  91. }
  92. };
  93. }
  94. #endif