Vec3s
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_VEC3S
#define OSG_VEC3S 1
namespace osg {
class Vec3s
{
public:
typedef short value_type;
enum { num_components = 3 };
value_type _v[3];
Vec3s() { _v[0]=0; _v[1]=0; _v[2]=0; }
Vec3s(value_type r, value_type g, value_type b) { _v[0]=r; _v[1]=g; _v[2]=b; }
inline bool operator == (const Vec3s& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3s& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3s& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else if (_v[1]<v._v[1]) return true;
else if (_v[1]>v._v[1]) return false;
else return (_v[2]<v._v[2]);
}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set(value_type r, value_type g, value_type b)
{
_v[0]=r; _v[1]=g; _v[2]=b;
}
inline void set( const Vec3s& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
}
inline value_type& operator [] (unsigned int i) { return _v[i]; }
inline value_type operator [] (unsigned int i) const { return _v[i]; }
inline value_type& x() { return _v[0]; }
inline value_type& y() { return _v[1]; }
inline value_type& z() { return _v[2]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline value_type z() const { return _v[2]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type& b() { return _v[2]; }
inline value_type r() const { return _v[0]; }
inline value_type g() const { return _v[1]; }
inline value_type b() const { return _v[2]; }
inline Vec3s operator * (value_type rhs) const
{
return Vec3s(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Vec3s& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
return *this;
}
inline Vec3s operator / (value_type rhs) const
{
return Vec3s(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Vec3s& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
return *this;
}
inline Vec3s operator * (const Vec3s& rhs) const
{
return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
}
inline Vec3s operator + (const Vec3s& rhs) const
{
return Vec3s(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Vec3s& operator += (const Vec3s& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
inline Vec3s operator - (const Vec3s& rhs) const
{
return Vec3s(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Vec3s& operator -= (const Vec3s& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
inline Vec3s operator - () const
{
return Vec3s (-_v[0], -_v[1], -_v[2]);
}
}; // end of class Vec3s
inline Vec3s componentMultiply(const Vec3s& lhs, const Vec3s& rhs)
{
return Vec3s(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
inline Vec3s componentDivide(const Vec3s& lhs, const Vec3s& rhs)
{
return Vec3s(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
} // end of namespace osg
#endif
osg::Vec3s
Definition Vec3s:20
osg::Vec3s::operator-
Vec3s operator-() const
Definition Vec3s:148
osg::Vec3s::operator+=
Vec3s & operator+=(const Vec3s &rhs)
Definition Vec3s:124
osg::Vec3s::operator/=
Vec3s & operator/=(value_type rhs)
Definition Vec3s:101
osg::Vec3s::operator==
bool operator==(const Vec3s &v) const
Definition Vec3s:36
osg::Vec3s::Vec3s
Vec3s(value_type r, value_type g, value_type b)
Definition Vec3s:34
osg::Vec3s::ptr
value_type * ptr()
Definition Vec3s:47
osg::Vec3s::g
value_type & g()
Definition Vec3s:72
osg::Vec3s::operator*
Vec3s operator*(value_type rhs) const
Definition Vec3s:80
osg::Vec3s::value_type
short value_type
Definition Vec3s:24
osg::Vec3s::ptr
const value_type * ptr() const
Definition Vec3s:48
osg::Vec3s::y
value_type & y()
Definition Vec3s:64
osg::Vec3s::operator+
Vec3s operator+(const Vec3s &rhs) const
Definition Vec3s:116
osg::Vec3s::z
value_type z() const
Definition Vec3s:69
osg::Vec3s::z
value_type & z()
Definition Vec3s:65
osg::Vec3s::g
value_type g() const
Definition Vec3s:76
osg::Vec3s::set
void set(value_type r, value_type g, value_type b)
Definition Vec3s:50
osg::Vec3s::operator*=
Vec3s & operator*=(value_type rhs)
Definition Vec3s:86
osg::Vec3s::Vec3s
Vec3s()
Definition Vec3s:32
osg::Vec3s::operator<
bool operator<(const Vec3s &v) const
Definition Vec3s:38
osg::Vec3s::operator/
Vec3s operator/(value_type rhs) const
Definition Vec3s:95
osg::Vec3s::y
value_type y() const
Definition Vec3s:68
osg::Vec3s::operator!=
bool operator!=(const Vec3s &v) const
Definition Vec3s:37
osg::Vec3s::operator[]
value_type & operator[](unsigned int i)
Definition Vec3s:60
osg::Vec3s::r
value_type & r()
Definition Vec3s:71
osg::Vec3s::b
value_type b() const
Definition Vec3s:77
osg::Vec3s::operator-=
Vec3s & operator-=(const Vec3s &rhs)
Definition Vec3s:139
osg::Vec3s::r
value_type r() const
Definition Vec3s:75
osg::Vec3s::x
value_type & x()
Definition Vec3s:63
osg::Vec3s::_v
value_type _v[3]
Definition Vec3s:29
osg::Vec3s::set
void set(const Vec3s &rhs)
Definition Vec3s:55
osg::Vec3s::b
value_type & b()
Definition Vec3s:73
osg::Vec3s::x
value_type x() const
Definition Vec3s:67
osg::Vec3s::num_components
@ num_components
Definition Vec3s:27
osg
Definition AlphaFunc:19
osg::componentDivide
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:187
osg::componentMultiply
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:181