OpenSceneGraph 3.6.5
Vec2b
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_VEC2B
15#define OSG_VEC2B 1
16
17namespace osg {
18
25class Vec2b
26{
27 public:
28
29 // Methods are defined here so that they are implicitly inlined
30
32 typedef signed char value_type;
33
35 enum { num_components = 2 };
36
39
41 Vec2b() { _v[0]=0; _v[1]=0; }
42
44 {
45 _v[0]=r; _v[1]=g;
46 }
47
48 inline bool operator == (const Vec2b& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
49
50 inline bool operator != (const Vec2b& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
51
52 inline bool operator < (const Vec2b& v) const
53 {
54 if (_v[0]<v._v[0]) return true;
55 else if (_v[0]>v._v[0]) return false;
56 else return (_v[1]<v._v[1]);
57 }
58
59 inline value_type* ptr() { return _v; }
60 inline const value_type* ptr() const { return _v; }
61
62 inline void set( value_type x, value_type y)
63 {
64 _v[0]=x; _v[1]=y;
65 }
66
67 inline void set( const Vec2b& rhs)
68 {
69 _v[0]=rhs._v[0]; _v[1]=rhs._v[1];
70 }
71
72 inline value_type& operator [] (int i) { return _v[i]; }
73 inline value_type operator [] (int i) const { return _v[i]; }
74
75 inline value_type& x() { return _v[0]; }
76 inline value_type& y() { return _v[1]; }
77
78 inline value_type x() const { return _v[0]; }
79 inline value_type y() const { return _v[1]; }
80
81 inline value_type& r() { return _v[0]; }
82 inline value_type& g() { return _v[1]; }
83
84 inline value_type r() const { return _v[0]; }
85 inline value_type g() const { return _v[1]; }
86
88 inline Vec2b operator * (float rhs) const
89 {
90 Vec2b col(*this);
91 col *= rhs;
92 return col;
93 }
94
96 inline Vec2b& operator *= (float rhs)
97 {
98 _v[0]=(value_type)((float)_v[0]*rhs);
99 _v[1]=(value_type)((float)_v[1]*rhs);
100 return *this;
101 }
102
104 inline Vec2b operator / (float rhs) const
105 {
106 Vec2b col(*this);
107 col /= rhs;
108 return col;
109 }
110
112 inline Vec2b& operator /= (float rhs)
113 {
114 float div = 1.0f/rhs;
115 *this *= div;
116 return *this;
117 }
118
120 inline Vec2b operator + (const Vec2b& rhs) const
121 {
122 return Vec2b(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
123 }
124
128 inline Vec2b& operator += (const Vec2b& rhs)
129 {
130 _v[0] += rhs._v[0];
131 _v[1] += rhs._v[1];
132 return *this;
133 }
134
136 inline Vec2b operator - (const Vec2b& rhs) const
137 {
138 return Vec2b(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
139 }
140
142 inline Vec2b& operator -= (const Vec2b& rhs)
143 {
144 _v[0]-=rhs._v[0];
145 _v[1]-=rhs._v[1];
146 return *this;
147 }
148
149}; // end of class Vec2b
150
151
152
153} // end of namespace osg
154
155#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
value_type & g()
Definition Vec2b:82
Vec2b operator+(const Vec2b &rhs) const
Binary vector add.
Definition Vec2b:120
void set(const Vec2b &rhs)
Definition Vec2b:67
value_type & r()
Definition Vec2b:81
@ num_components
Definition Vec2b:35
value_type & x()
Definition Vec2b:75
value_type r() const
Definition Vec2b:84
value_type x() const
Definition Vec2b:78
Vec2b & operator+=(const Vec2b &rhs)
Unary vector add.
Definition Vec2b:128
Vec2b & operator/=(float rhs)
Unary divide by scalar.
Definition Vec2b:112
bool operator!=(const Vec2b &v) const
Definition Vec2b:50
value_type g() const
Definition Vec2b:85
Vec2b operator*(float rhs) const
Multiply by scalar.
Definition Vec2b:88
value_type & operator[](int i)
Definition Vec2b:72
signed char value_type
Data type of vector components.
Definition Vec2b:32
const value_type * ptr() const
Definition Vec2b:60
value_type & y()
Definition Vec2b:76
Vec2b operator-(const Vec2b &rhs) const
Binary vector subtract.
Definition Vec2b:136
Vec2b & operator*=(float rhs)
Unary multiply by scalar.
Definition Vec2b:96
Vec2b & operator-=(const Vec2b &rhs)
Unary vector subtract.
Definition Vec2b:142
bool operator==(const Vec2b &v) const
Definition Vec2b:48
value_type y() const
Definition Vec2b:79
value_type _v[2]
Vec member variable.
Definition Vec2b:38
void set(value_type x, value_type y)
Definition Vec2b:62
Vec2b()
Constructor that sets all components of the vector to zero.
Definition Vec2b:41
Vec2b(value_type r, value_type g)
Definition Vec2b:43
Vec2b operator/(float rhs) const
Divide by scalar.
Definition Vec2b:104
value_type * ptr()
Definition Vec2b:59
bool operator<(const Vec2b &v) const
Definition Vec2b:52

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.