OpenSceneGraph 3.6.5
Vec2us
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_VEC2US
15#define OSG_VEC2US 1
16
17namespace osg {
18
19class Vec2us
20{
21 public:
22
24 typedef unsigned short value_type;
25
27 enum { num_components = 2 };
28
30
32 Vec2us() { _v[0]=0; _v[1]=0; }
33
34 Vec2us(value_type x, value_type y) { _v[0] = x; _v[1] = y; }
35
36 inline bool operator == (const Vec2us& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
37 inline bool operator != (const Vec2us& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
38 inline bool operator < (const Vec2us& v) const
39 {
40 if (_v[0]<v._v[0]) return true;
41 else if (_v[0]>v._v[0]) return false;
42 else return (_v[1]<v._v[1]);
43 }
44
45 inline value_type* ptr() { return _v; }
46 inline const value_type* ptr() const { return _v; }
47
48 inline void set( value_type x, value_type y)
49 {
50 _v[0]=x; _v[1]=y;
51 }
52
53 inline void set( const Vec2us& rhs)
54 {
55 _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
56 }
57
58 inline value_type& operator [] (int i) { return _v[i]; }
59 inline value_type operator [] (int i) const { return _v[i]; }
60
61 inline value_type& x() { return _v[0]; }
62 inline value_type& y() { return _v[1]; }
63
64 inline value_type x() const { return _v[0]; }
65 inline value_type y() const { return _v[1]; }
66
67 inline value_type& r() { return _v[0]; }
68 inline value_type& g() { return _v[1]; }
69
70 inline value_type r() const { return _v[0]; }
71 inline value_type g() const { return _v[1]; }
72
73 inline Vec2us operator * (value_type rhs) const
74 {
75 return Vec2us(_v[0]*rhs, _v[1]*rhs);
76 }
77
79 {
80 _v[0]*=rhs;
81 _v[1]*=rhs;
82 return *this;
83 }
84
85 inline Vec2us operator / (value_type rhs) const
86 {
87 return Vec2us(_v[0]/rhs, _v[1]/rhs);
88 }
89
91 {
92 _v[0]/=rhs;
93 _v[1]/=rhs;
94 return *this;
95 }
96
97 inline Vec2us operator + (const Vec2us& rhs) const
98 {
99 return Vec2us(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
100 }
101
102 inline Vec2us& operator += (const Vec2us& rhs)
103 {
104 _v[0] += rhs._v[0];
105 _v[1] += rhs._v[1];
106 return *this;
107 }
108
109 inline Vec2us operator - (const Vec2us& rhs) const
110 {
111 return Vec2us(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
112 }
113
114 inline Vec2us& operator -= (const Vec2us& rhs)
115 {
116 _v[0]-=rhs._v[0];
117 _v[1]-=rhs._v[1];
118 return *this;
119 }
120
121}; // end of class Vec2us
122
124inline Vec2us componentMultiply(const Vec2us& lhs, const Vec2us& rhs)
125{
126 return Vec2us(lhs[0]*rhs[0], lhs[1]*rhs[1]);
127}
128
130inline Vec2us componentDivide(const Vec2us& lhs, const Vec2us& rhs)
131{
132 return Vec2us(lhs[0]/rhs[0], lhs[1]/rhs[1]);
133}
134
135} // end of namespace osg
136#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
divide rhs components by rhs vector components.
Definition Vec2d:187
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
multiply by vector components.
Definition Vec2d:181
Definition Vec2us:20
Vec2us & operator+=(const Vec2us &rhs)
Definition Vec2us:102
bool operator<(const Vec2us &v) const
Definition Vec2us:38
bool operator!=(const Vec2us &v) const
Definition Vec2us:37
value_type & operator[](int i)
Definition Vec2us:58
Vec2us operator-(const Vec2us &rhs) const
Definition Vec2us:109
Vec2us operator*(value_type rhs) const
Definition Vec2us:73
value_type x() const
Definition Vec2us:64
value_type _v[2]
Definition Vec2us:29
Vec2us & operator*=(value_type rhs)
Definition Vec2us:78
unsigned short value_type
Data type of vector components.
Definition Vec2us:24
const value_type * ptr() const
Definition Vec2us:46
value_type r() const
Definition Vec2us:70
Vec2us()
Constructor that sets all components of the vector to zero.
Definition Vec2us:32
value_type & g()
Definition Vec2us:68
value_type & y()
Definition Vec2us:62
Vec2us operator+(const Vec2us &rhs) const
Definition Vec2us:97
Vec2us & operator-=(const Vec2us &rhs)
Definition Vec2us:114
Vec2us & operator/=(value_type rhs)
Definition Vec2us:90
value_type * ptr()
Definition Vec2us:45
void set(const Vec2us &rhs)
Definition Vec2us:53
value_type y() const
Definition Vec2us:65
value_type & r()
Definition Vec2us:67
@ num_components
Definition Vec2us:27
Vec2us(value_type x, value_type y)
Definition Vec2us:34
void set(value_type x, value_type y)
Definition Vec2us:48
Vec2us operator/(value_type rhs) const
Definition Vec2us:85
bool operator==(const Vec2us &v) const
Definition Vec2us:36
value_type & x()
Definition Vec2us:61
value_type g() const
Definition Vec2us:71

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.