OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec3us.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_VEC3US
15 #define OSG_VEC3US 1
16 
17 namespace osg {
18 
19 class Vec3us
20 {
21  public:
22 
24  typedef unsigned short value_type;
25 
27  enum { num_components = 3 };
28 
29  value_type _v[3];
30 
32  Vec3us() { _v[0]=0; _v[1]=0; _v[2]=0; }
33 
34  Vec3us(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
35 
36  inline bool operator == (const Vec3us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
37  inline bool operator != (const Vec3us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
38  inline bool operator < (const Vec3us& v) const
39  {
40  if (_v[0]<v._v[0]) return true;
41  else if (_v[0]>v._v[0]) return false;
42  else if (_v[1]<v._v[1]) return true;
43  else if (_v[1]>v._v[1]) return false;
44  else return (_v[2]<v._v[2]);
45  }
46 
47  inline value_type* ptr() { return _v; }
48  inline const value_type* ptr() const { return _v; }
49 
50  inline void set(value_type r, value_type g, value_type b)
51  {
52  _v[0]=r; _v[1]=g; _v[2]=b;
53  }
54 
55  inline void set( const Vec3us& rhs)
56  {
57  _v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
58  }
59 
60  inline value_type& operator [] (unsigned int i) { return _v[i]; }
61  inline value_type operator [] (unsigned int i) const { return _v[i]; }
62 
63  inline value_type& x() { return _v[0]; }
64  inline value_type& y() { return _v[1]; }
65  inline value_type& z() { return _v[2]; }
66 
67  inline value_type x() const { return _v[0]; }
68  inline value_type y() const { return _v[1]; }
69  inline value_type z() const { return _v[2]; }
70 
71  inline value_type& r() { return _v[0]; }
72  inline value_type& g() { return _v[1]; }
73  inline value_type& b() { return _v[2]; }
74 
75  inline value_type r() const { return _v[0]; }
76  inline value_type g() const { return _v[1]; }
77  inline value_type b() const { return _v[2]; }
78 
80  inline Vec3us operator * (value_type rhs) const
81  {
82  return Vec3us(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
83  }
84 
86  inline Vec3us& operator *= (value_type rhs)
87  {
88  _v[0]*=rhs;
89  _v[1]*=rhs;
90  _v[2]*=rhs;
91  return *this;
92  }
93 
95  inline Vec3us operator / (value_type rhs) const
96  {
97  return Vec3us(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
98  }
99 
101  inline Vec3us& operator /= (value_type rhs)
102  {
103  _v[0]/=rhs;
104  _v[1]/=rhs;
105  _v[2]/=rhs;
106  return *this;
107  }
108 
110  inline Vec3us operator * (const Vec3us& rhs) const
111  {
112  return Vec3us(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
113  }
114 
116  inline Vec3us operator + (const Vec3us& rhs) const
117  {
118  return Vec3us(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
119  }
120 
124  inline Vec3us& operator += (const Vec3us& rhs)
125  {
126  _v[0] += rhs._v[0];
127  _v[1] += rhs._v[1];
128  _v[2] += rhs._v[2];
129  return *this;
130  }
131 
133  inline Vec3us operator - (const Vec3us& rhs) const
134  {
135  return Vec3us(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
136  }
137 
139  inline Vec3us& operator -= (const Vec3us& rhs)
140  {
141  _v[0]-=rhs._v[0];
142  _v[1]-=rhs._v[1];
143  _v[2]-=rhs._v[2];
144  return *this;
145  }
146 
147 }; // end of class Vec3us
148 
150 inline Vec3us componentMultiply(const Vec3us& lhs, const Vec3us& rhs)
151 {
152  return Vec3us(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
153 }
154 
156 inline Vec3us componentDivide(const Vec3us& lhs, const Vec3us& rhs)
157 {
158  return Vec3us(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
159 }
160 
161 } // end of namespace osg
162 
163 #endif
164 
value_type & x()
Definition: Vec3us.h:63
bool operator==(const Vec3us &v) const
Definition: Vec3us.h:36
value_type & operator[](unsigned int i)
Definition: Vec3us.h:60
Vec3us operator/(value_type rhs) const
Definition: Vec3us.h:95
value_type & g()
Definition: Vec3us.h:72
value_type & y()
Definition: Vec3us.h:64
const value_type * ptr() const
Definition: Vec3us.h:48
void set(const Vec3us &rhs)
Definition: Vec3us.h:55
value_type b() const
Definition: Vec3us.h:77
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:187
Vec3us operator*(value_type rhs) const
Definition: Vec3us.h:80
void set(value_type r, value_type g, value_type b)
Definition: Vec3us.h:50
Vec3us & operator/=(value_type rhs)
Definition: Vec3us.h:101
Vec3us operator+(const Vec3us &rhs) const
Definition: Vec3us.h:116
value_type * ptr()
Definition: Vec3us.h:47
Vec3us & operator-=(const Vec3us &rhs)
Definition: Vec3us.h:139
value_type & b()
Definition: Vec3us.h:73
value_type x() const
Definition: Vec3us.h:67
Vec3us(value_type r, value_type g, value_type b)
Definition: Vec3us.h:34
value_type & z()
Definition: Vec3us.h:65
value_type r() const
Definition: Vec3us.h:75
value_type _v[3]
Definition: Vec3us.h:29
Vec3us & operator*=(value_type rhs)
Definition: Vec3us.h:86
value_type y() const
Definition: Vec3us.h:68
unsigned short value_type
Definition: Vec3us.h:24
bool operator<(const Vec3us &v) const
Definition: Vec3us.h:38
Vec3us()
Definition: Vec3us.h:32
Definition: AlphaFunc.h:19
Vec3us & operator+=(const Vec3us &rhs)
Definition: Vec3us.h:124
value_type & r()
Definition: Vec3us.h:71
bool operator!=(const Vec3us &v) const
Definition: Vec3us.h:37
value_type g() const
Definition: Vec3us.h:76
Vec3us operator-(const Vec3us &rhs) const
Definition: Vec3us.h:133
value_type z() const
Definition: Vec3us.h:69
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:181