Vec4d
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_VEC4D
#define OSG_VEC4D 1
#include <osg/Vec3d>
#include <osg/Vec4f>
namespace osg {
class Vec4d
{
public:
typedef double value_type;
enum { num_components = 4 };
value_type _v[4];
Vec4d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0; }
Vec4d(value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
_v[3]=w;
}
Vec4d(const Vec3d& v3,value_type w)
{
_v[0]=v3[0];
_v[1]=v3[1];
_v[2]=v3[2];
_v[3]=w;
}
inline Vec4d(const Vec4f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; _v[2]=vec._v[2]; _v[3]=vec._v[3];}
inline operator Vec4f() const { return Vec4f(static_cast<float>(_v[0]),static_cast<float>(_v[1]),static_cast<float>(_v[2]),static_cast<float>(_v[3]));}
inline bool operator == (const Vec4d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
inline bool operator != (const Vec4d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
inline bool operator < (const Vec4d& 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 if (_v[2]<v._v[2]) return true;
else if (_v[2]>v._v[2]) return false;
else return (_v[3]<v._v[3]);
}
inline value_type* ptr() { return _v; }
inline const value_type* ptr() const { return _v; }
inline void set( value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
}
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& w() { return _v[3]; }
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 w() const { return _v[3]; }
inline value_type& r() { return _v[0]; }
inline value_type& g() { return _v[1]; }
inline value_type& b() { return _v[2]; }
inline value_type& a() { return _v[3]; }
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 value_type a() const { return _v[3]; }
inline unsigned int asABGR() const
{
return (unsigned int)clampTo((_v[0]*255.0),0.0,255.0)<<24 |
(unsigned int)clampTo((_v[1]*255.0),0.0,255.0)<<16 |
(unsigned int)clampTo((_v[2]*255.0),0.0,255.0)<<8 |
(unsigned int)clampTo((_v[3]*255.0),0.0,255.0);
}
inline unsigned int asRGBA() const
{
return (unsigned int)clampTo((_v[3]*255.0),0.0,255.0)<<24 |
(unsigned int)clampTo((_v[2]*255.0),0.0,255.0)<<16 |
(unsigned int)clampTo((_v[1]*255.0),0.0,255.0)<<8 |
(unsigned int)clampTo((_v[0]*255.0),0.0,255.0);
}
inline bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]) || osg::isNaN(_v[2]) || osg::isNaN(_v[3]); }
inline value_type operator * (const Vec4d& rhs) const
{
return _v[0]*rhs._v[0]+
_v[1]*rhs._v[1]+
_v[2]*rhs._v[2]+
_v[3]*rhs._v[3] ;
}
inline Vec4d operator * (value_type rhs) const
{
return Vec4d(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
inline Vec4d& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
_v[3]*=rhs;
return *this;
}
inline Vec4d operator / (value_type rhs) const
{
return Vec4d(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
inline Vec4d& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
_v[3]/=rhs;
return *this;
}
inline Vec4d operator + (const Vec4d& rhs) const
{
return Vec4d(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
inline Vec4d& operator += (const Vec4d& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
_v[3] += rhs._v[3];
return *this;
}
inline Vec4d operator - (const Vec4d& rhs) const
{
return Vec4d(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
}
inline Vec4d& operator -= (const Vec4d& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
_v[3]-=rhs._v[3];
return *this;
}
inline const Vec4d operator - () const
{
return Vec4d (-_v[0], -_v[1], -_v[2], -_v[3]);
}
inline value_type length() const
{
return sqrt( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3]);
}
inline value_type length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
}
inline value_type normalize()
{
value_type norm = Vec4d::length();
if (norm>0.0f)
{
value_type inv = 1.0/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
_v[3] *= inv;
}
return( norm );
}
}; // end of class Vec4d
inline Vec4d::value_type operator * (const Vec3d& lhs,const Vec4d& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3];
}
inline Vec4d::value_type operator * (const Vec3f& lhs,const Vec4d& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3];
}
inline Vec4d::value_type operator * (const Vec3d& lhs,const Vec4f& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3];
}
inline Vec4d::value_type operator * (const Vec4d& lhs,const Vec3d& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
}
inline Vec4d::value_type operator * (const Vec4d& lhs,const Vec3f& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
}
inline Vec4d::value_type operator * (const Vec4f& lhs,const Vec3d& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
}
inline Vec4d componentMultiply(const Vec4d& lhs, const Vec4d& rhs)
{
return Vec4d(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
}
inline Vec4d componentDivide(const Vec4d& lhs, const Vec4d& rhs)
{
return Vec4d(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
}
} // end of namespace osg
#endif
Vec3d
Vec4f
osg::Vec3d
Definition Vec3d:30
osg::Vec3f
Definition Vec3f:29
osg::Vec4d
Definition Vec4d:29
osg::Vec4d::operator==
bool operator==(const Vec4d &v) const
Definition Vec4d:64
osg::Vec4d::operator/
Vec4d operator/(value_type rhs) const
Definition Vec4d:158
osg::Vec4d::x
value_type & x()
Definition Vec4d:90
osg::Vec4d::valid
bool valid() const
Definition Vec4d:128
osg::Vec4d::isNaN
bool isNaN() const
Definition Vec4d:130
osg::Vec4d::b
value_type & b()
Definition Vec4d:102
osg::Vec4d::operator/=
Vec4d & operator/=(value_type rhs)
Definition Vec4d:164
osg::Vec4d::normalize
value_type normalize()
Definition Vec4d:230
osg::Vec4d::operator+=
Vec4d & operator+=(const Vec4d &rhs)
Definition Vec4d:183
osg::Vec4d::y
value_type & y()
Definition Vec4d:91
osg::Vec4d::_v
value_type _v[4]
Definition Vec4d:38
osg::Vec4d::asRGBA
unsigned int asRGBA() const
Definition Vec4d:119
osg::Vec4d::g
value_type g() const
Definition Vec4d:106
osg::Vec4d::Vec4d
Vec4d(value_type x, value_type y, value_type z, value_type w)
Definition Vec4d:43
osg::Vec4d::Vec4d
Vec4d(const Vec3d &v3, value_type w)
Definition Vec4d:51
osg::Vec4d::z
value_type & z()
Definition Vec4d:92
osg::Vec4d::num_components
@ num_components
Definition Vec4d:36
osg::Vec4d::operator-
const Vec4d operator-() const
Definition Vec4d:210
osg::Vec4d::ptr
const value_type * ptr() const
Definition Vec4d:80
osg::Vec4d::asABGR
unsigned int asABGR() const
Definition Vec4d:111
osg::Vec4d::r
value_type r() const
Definition Vec4d:105
osg::Vec4d::a
value_type a() const
Definition Vec4d:108
osg::Vec4d::r
value_type & r()
Definition Vec4d:100
osg::Vec4d::value_type
double value_type
Definition Vec4d:33
osg::Vec4d::length
value_type length() const
Definition Vec4d:216
osg::Vec4d::operator[]
value_type & operator[](unsigned int i)
Definition Vec4d:87
osg::Vec4d::Vec4d
Vec4d()
Definition Vec4d:41
osg::Vec4d::operator<
bool operator<(const Vec4d &v) const
Definition Vec4d:68
osg::Vec4d::length2
value_type length2() const
Definition Vec4d:222
osg::Vec4d::operator!=
bool operator!=(const Vec4d &v) const
Definition Vec4d:66
osg::Vec4d::operator*
value_type operator*(const Vec4d &rhs) const
Definition Vec4d:133
osg::Vec4d::Vec4d
Vec4d(const Vec4f &vec)
Definition Vec4d:59
osg::Vec4d::g
value_type & g()
Definition Vec4d:101
osg::Vec4d::operator-=
Vec4d & operator-=(const Vec4d &rhs)
Definition Vec4d:200
osg::Vec4d::b
value_type b() const
Definition Vec4d:107
osg::Vec4d::a
value_type & a()
Definition Vec4d:103
osg::Vec4d::operator*=
Vec4d & operator*=(value_type rhs)
Definition Vec4d:148
osg::Vec4d::set
void set(value_type x, value_type y, value_type z, value_type w)
Definition Vec4d:82
osg::Vec4d::x
value_type x() const
Definition Vec4d:95
osg::Vec4d::ptr
value_type * ptr()
Definition Vec4d:79
osg::Vec4d::z
value_type z() const
Definition Vec4d:97
osg::Vec4d::operator+
Vec4d operator+(const Vec4d &rhs) const
Definition Vec4d:174
osg::Vec4d::w
value_type w() const
Definition Vec4d:98
osg::Vec4d::y
value_type y() const
Definition Vec4d:96
osg::Vec4d::w
value_type & w()
Definition Vec4d:93
osg::Vec4f
Definition Vec4f:28
osg::Vec4f::_v
value_type _v[4]
Definition Vec4f:38
osg
Definition AlphaFunc:19
osg::operator*
Vec3f operator*(const Vec3f &v, const Matrixd &m)
Definition Matrixd:793
osg::componentDivide
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:187
osg::isNaN
bool isNaN(float v)
Definition Math:133
osg::clampTo
T clampTo(T v, T minimum, T maximum)
Definition Math:88
osg::componentMultiply
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:181