openscenegraph
Vec3i
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
17namespace osg {
18
19/** General purpose integer triple
20**/
21class Vec3i
22{
23 public:
24
25 /** Type of Vec class.*/
26 typedef int value_type;
27
28 /** Number of vector components. */
29 enum { num_components = 3 };
30
31 /** Vec member variable. */
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
81 /** Multiply by scalar. */
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