Vec3d
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_VEC3D
#define OSG_VEC3D 1
#include <osg/Vec2d>
#include <osg/Vec3f>
namespace osg {
class Vec3d
{
public:
typedef double value_type;
enum { num_components = 3 };
value_type _v[3];
Vec3d() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;}
inline Vec3d(const Vec3f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; _v[2]=vec._v[2];}
inline operator Vec3f() const { return Vec3f(static_cast<float>(_v[0]),static_cast<float>(_v[1]),static_cast<float>(_v[2]));}
Vec3d(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; }
Vec3d(const Vec2d& v2,value_type zz)
{
_v[0] = v2[0];
_v[1] = v2[1];
_v[2] = zz;
}
inline bool operator == (const Vec3d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3d& 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 x, value_type y, value_type z)
{
_v[0]=x; _v[1]=y; _v[2]=z;
}
inline void set( const Vec3d& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
}
inline value_type& operator [] (int i) { return _v[i]; }
inline value_type operator [] (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 bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]) || osg::isNaN(_v[2]); }
inline value_type operator * (const Vec3d& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1]+_v[2]*rhs._v[2];
}
inline const Vec3d operator ^ (const Vec3d& rhs) const
{
return Vec3d(_v[1]*rhs._v[2]-_v[2]*rhs._v[1],
_v[2]*rhs._v[0]-_v[0]*rhs._v[2] ,
_v[0]*rhs._v[1]-_v[1]*rhs._v[0]);
}
inline const Vec3d operator * (value_type rhs) const
{
return Vec3d(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
inline Vec3d& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
return *this;
}
inline const Vec3d operator / (value_type rhs) const
{
return Vec3d(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
inline Vec3d& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
return *this;
}
inline const Vec3d operator + (const Vec3d& rhs) const
{
return Vec3d(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
inline Vec3d& operator += (const Vec3d& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
inline const Vec3d operator - (const Vec3d& rhs) const
{
return Vec3d(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
inline Vec3d& operator -= (const Vec3d& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
inline const Vec3d operator - () const
{
return Vec3d (-_v[0], -_v[1], -_v[2]);
}
inline value_type length() const
{
return sqrt( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
inline value_type length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2];
}
inline value_type normalize()
{
value_type norm = Vec3d::length();
if (norm>0.0)
{
value_type inv = 1.0/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
}
return( norm );
}
}; // end of class Vec3d
inline Vec3d componentMultiply(const Vec3d& lhs, const Vec3d& rhs)
{
return Vec3d(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
inline Vec3d componentDivide(const Vec3d& lhs, const Vec3d& rhs)
{
return Vec3d(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
} // end of namespace osg
#endif
Vec2d
Vec3f
osg::Vec2d
Definition Vec2d:29
osg::Vec3d
Definition Vec3d:30
osg::Vec3d::value_type
double value_type
Definition Vec3d:34
osg::Vec3d::z
value_type z() const
Definition Vec3d:91
osg::Vec3d::z
value_type & z()
Definition Vec3d:87
osg::Vec3d::operator==
bool operator==(const Vec3d &v) const
Definition Vec3d:56
osg::Vec3d::Vec3d
Vec3d(const Vec3f &vec)
Definition Vec3d:44
osg::Vec3d::isNaN
bool isNaN() const
Definition Vec3d:96
osg::Vec3d::valid
bool valid() const
Definition Vec3d:94
osg::Vec3d::_v
value_type _v[3]
Definition Vec3d:39
osg::Vec3d::operator-=
Vec3d & operator-=(const Vec3d &rhs)
Definition Vec3d:166
osg::Vec3d::Vec3d
Vec3d(value_type x, value_type y, value_type z)
Definition Vec3d:48
osg::Vec3d::operator*
value_type operator*(const Vec3d &rhs) const
Definition Vec3d:99
osg::Vec3d::operator+
const Vec3d operator+(const Vec3d &rhs) const
Definition Vec3d:143
osg::Vec3d::normalize
value_type normalize()
Definition Vec3d:196
osg::Vec3d::length2
value_type length2() const
Definition Vec3d:187
osg::Vec3d::ptr
const value_type * ptr() const
Definition Vec3d:70
osg::Vec3d::Vec3d
Vec3d()
Definition Vec3d:42
osg::Vec3d::operator-
const Vec3d operator-() const
Definition Vec3d:175
osg::Vec3d::set
void set(value_type x, value_type y, value_type z)
Definition Vec3d:72
osg::Vec3d::operator^
const Vec3d operator^(const Vec3d &rhs) const
Definition Vec3d:105
osg::Vec3d::num_components
@ num_components
Definition Vec3d:37
osg::Vec3d::operator[]
value_type & operator[](int i)
Definition Vec3d:82
osg::Vec3d::ptr
value_type * ptr()
Definition Vec3d:69
osg::Vec3d::set
void set(const Vec3d &rhs)
Definition Vec3d:77
osg::Vec3d::x
value_type & x()
Definition Vec3d:85
osg::Vec3d::y
value_type & y()
Definition Vec3d:86
osg::Vec3d::operator!=
bool operator!=(const Vec3d &v) const
Definition Vec3d:58
osg::Vec3d::operator/=
Vec3d & operator/=(value_type rhs)
Definition Vec3d:134
osg::Vec3d::y
value_type y() const
Definition Vec3d:90
osg::Vec3d::operator<
bool operator<(const Vec3d &v) const
Definition Vec3d:60
osg::Vec3d::x
value_type x() const
Definition Vec3d:89
osg::Vec3d::operator+=
Vec3d & operator+=(const Vec3d &rhs)
Definition Vec3d:151
osg::Vec3d::operator*=
Vec3d & operator*=(value_type rhs)
Definition Vec3d:119
osg::Vec3d::operator/
const Vec3d operator/(value_type rhs) const
Definition Vec3d:128
osg::Vec3d::Vec3d
Vec3d(const Vec2d &v2, value_type zz)
Definition Vec3d:49
osg::Vec3d::length
value_type length() const
Definition Vec3d:181
osg::Vec3f
Definition Vec3f:29
osg::Vec3f::_v
value_type _v[3]
Definition Vec3f:38
osg
Definition AlphaFunc:19
osg::componentDivide
Vec2d componentDivide(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:187
osg::isNaN
bool isNaN(float v)
Definition Math:133
osg::componentMultiply
Vec2d componentMultiply(const Vec2d &lhs, const Vec2d &rhs)
Definition Vec2d:181