1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
19/** General purpose integer triple
25 /** Type of Vec class.*/
26 typedef int value_type;
28 /** Number of vector components. */
29 enum { num_components = 3 };
31 /** Vec member variable. */
34 Vec3i() { _v[0]=0; _v[1]=0; _v[2]=0; }
36 Vec3i(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
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
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]);
49 inline value_type* ptr() { return _v; }
50 inline const value_type* ptr() const { return _v; }
52 inline void set(value_type r, value_type g, value_type b)
54 _v[0]=r; _v[1]=g; _v[2]=b;
57 inline void set( const Vec3i& rhs)
59 _v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
62 inline value_type& operator [] (unsigned int i) { return _v[i]; }
63 inline value_type operator [] (unsigned int i) const { return _v[i]; }
65 inline value_type& x() { return _v[0]; }
66 inline value_type& y() { return _v[1]; }
67 inline value_type& z() { return _v[2]; }
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]; }
73 inline value_type& r() { return _v[0]; }
74 inline value_type& g() { return _v[1]; }
75 inline value_type& b() { return _v[2]; }
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]; }
81 /** Multiply by scalar. */
82 inline Vec3i operator * (value_type rhs) const
84 return Vec3i(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
87 inline Vec3i operator / (value_type rhs) const
89 return Vec3i(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
92 inline Vec3i operator + (value_type rhs) const
94 return Vec3i(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs);
97 inline Vec3i operator - (value_type rhs) const
99 return Vec3i(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs);
102 inline Vec3i operator + (const Vec3i& rhs) const
104 return Vec3i(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
107 inline Vec3i operator - (const Vec3i& rhs) const
109 return Vec3i(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
112 inline Vec3i operator * (const Vec3i& rhs) const
114 return Vec3i(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);