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 quad
25 /** Type of Vec class.*/
26 typedef int value_type;
28 /** Number of vector components. */
29 enum { num_components = 4 };
31 /** Vec member variable. */
34 Vec4i() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
36 Vec4i(value_type x, value_type y, value_type z, value_type w)
44 inline bool operator == (const Vec4i& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
45 inline bool operator != (const Vec4i& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
46 inline bool operator < (const Vec4i& v) const
48 if (_v[0]<v._v[0]) return true;
49 else if (_v[0]>v._v[0]) return false;
50 else if (_v[1]<v._v[1]) return true;
51 else if (_v[1]>v._v[1]) return false;
52 else if (_v[2]<v._v[2]) return true;
53 else if (_v[2]>v._v[2]) return false;
54 else return (_v[3]<v._v[3]);
57 inline value_type* ptr() { return _v; }
58 inline const value_type* ptr() const { return _v; }
60 inline void set( value_type x, value_type y, value_type z, value_type w)
62 _v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
65 inline value_type& operator [] (unsigned int i) { return _v[i]; }
66 inline value_type operator [] (unsigned int i) const { return _v[i]; }
68 inline value_type& x() { return _v[0]; }
69 inline value_type& y() { return _v[1]; }
70 inline value_type& z() { return _v[2]; }
71 inline value_type& w() { return _v[3]; }
73 inline value_type x() const { return _v[0]; }
74 inline value_type y() const { return _v[1]; }
75 inline value_type z() const { return _v[2]; }
76 inline value_type w() const { return _v[3]; }
78 inline value_type& r() { return _v[0]; }
79 inline value_type& g() { return _v[1]; }
80 inline value_type& b() { return _v[2]; }
81 inline value_type& a() { return _v[3]; }
83 inline value_type r() const { return _v[0]; }
84 inline value_type g() const { return _v[1]; }
85 inline value_type b() const { return _v[2]; }
86 inline value_type a() const { return _v[3]; }
88 inline Vec4i operator * (value_type rhs) const
90 return Vec4i(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
93 inline Vec4i operator / (value_type rhs) const
95 return Vec4i(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
98 inline Vec4i operator + (value_type rhs) const
100 return Vec4i(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
103 inline Vec4i operator - (value_type rhs) const
105 return Vec4i(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
108 inline Vec4i operator + (const Vec4i& rhs) const
110 return Vec4i(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
113 inline Vec4i operator - (const Vec4i& rhs) const
115 return Vec4i(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
118 inline Vec4i operator * (const Vec4i& rhs) const
120 return Vec4i(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);