Vec4ui 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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_VEC4UI
  14. #define OSG_VEC4UI 1
  15. namespace osg {
  16. /** General purpose integer quad
  17. **/
  18. class Vec4ui
  19. {
  20. public:
  21. /** Type of Vec class.*/
  22. typedef unsigned int value_type;
  23. /** Number of vector components. */
  24. enum { num_components = 4 };
  25. /** Vec member variable. */
  26. value_type _v[4];
  27. Vec4ui() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
  28. Vec4ui(value_type x, value_type y, value_type z, value_type w)
  29. {
  30. _v[0]=x;
  31. _v[1]=y;
  32. _v[2]=z;
  33. _v[3]=w;
  34. }
  35. inline bool operator == (const Vec4ui& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
  36. inline bool operator != (const Vec4ui& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
  37. inline bool operator < (const Vec4ui& v) const
  38. {
  39. if (_v[0]<v._v[0]) return true;
  40. else if (_v[0]>v._v[0]) return false;
  41. else if (_v[1]<v._v[1]) return true;
  42. else if (_v[1]>v._v[1]) return false;
  43. else if (_v[2]<v._v[2]) return true;
  44. else if (_v[2]>v._v[2]) return false;
  45. else return (_v[3]<v._v[3]);
  46. }
  47. inline value_type* ptr() { return _v; }
  48. inline const value_type* ptr() const { return _v; }
  49. inline void set( value_type x, value_type y, value_type z, value_type w)
  50. {
  51. _v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
  52. }
  53. inline value_type& operator [] (unsigned int i) { return _v[i]; }
  54. inline value_type operator [] (unsigned int i) const { return _v[i]; }
  55. inline value_type& x() { return _v[0]; }
  56. inline value_type& y() { return _v[1]; }
  57. inline value_type& z() { return _v[2]; }
  58. inline value_type& w() { return _v[3]; }
  59. inline value_type x() const { return _v[0]; }
  60. inline value_type y() const { return _v[1]; }
  61. inline value_type z() const { return _v[2]; }
  62. inline value_type w() const { return _v[3]; }
  63. inline value_type& r() { return _v[0]; }
  64. inline value_type& g() { return _v[1]; }
  65. inline value_type& b() { return _v[2]; }
  66. inline value_type& a() { return _v[3]; }
  67. inline value_type r() const { return _v[0]; }
  68. inline value_type g() const { return _v[1]; }
  69. inline value_type b() const { return _v[2]; }
  70. inline value_type a() const { return _v[3]; }
  71. inline Vec4ui operator * (value_type rhs) const
  72. {
  73. return Vec4ui(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
  74. }
  75. inline Vec4ui operator / (value_type rhs) const
  76. {
  77. return Vec4ui(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
  78. }
  79. inline Vec4ui operator + (value_type rhs) const
  80. {
  81. return Vec4ui(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
  82. }
  83. inline Vec4ui operator - (value_type rhs) const
  84. {
  85. return Vec4ui(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
  86. }
  87. inline Vec4ui operator + (const Vec4ui& rhs) const
  88. {
  89. return Vec4ui(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
  90. }
  91. inline Vec4ui operator - (const Vec4ui& rhs) const
  92. {
  93. return Vec4ui(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
  94. }
  95. inline Vec4ui operator * (const Vec4ui& rhs) const
  96. {
  97. return Vec4ui(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
  98. }
  99. };
  100. }
  101. #endif