openscenegraph
Vec4i
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_VEC4I
15#define OSG_VEC4I 1
16
17namespace osg {
18
19/** General purpose integer quad
20**/
21class Vec4i
22{
23 public:
24
25 /** Type of Vec class.*/
26 typedef int value_type;
27
28 /** Number of vector components. */
29 enum { num_components = 4 };
30
31 /** Vec member variable. */
32 value_type _v[4];
33
34 Vec4i() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
35
36 Vec4i(value_type x, value_type y, value_type z, value_type w)
37 {
38 _v[0]=x;
39 _v[1]=y;
40 _v[2]=z;
41 _v[3]=w;
42 }
43
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
47 {
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]);
55 }
56
57 inline value_type* ptr() { return _v; }
58 inline const value_type* ptr() const { return _v; }
59
60 inline void set( value_type x, value_type y, value_type z, value_type w)
61 {
62 _v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
63 }
64
65 inline value_type& operator [] (unsigned int i) { return _v[i]; }
66 inline value_type operator [] (unsigned int i) const { return _v[i]; }
67
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]; }
72
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]; }
77
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]; }
82
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]; }
87
88 inline Vec4i operator * (value_type rhs) const
89 {
90 return Vec4i(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
91 }
92
93 inline Vec4i operator / (value_type rhs) const
94 {
95 return Vec4i(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
96 }
97
98 inline Vec4i operator + (value_type rhs) const
99 {
100 return Vec4i(_v[0]+rhs, _v[1]+rhs, _v[2]+rhs, _v[3]+rhs);
101 }
102
103 inline Vec4i operator - (value_type rhs) const
104 {
105 return Vec4i(_v[0]-rhs, _v[1]-rhs, _v[2]-rhs, _v[3]-rhs);
106 }
107
108 inline Vec4i operator + (const Vec4i& rhs) const
109 {
110 return Vec4i(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
111 }
112
113 inline Vec4i operator - (const Vec4i& rhs) const
114 {
115 return Vec4i(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2], _v[3]-rhs._v[3]);
116 }
117
118 inline Vec4i operator * (const Vec4i& rhs) const
119 {
120 return Vec4i(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
121 }
122};
123
124}
125
126#endif