openscenegraph
Vec4us
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_VEC4US
15#define OSG_VEC4US 1
16
17namespace osg {
18
25class Vec4us
26{
27 public:
28
30 typedef unsigned short value_type;
31
33 enum { num_components = 4 };
34
37
39 Vec4us() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
40
42 {
43 _v[0]=x;
44 _v[1]=y;
45 _v[2]=z;
46 _v[3]=w;
47 }
48
49 inline bool operator == (const Vec4us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
50 inline bool operator != (const Vec4us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
51 inline bool operator < (const Vec4us& v) const
52 {
53 if (_v[0]<v._v[0]) return true;
54 else if (_v[0]>v._v[0]) return false;
55 else if (_v[1]<v._v[1]) return true;
56 else if (_v[1]>v._v[1]) return false;
57 else if (_v[2]<v._v[2]) return true;
58 else if (_v[2]>v._v[2]) return false;
59 else return (_v[3]<v._v[3]);
60 }
61
62 inline value_type* ptr() { return _v; }
63 inline const value_type* ptr() const { return _v; }
64
66 {
67 _v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
68 }
69
70 inline value_type& operator [] (unsigned int i) { return _v[i]; }
71 inline value_type operator [] (unsigned int i) const { return _v[i]; }
72
73 inline value_type& x() { return _v[0]; }
74 inline value_type& y() { return _v[1]; }
75 inline value_type& z() { return _v[2]; }
76 inline value_type& w() { return _v[3]; }
77
78 inline value_type x() const { return _v[0]; }
79 inline value_type y() const { return _v[1]; }
80 inline value_type z() const { return _v[2]; }
81 inline value_type w() const { return _v[3]; }
82
83 inline value_type& r() { return _v[0]; }
84 inline value_type& g() { return _v[1]; }
85 inline value_type& b() { return _v[2]; }
86 inline value_type& a() { return _v[3]; }
87
88 inline value_type r() const { return _v[0]; }
89 inline value_type g() const { return _v[1]; }
90 inline value_type b() const { return _v[2]; }
91 inline value_type a() const { return _v[3]; }
92
95 {
96 return Vec4us(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
97 }
98
101 {
102 _v[0]*=rhs;
103 _v[1]*=rhs;
104 _v[2]*=rhs;
105 _v[3]*=rhs;
106 return *this;
107 }
108
111 {
112 return Vec4us(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
113 }
114
117 {
118 _v[0]/=rhs;
119 _v[1]/=rhs;
120 _v[2]/=rhs;
121 _v[3]/=rhs;
122 return *this;
123 }
124
125
127 inline Vec4us operator * (const Vec4us& rhs) const
128 {
129 return Vec4us(_v[0]*rhs._v[0], _v[1]*rhs._v[1],
130 _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
131 }
132
134 inline Vec4us operator + (const Vec4us& rhs) const
135 {
136 return Vec4us(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
137 _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
138 }
139
144 {
145 _v[0] += rhs._v[0];
146 _v[1] += rhs._v[1];
147 _v[2] += rhs._v[2];
148 _v[3] += rhs._v[3];
149 return *this;
150 }
151
153 inline Vec4us operator - (const Vec4us& rhs) const
154 {
155 return Vec4us(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
156 _v[2]-rhs._v[2], _v[3]-rhs._v[3] );
157 }
158
161 {
162 _v[0]-=rhs._v[0];
163 _v[1]-=rhs._v[1];
164 _v[2]-=rhs._v[2];
165 _v[3]-=rhs._v[3];
166 return *this;
167 }
168
169}; // end of class Vec4us
170
172inline Vec4us componentMultiply(const Vec4us& lhs, const Vec4us& rhs)
173{
174 return Vec4us(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
175}
176
178inline Vec4us componentDivide(const Vec4us& lhs, const Vec4us& rhs)
179{
180 return Vec4us(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
181}
182
183} // end of namespace osg
184
185#endif
186
Definition Vec4us:26
unsigned short value_type
Definition Vec4us:30
value_type y() const
Definition Vec4us:79
const value_type * ptr() const
Definition Vec4us:63
Vec4us operator/(value_type rhs) const
Definition Vec4us:110
value_type & b()
Definition Vec4us:85
value_type & operator[](unsigned int i)
Definition Vec4us:70
Vec4us operator-(const Vec4us &rhs) const
Definition Vec4us:153
value_type * ptr()
Definition Vec4us:62
void set(value_type x, value_type y, value_type z, value_type w)
Definition Vec4us:65
bool operator==(const Vec4us &v) const
Definition Vec4us:49
value_type & w()
Definition Vec4us:76
@ num_components
Definition Vec4us:33
value_type z() const
Definition Vec4us:80
value_type & x()
Definition Vec4us:73
value_type w() const
Definition Vec4us:81
value_type & a()
Definition Vec4us:86
value_type & y()
Definition Vec4us:74
Vec4us()
Definition Vec4us:39
value_type a() const
Definition Vec4us:91
value_type b() const
Definition Vec4us:90
value_type x() const
Definition Vec4us:78
Vec4us(value_type x, value_type y, value_type z, value_type w)
Definition Vec4us:41
Vec4us operator*(value_type rhs) const
Definition Vec4us:94
bool operator<(const Vec4us &v) const
Definition Vec4us:51
Vec4us & operator-=(const Vec4us &rhs)
Definition Vec4us:160
Vec4us & operator+=(const Vec4us &rhs)
Definition Vec4us:143
Vec4us & operator*=(value_type rhs)
Definition Vec4us:100
value_type g() const
Definition Vec4us:89
value_type r() const
Definition Vec4us:88
Vec4us operator+(const Vec4us &rhs) const
Definition Vec4us:134
value_type & r()
Definition Vec4us:83
bool operator!=(const Vec4us &v) const
Definition Vec4us:50
value_type & g()
Definition Vec4us:84
value_type _v[4]
Definition Vec4us:36
value_type & z()
Definition Vec4us:75
Vec4us & operator/=(value_type rhs)
Definition Vec4us:116
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:187
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:181