openscenegraph
Vec3s
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_VEC3S
15#define OSG_VEC3S 1
16
17namespace osg {
18
19class Vec3s
20{
21 public:
22
24 typedef short value_type;
25
27 enum { num_components = 3 };
28
30
32 Vec3s() { _v[0]=0; _v[1]=0; _v[2]=0; }
33
35
36 inline bool operator == (const Vec3s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
37 inline bool operator != (const Vec3s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
38 inline bool operator < (const Vec3s& v) const
39 {
40 if (_v[0]<v._v[0]) return true;
41 else if (_v[0]>v._v[0]) return false;
42 else if (_v[1]<v._v[1]) return true;
43 else if (_v[1]>v._v[1]) return false;
44 else return (_v[2]<v._v[2]);
45 }
46
47 inline value_type* ptr() { return _v; }
48 inline const value_type* ptr() const { return _v; }
49
51 {
52 _v[0]=r; _v[1]=g; _v[2]=b;
53 }
54
55 inline void set( const Vec3s& rhs)
56 {
57 _v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
58 }
59
60 inline value_type& operator [] (unsigned int i) { return _v[i]; }
61 inline value_type operator [] (unsigned int i) const { return _v[i]; }
62
63 inline value_type& x() { return _v[0]; }
64 inline value_type& y() { return _v[1]; }
65 inline value_type& z() { return _v[2]; }
66
67 inline value_type x() const { return _v[0]; }
68 inline value_type y() const { return _v[1]; }
69 inline value_type z() const { return _v[2]; }
70
71 inline value_type& r() { return _v[0]; }
72 inline value_type& g() { return _v[1]; }
73 inline value_type& b() { return _v[2]; }
74
75 inline value_type r() const { return _v[0]; }
76 inline value_type g() const { return _v[1]; }
77 inline value_type b() const { return _v[2]; }
78
81 {
82 return Vec3s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
83 }
84
87 {
88 _v[0]*=rhs;
89 _v[1]*=rhs;
90 _v[2]*=rhs;
91 return *this;
92 }
93
96 {
97 return Vec3s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
98 }
99
102 {
103 _v[0]/=rhs;
104 _v[1]/=rhs;
105 _v[2]/=rhs;
106 return *this;
107 }
108
110 inline Vec3s operator * (const Vec3s& rhs) const
111 {
112 return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
113 }
114
116 inline Vec3s operator + (const Vec3s& rhs) const
117 {
118 return Vec3s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
119 }
120
124 inline Vec3s& operator += (const Vec3s& rhs)
125 {
126 _v[0] += rhs._v[0];
127 _v[1] += rhs._v[1];
128 _v[2] += rhs._v[2];
129 return *this;
130 }
131
133 inline Vec3s operator - (const Vec3s& rhs) const
134 {
135 return Vec3s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
136 }
137
139 inline Vec3s& operator -= (const Vec3s& rhs)
140 {
141 _v[0]-=rhs._v[0];
142 _v[1]-=rhs._v[1];
143 _v[2]-=rhs._v[2];
144 return *this;
145 }
146
148 inline Vec3s operator - () const
149 {
150 return Vec3s (-_v[0], -_v[1], -_v[2]);
151 }
152
153}; // end of class Vec3s
154
155
157inline Vec3s componentMultiply(const Vec3s& lhs, const Vec3s& rhs)
158{
159 return Vec3s(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
160}
161
163inline Vec3s componentDivide(const Vec3s& lhs, const Vec3s& rhs)
164{
165 return Vec3s(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
166}
167
168} // end of namespace osg
169
170#endif
171
Definition Vec3s:20
Vec3s operator-() const
Definition Vec3s:148
Vec3s & operator+=(const Vec3s &rhs)
Definition Vec3s:124
Vec3s & operator/=(value_type rhs)
Definition Vec3s:101
bool operator==(const Vec3s &v) const
Definition Vec3s:36
Vec3s(value_type r, value_type g, value_type b)
Definition Vec3s:34
value_type * ptr()
Definition Vec3s:47
value_type & g()
Definition Vec3s:72
Vec3s operator*(value_type rhs) const
Definition Vec3s:80
short value_type
Definition Vec3s:24
const value_type * ptr() const
Definition Vec3s:48
value_type & y()
Definition Vec3s:64
Vec3s operator+(const Vec3s &rhs) const
Definition Vec3s:116
value_type z() const
Definition Vec3s:69
value_type & z()
Definition Vec3s:65
value_type g() const
Definition Vec3s:76
void set(value_type r, value_type g, value_type b)
Definition Vec3s:50
Vec3s & operator*=(value_type rhs)
Definition Vec3s:86
Vec3s()
Definition Vec3s:32
bool operator<(const Vec3s &v) const
Definition Vec3s:38
Vec3s operator/(value_type rhs) const
Definition Vec3s:95
value_type y() const
Definition Vec3s:68
bool operator!=(const Vec3s &v) const
Definition Vec3s:37
value_type & operator[](unsigned int i)
Definition Vec3s:60
value_type & r()
Definition Vec3s:71
value_type b() const
Definition Vec3s:77
Vec3s & operator-=(const Vec3s &rhs)
Definition Vec3s:139
@ num_components
Definition Vec3s:27
value_type r() const
Definition Vec3s:75
value_type & x()
Definition Vec3s:63
value_type _v[3]
Definition Vec3s:29
void set(const Vec3s &rhs)
Definition Vec3s:55
value_type & b()
Definition Vec3s:73
value_type x() const
Definition Vec3s:67
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