OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec4us.h
Go to the documentation of this file.
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 
14 #ifndef OSG_VEC4US
15 #define OSG_VEC4US 1
16 
17 namespace osg {
18 
25 class Vec4us
26 {
27  public:
28 
30  typedef unsigned short value_type;
31 
33  enum { num_components = 4 };
34 
36  value_type _v[4];
37 
39  Vec4us() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
40 
41  Vec4us(value_type x, value_type y, value_type z, value_type w)
42  {
43  _v[0]=x;
44  _v[1]=y;
45  _v[2]=z;
46  _v[3]=w;
47  }
48 
49  inline bool operator == (const Vec4us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
50  inline bool operator != (const Vec4us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
51  inline bool operator < (const Vec4us& v) const
52  {
53  if (_v[0]<v._v[0]) return true;
54  else if (_v[0]>v._v[0]) return false;
55  else if (_v[1]<v._v[1]) return true;
56  else if (_v[1]>v._v[1]) return false;
57  else if (_v[2]<v._v[2]) return true;
58  else if (_v[2]>v._v[2]) return false;
59  else return (_v[3]<v._v[3]);
60  }
61 
62  inline value_type* ptr() { return _v; }
63  inline const value_type* ptr() const { return _v; }
64 
65  inline void set( value_type x, value_type y, value_type z, value_type w)
66  {
67  _v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
68  }
69 
70  inline value_type& operator [] (unsigned int i) { return _v[i]; }
71  inline value_type operator [] (unsigned int i) const { return _v[i]; }
72 
73  inline value_type& x() { return _v[0]; }
74  inline value_type& y() { return _v[1]; }
75  inline value_type& z() { return _v[2]; }
76  inline value_type& w() { return _v[3]; }
77 
78  inline value_type x() const { return _v[0]; }
79  inline value_type y() const { return _v[1]; }
80  inline value_type z() const { return _v[2]; }
81  inline value_type w() const { return _v[3]; }
82 
83  inline value_type& r() { return _v[0]; }
84  inline value_type& g() { return _v[1]; }
85  inline value_type& b() { return _v[2]; }
86  inline value_type& a() { return _v[3]; }
87 
88  inline value_type r() const { return _v[0]; }
89  inline value_type g() const { return _v[1]; }
90  inline value_type b() const { return _v[2]; }
91  inline value_type a() const { return _v[3]; }
92 
94  inline Vec4us operator * (value_type rhs) const
95  {
96  return Vec4us(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
97  }
98 
100  inline Vec4us& operator *= (value_type rhs)
101  {
102  _v[0]*=rhs;
103  _v[1]*=rhs;
104  _v[2]*=rhs;
105  _v[3]*=rhs;
106  return *this;
107  }
108 
110  inline Vec4us operator / (value_type rhs) const
111  {
112  return Vec4us(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
113  }
114 
116  inline Vec4us& operator /= (value_type rhs)
117  {
118  _v[0]/=rhs;
119  _v[1]/=rhs;
120  _v[2]/=rhs;
121  _v[3]/=rhs;
122  return *this;
123  }
124 
125 
127  inline Vec4us operator * (const Vec4us& rhs) const
128  {
129  return Vec4us(_v[0]*rhs._v[0], _v[1]*rhs._v[1],
130  _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
131  }
132 
134  inline Vec4us operator + (const Vec4us& rhs) const
135  {
136  return Vec4us(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
137  _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
138  }
139 
143  inline Vec4us& operator += (const Vec4us& rhs)
144  {
145  _v[0] += rhs._v[0];
146  _v[1] += rhs._v[1];
147  _v[2] += rhs._v[2];
148  _v[3] += rhs._v[3];
149  return *this;
150  }
151 
153  inline Vec4us operator - (const Vec4us& rhs) const
154  {
155  return Vec4us(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
156  _v[2]-rhs._v[2], _v[3]-rhs._v[3] );
157  }
158 
160  inline Vec4us& operator -= (const Vec4us& rhs)
161  {
162  _v[0]-=rhs._v[0];
163  _v[1]-=rhs._v[1];
164  _v[2]-=rhs._v[2];
165  _v[3]-=rhs._v[3];
166  return *this;
167  }
168 
169 }; // end of class Vec4us
170 
172 inline Vec4us componentMultiply(const Vec4us& lhs, const Vec4us& rhs)
173 {
174  return Vec4us(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
175 }
176 
178 inline Vec4us componentDivide(const Vec4us& lhs, const Vec4us& rhs)
179 {
180  return Vec4us(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
181 }
182 
183 } // end of namespace osg
184 
185 #endif
186 
bool operator!=(const Vec4us &v) const
Definition: Vec4us.h:50
value_type b() const
Definition: Vec4us.h:90
value_type * ptr()
Definition: Vec4us.h:62
unsigned short value_type
Definition: Vec4us.h:30
value_type a() const
Definition: Vec4us.h:91
Vec4us & operator/=(value_type rhs)
Definition: Vec4us.h:116
bool operator<(const Vec4us &v) const
Definition: Vec4us.h:51
value_type & r()
Definition: Vec4us.h:83
Vec4us operator/(value_type rhs) const
Definition: Vec4us.h:110
Vec4us()
Definition: Vec4us.h:39
Vec4us(value_type x, value_type y, value_type z, value_type w)
Definition: Vec4us.h:41
value_type & w()
Definition: Vec4us.h:76
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:187
value_type r() const
Definition: Vec4us.h:88
value_type & b()
Definition: Vec4us.h:85
bool operator==(const Vec4us &v) const
Definition: Vec4us.h:49
Vec4us operator*(value_type rhs) const
Definition: Vec4us.h:94
Vec4us operator+(const Vec4us &rhs) const
Definition: Vec4us.h:134
value_type z() const
Definition: Vec4us.h:80
value_type g() const
Definition: Vec4us.h:89
void set(value_type x, value_type y, value_type z, value_type w)
Definition: Vec4us.h:65
Vec4us & operator-=(const Vec4us &rhs)
Definition: Vec4us.h:160
value_type w() const
Definition: Vec4us.h:81
value_type x() const
Definition: Vec4us.h:78
const value_type * ptr() const
Definition: Vec4us.h:63
value_type _v[4]
Definition: Vec4us.h:36
value_type & g()
Definition: Vec4us.h:84
Definition: AlphaFunc.h:19
Vec4us & operator*=(value_type rhs)
Definition: Vec4us.h:100
value_type & x()
Definition: Vec4us.h:73
value_type & y()
Definition: Vec4us.h:74
value_type y() const
Definition: Vec4us.h:79
value_type & a()
Definition: Vec4us.h:86
value_type & operator[](unsigned int i)
Definition: Vec4us.h:70
Vec4us operator-(const Vec4us &rhs) const
Definition: Vec4us.h:153
Vec4us & operator+=(const Vec4us &rhs)
Definition: Vec4us.h:143
value_type & z()
Definition: Vec4us.h:75
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:181