OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec3i.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_VEC3I
15 #define OSG_VEC3I 1
16 
17 namespace osg {
18 
21 class Vec3i
22 {
23  public:
24 
26  typedef int value_type;
27 
29  enum { num_components = 3 };
30 
32  value_type _v[3];
33 
34  Vec3i() { _v[0]=0; _v[1]=0; _v[2]=0; }
35 
36  Vec3i(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
37 
38  inline bool operator == (const Vec3i& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
39  inline bool operator != (const Vec3i& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
40  inline bool operator < (const Vec3i& v) const
41  {
42  if (_v[0]<v._v[0]) return true;
43  else if (_v[0]>v._v[0]) return false;
44  else if (_v[1]<v._v[1]) return true;
45  else if (_v[1]>v._v[1]) return false;
46  else return (_v[2]<v._v[2]);
47  }
48 
49  inline value_type* ptr() { return _v; }
50  inline const value_type* ptr() const { return _v; }
51 
52  inline void set(value_type r, value_type g, value_type b)
53  {
54  _v[0]=r; _v[1]=g; _v[2]=b;
55  }
56 
57  inline void set( const Vec3i& rhs)
58  {
59  _v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
60  }
61 
62  inline value_type& operator [] (unsigned int i) { return _v[i]; }
63  inline value_type operator [] (unsigned int i) const { return _v[i]; }
64 
65  inline value_type& x() { return _v[0]; }
66  inline value_type& y() { return _v[1]; }
67  inline value_type& z() { return _v[2]; }
68 
69  inline value_type x() const { return _v[0]; }
70  inline value_type y() const { return _v[1]; }
71  inline value_type z() const { return _v[2]; }
72 
73  inline value_type& r() { return _v[0]; }
74  inline value_type& g() { return _v[1]; }
75  inline value_type& b() { return _v[2]; }
76 
77  inline value_type r() const { return _v[0]; }
78  inline value_type g() const { return _v[1]; }
79  inline value_type b() const { return _v[2]; }
80 
82  inline Vec3i operator * (value_type rhs) const
83  {
84  return Vec3i(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
85  }
86 
87  inline Vec3i operator / (value_type rhs) const
88  {
89  return Vec3i(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
90  }
91 
92  inline Vec3i operator + (value_type rhs) const
93  {
94  return Vec3i(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
95  }
96 
97  inline Vec3i operator - (value_type rhs) const
98  {
99  return Vec3i(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
100  }
101 
102  inline Vec3i operator + (const Vec3i& rhs) const
103  {
104  return Vec3i(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
105  }
106 
107  inline Vec3i operator - (const Vec3i& rhs) const
108  {
109  return Vec3i(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
110  }
111 
112  inline Vec3i operator * (const Vec3i& rhs) const
113  {
114  return Vec3i(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
115  }
116 };
117 
118 }
119 
120 #endif
value_type & g()
Definition: Vec3i.h:74
bool operator<(const Vec3i &v) const
Definition: Vec3i.h:40
value_type & b()
Definition: Vec3i.h:75
value_type b() const
Definition: Vec3i.h:79
value_type r() const
Definition: Vec3i.h:77
value_type & operator[](unsigned int i)
Definition: Vec3i.h:62
value_type y() const
Definition: Vec3i.h:70
value_type g() const
Definition: Vec3i.h:78
value_type _v[3]
Definition: Vec3i.h:32
void set(const Vec3i &rhs)
Definition: Vec3i.h:57
value_type & r()
Definition: Vec3i.h:73
value_type x() const
Definition: Vec3i.h:69
value_type & x()
Definition: Vec3i.h:65
value_type * ptr()
Definition: Vec3i.h:49
Vec3i operator*(value_type rhs) const
Definition: Vec3i.h:82
Vec3i operator-(value_type rhs) const
Definition: Vec3i.h:97
value_type & y()
Definition: Vec3i.h:66
Vec3i operator/(value_type rhs) const
Definition: Vec3i.h:87
bool operator==(const Vec3i &v) const
Definition: Vec3i.h:38
bool operator!=(const Vec3i &v) const
Definition: Vec3i.h:39
value_type z() const
Definition: Vec3i.h:71
const value_type * ptr() const
Definition: Vec3i.h:50
value_type & z()
Definition: Vec3i.h:67
Vec3i(value_type r, value_type g, value_type b)
Definition: Vec3i.h:36
Vec3i operator+(value_type rhs) const
Definition: Vec3i.h:92
Definition: AlphaFunc.h:19
Vec3i()
Definition: Vec3i.h:34
int value_type
Definition: Vec3i.h:26
void set(value_type r, value_type g, value_type b)
Definition: Vec3i.h:52