OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec4s.h
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_VEC4S
15 #define OSG_VEC4S 1
16 
17 namespace osg {
18 
25 class Vec4s
26 {
27  public:
28 
30  typedef short value_type;
31 
33  enum { num_components = 4 };
34 
36  value_type _v[4];
37 
39  Vec4s() { _v[0]=0; _v[1]=0; _v[2]=0; _v[3]=0; }
40 
41  Vec4s(value_type x, value_type y, value_type z, value_type w)
42  {
43  _v[0]=x;
44  _v[1]=y;
45  _v[2]=z;
46  _v[3]=w;
47  }
48 
49  inline bool operator == (const Vec4s& 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 Vec4s& 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 Vec4s& 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 
65  inline void set( value_type x, value_type y, value_type z, value_type w)
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 
94  inline Vec4s operator * (value_type rhs) const
95  {
96  return Vec4s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
97  }
98 
100  inline Vec4s& operator *= (value_type rhs)
101  {
102  _v[0]*=rhs;
103  _v[1]*=rhs;
104  _v[2]*=rhs;
105  _v[3]*=rhs;
106  return *this;
107  }
108 
110  inline Vec4s operator / (value_type rhs) const
111  {
112  return Vec4s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
113  }
114 
116  inline Vec4s& operator /= (value_type rhs)
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 Vec4s operator * (const Vec4s& rhs) const
128  {
129  return Vec4s(_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 Vec4s operator + (const Vec4s& rhs) const
135  {
136  return Vec4s(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
137  _v[2]+rhs._v[2], _v[3]+rhs._v[3]);
138  }
139 
143  inline Vec4s& operator += (const Vec4s& rhs)
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 Vec4s operator - (const Vec4s& rhs) const
154  {
155  return Vec4s(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
156  _v[2]-rhs._v[2], _v[3]-rhs._v[3] );
157  }
158 
160  inline Vec4s& operator -= (const Vec4s& rhs)
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 
170  inline Vec4s operator - () const
171  {
172  return Vec4s (-_v[0], -_v[1], -_v[2], -_v[3]);
173  }
174 
175 }; // end of class Vec4s
176 
177 
179 inline Vec4s componentMultiply(const Vec4s& lhs, const Vec4s& rhs)
180 {
181  return Vec4s(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
182 }
183 
185 inline Vec4s componentDivide(const Vec4s& lhs, const Vec4s& rhs)
186 {
187  return Vec4s(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
188 }
189 
190 } // end of namespace osg
191 
192 #endif
193 
value_type & z()
Definition: Vec4s.h:75
value_type y() const
Definition: Vec4s.h:79
Vec4s & operator/=(value_type rhs)
Definition: Vec4s.h:116
value_type & b()
Definition: Vec4s.h:85
Vec4s & operator*=(value_type rhs)
Definition: Vec4s.h:100
Vec4s operator-() const
Definition: Vec4s.h:170
Vec4s & operator-=(const Vec4s &rhs)
Definition: Vec4s.h:160
value_type b() const
Definition: Vec4s.h:90
short value_type
Definition: Vec4s.h:30
value_type & operator[](unsigned int i)
Definition: Vec4s.h:70
Vec4s(value_type x, value_type y, value_type z, value_type w)
Definition: Vec4s.h:41
bool operator<(const Vec4s &v) const
Definition: Vec4s.h:51
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:187
Vec4s()
Definition: Vec4s.h:39
value_type a() const
Definition: Vec4s.h:91
value_type g() const
Definition: Vec4s.h:89
value_type & r()
Definition: Vec4s.h:83
value_type r() const
Definition: Vec4s.h:88
value_type w() const
Definition: Vec4s.h:81
value_type z() const
Definition: Vec4s.h:80
value_type * ptr()
Definition: Vec4s.h:62
const value_type * ptr() const
Definition: Vec4s.h:63
Vec4s & operator+=(const Vec4s &rhs)
Definition: Vec4s.h:143
void set(value_type x, value_type y, value_type z, value_type w)
Definition: Vec4s.h:65
bool operator==(const Vec4s &v) const
Definition: Vec4s.h:49
bool operator!=(const Vec4s &v) const
Definition: Vec4s.h:50
value_type & w()
Definition: Vec4s.h:76
value_type x() const
Definition: Vec4s.h:78
value_type & a()
Definition: Vec4s.h:86
Definition: AlphaFunc.h:19
value_type & x()
Definition: Vec4s.h:73
value_type & y()
Definition: Vec4s.h:74
Vec4s operator/(value_type rhs) const
Definition: Vec4s.h:110
value_type & g()
Definition: Vec4s.h:84
value_type _v[4]
Definition: Vec4s.h:36
Vec4s operator*(value_type rhs) const
Definition: Vec4s.h:94
Vec4s operator+(const Vec4s &rhs) const
Definition: Vec4s.h:134
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition: Vec2d.h:181