Added Vec2d, Vec3d and Vec4d classes, and remapped Vec2, Vec3 and Vec4 to

Vec2f, Vec3f an Vec4f respectively, with typedef's to the from Vec* to Vec*f.
This commit is contained in:
Robert Osfield
2004-05-20 10:15:48 +00:00
parent 17214df1fc
commit f02c75f5ea
40 changed files with 2150 additions and 977 deletions

View File

@@ -47,24 +47,24 @@ class SG_EXPORT AnimationPath : public virtual osg::Object
ControlPoint():
_scale(1.0f,1.0f,1.0f) {}
ControlPoint(const osg::Vec3& position):
ControlPoint(const osg::Vec3d& position):
_position(position),
_rotation(),
_scale(1.0f,1.0f,1.0f) {}
ControlPoint(const osg::Vec3& position, const osg::Quat& rotation):
ControlPoint(const osg::Vec3d& position, const osg::Quat& rotation):
_position(position),
_rotation(rotation),
_scale(1.0f,1.0f,1.0f) {}
ControlPoint(const osg::Vec3& position, const osg::Quat& rotation, const osg::Vec3& scale):
ControlPoint(const osg::Vec3d& position, const osg::Quat& rotation, const osg::Vec3d& scale):
_position(position),
_rotation(rotation),
_scale(scale) {}
osg::Vec3 _position;
osg::Vec3d _position;
osg::Quat _rotation;
osg::Vec3 _scale;
osg::Vec3d _scale;
inline void interpolate(float ratio,const ControlPoint& first, const ControlPoint& second)
@@ -230,8 +230,8 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
AnimationPath* getAnimationPath() { return _animationPath.get(); }
const AnimationPath* getAnimationPath() const { return _animationPath.get(); }
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; }
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; }
inline const Vec3d& getPivotPoint() const { return _pivotPoint; }
void setUseInverseMatrix(bool useInverseMatrix) { _useInverseMatrix = useInverseMatrix; }
bool getUseInverseMatrix() const { return _useInverseMatrix; }
@@ -259,7 +259,7 @@ class SG_EXPORT AnimationPathCallback : public NodeCallback
public:
ref_ptr<AnimationPath> _animationPath;
osg::Vec3 _pivotPoint;
osg::Vec3d _pivotPoint;
bool _useInverseMatrix;
double _timeOffset;
double _timeMultiplier;

View File

@@ -57,7 +57,7 @@ class EllipsoidModel : public Object
inline void computeLocalToWorldTransformFromXYZ(double X, double Y, double Z, osg::Matrixd& localToWorld) const;
inline osg::Vec3 computeLocalUpVector(double X, double Y, double Z) const;
inline osg::Vec3d computeLocalUpVector(double X, double Y, double Z) const;
protected:
@@ -109,16 +109,10 @@ class SG_EXPORT CoordinateSystemNode : public Group
const EllipsoidModel* getEllipsoidModel() const { return _ellipsoidModel.get(); }
/** compute the local coorindate frame for specified point.*/
CoordinateFrame computeLocalCoordinateFrame(const Vec3& position) const;
CoordinateFrame computeLocalCoordinateFrame(const Vec3d& position) const;
/** compute the local coorindate frame for specified point.*/
CoordinateFrame computeLocalCoordinateFrame(double X, double Y, double Z) const;
/** compute the local coorindate frame for specified point.*/
osg::Vec3 computeLocalUpVector(const Vec3& position) const;
/** compute the local coorindate frame for specified point.*/
osg::Vec3 computeLocalUpVector(double X, double Y, double Z) const;
osg::Vec3d computeLocalUpVector(const Vec3d& position) const;
protected:
@@ -211,7 +205,7 @@ inline void EllipsoidModel::computeLocalToWorldTransformFromXYZ(double X, double
localToWorld(2,2) = Z;
}
inline osg::Vec3 EllipsoidModel::computeLocalUpVector(double X, double Y, double Z) const
inline osg::Vec3d EllipsoidModel::computeLocalUpVector(double X, double Y, double Z) const
{
osg::Vec3 normal(X,Y,Z);
normal.normalize();

View File

@@ -22,9 +22,9 @@
namespace osg {
class Vec2;
class Vec3;
class Vec4;
class Vec2f;
class Vec3f;
class Vec4f;
class UByte4;
class Geometry;

View File

@@ -15,8 +15,10 @@
#define OSG_MATRIXD 1
#include <osg/Object>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec3f>
#include <osg/Vec3d>
#include <osg/Vec4f>
#include <osg/Vec4d>
#include <osg/Quat>
#include <string.h>
@@ -71,7 +73,7 @@ class SG_EXPORT Matrixd
return *this;
}
inline Matrixd& operator = (const Matrixf& other);
Matrixd& operator = (const Matrixf& other);
inline void set(const Matrixd& rhs) { set(rhs.ptr()); }
@@ -103,19 +105,26 @@ class SG_EXPORT Matrixd
void makeIdentity();
void makeScale( const Vec3& );
void makeScale( const Vec3f& );
void makeScale( const Vec3d& );
void makeScale( value_type, value_type, value_type );
void makeTranslate( const Vec3& );
void makeTranslate( const Vec3f& );
void makeTranslate( const Vec3d& );
void makeTranslate( value_type, value_type, value_type );
void makeRotate( const Vec3& from, const Vec3& to );
void makeRotate( value_type angle, const Vec3& axis );
void makeRotate( const Vec3f& from, const Vec3f& to );
void makeRotate( const Vec3d& from, const Vec3d& to );
void makeRotate( value_type angle, const Vec3f& axis );
void makeRotate( value_type angle, const Vec3d& axis );
void makeRotate( value_type angle, value_type x, value_type y, value_type z );
void makeRotate( const Quat& );
void makeRotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3);
void makeRotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3);
void makeRotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3);
@@ -163,10 +172,13 @@ class SG_EXPORT Matrixd
double& zNear, double& zFar) const;
/** Set to the position and orientation modelview matrix, using the same convention as gluLookAt. */
void makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
void getLookAt(Vec3& eye,Vec3& center,Vec3& up,value_type lookDistance=1.0f) const;
void getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,value_type lookDistance=1.0f) const;
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,value_type lookDistance=1.0f) const;
/** invert the matrix rhs. */
bool invert( const Matrixd& rhs);
@@ -179,16 +191,23 @@ class SG_EXPORT Matrixd
//basic utility functions to create new matrices
inline static Matrixd identity( void );
inline static Matrixd scale( const Vec3& sv);
inline static Matrixd scale( const Vec3f& sv);
inline static Matrixd scale( const Vec3d& sv);
inline static Matrixd scale( value_type sx, value_type sy, value_type sz);
inline static Matrixd translate( const Vec3& dv);
inline static Matrixd translate( const Vec3f& dv);
inline static Matrixd translate( const Vec3d& dv);
inline static Matrixd translate( value_type x, value_type y, value_type z);
inline static Matrixd rotate( const Vec3& from, const Vec3& to);
inline static Matrixd rotate( const Vec3f& from, const Vec3f& to);
inline static Matrixd rotate( const Vec3d& from, const Vec3d& to);
inline static Matrixd rotate( value_type angle, value_type x, value_type y, value_type z);
inline static Matrixd rotate( value_type angle, const Vec3& axis);
inline static Matrixd rotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3);
inline static Matrixd rotate( value_type angle, const Vec3f& axis);
inline static Matrixd rotate( value_type angle, const Vec3d& axis);
inline static Matrixd rotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3);
inline static Matrixd rotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3);
inline static Matrixd rotate( const Quat& quat);
inline static Matrixd inverse( const Matrixd& matrix);
@@ -212,29 +231,45 @@ class SG_EXPORT Matrixd
double zNear, double zFar);
/** Create the position and orientation as per a camera, using the same convention as gluLookAt. */
inline static Matrixd lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
inline static Matrixd lookAt(const Vec3f& eye,const Vec3f& center,const Vec3f& up);
/** Create the position and orientation as per a camera, using the same convention as gluLookAt. */
inline static Matrixd lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
inline Vec3 preMult( const Vec3& v ) const;
inline Vec3 postMult( const Vec3& v ) const;
inline Vec3 operator* ( const Vec3& v ) const;
inline Vec4 preMult( const Vec4& v ) const;
inline Vec4 postMult( const Vec4& v ) const;
inline Vec4 operator* ( const Vec4& v ) const;
inline Vec3f preMult( const Vec3f& v ) const;
inline Vec3d preMult( const Vec3d& v ) const;
inline Vec3f postMult( const Vec3f& v ) const;
inline Vec3d postMult( const Vec3d& v ) const;
inline Vec3f operator* ( const Vec3f& v ) const;
inline Vec3d operator* ( const Vec3d& v ) const;
inline Vec4f preMult( const Vec4f& v ) const;
inline Vec4d preMult( const Vec4d& v ) const;
inline Vec4f postMult( const Vec4f& v ) const;
inline Vec4d postMult( const Vec4d& v ) const;
inline Vec4f operator* ( const Vec4f& v ) const;
inline Vec4d operator* ( const Vec4d& v ) const;
void setTrans( value_type tx, value_type ty, value_type tz );
void setTrans( const Vec3& v );
inline Vec3 getTrans() const { return Vec3(_mat[3][0],_mat[3][1],_mat[3][2]); }
void setTrans( const Vec3f& v );
void setTrans( const Vec3d& v );
inline Vec3 getScale() const { return Vec3(_mat[0][0],_mat[1][1],_mat[2][2]); }
inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); }
inline Vec3d getScale() const { return Vec3d(_mat[0][0],_mat[1][1],_mat[2][2]); }
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
inline static Vec3 transform3x3(const Vec3& v,const Matrixd& m);
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
inline static Vec3 transform3x3(const Matrixd& m,const Vec3& v);
inline static Vec3f transform3x3(const Vec3f& v,const Matrixd& m);
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
inline static Vec3d transform3x3(const Vec3d& v,const Matrixd& m);
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
inline static Vec3f transform3x3(const Matrixd& m,const Vec3f& v);
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
inline static Vec3d transform3x3(const Matrixd& m,const Vec3d& v);
// basic Matrixd multiplication, our workhorse methods.
void mult( const Matrixd&, const Matrixd& );
@@ -307,7 +342,12 @@ inline Matrixd Matrixd::scale(value_type sx, value_type sy, value_type sz)
return m;
}
inline Matrixd Matrixd::scale(const Vec3& v )
inline Matrixd Matrixd::scale(const Vec3f& v )
{
return scale(v.x(), v.y(), v.z() );
}
inline Matrixd Matrixd::scale(const Vec3d& v )
{
return scale(v.x(), v.y(), v.z() );
}
@@ -319,7 +359,12 @@ inline Matrixd Matrixd::translate(value_type tx, value_type ty, value_type tz)
return m;
}
inline Matrixd Matrixd::translate(const Vec3& v )
inline Matrixd Matrixd::translate(const Vec3f& v )
{
return translate(v.x(), v.y(), v.z() );
}
inline Matrixd Matrixd::translate(const Vec3d& v )
{
return translate(v.x(), v.y(), v.z() );
}
@@ -334,21 +379,41 @@ inline Matrixd Matrixd::rotate(value_type angle, value_type x, value_type y, val
m.makeRotate(angle,x,y,z);
return m;
}
inline Matrixd Matrixd::rotate(value_type angle, const Vec3& axis )
inline Matrixd Matrixd::rotate(value_type angle, const Vec3f& axis )
{
Matrixd m;
m.makeRotate(angle,axis);
return m;
}
inline Matrixd Matrixd::rotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3)
inline Matrixd Matrixd::rotate(value_type angle, const Vec3d& axis )
{
Matrixd m;
m.makeRotate(angle,axis);
return m;
}
inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3)
{
Matrixd m;
m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
return m;
}
inline Matrixd Matrixd::rotate(const Vec3& from, const Vec3& to )
inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3)
{
Matrixd m;
m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
return m;
}
inline Matrixd Matrixd::rotate(const Vec3f& from, const Vec3f& to )
{
Matrixd m;
m.makeRotate(from,to);
return m;
}
inline Matrixd Matrixd::rotate(const Vec3d& from, const Vec3d& to )
{
Matrixd m;
m.makeRotate(from,to);
@@ -363,8 +428,8 @@ inline Matrixd Matrixd::inverse( const Matrixd& matrix)
}
inline Matrixd Matrixd::ortho(double left, double right,
double bottom, double top,
double zNear, double zFar)
double bottom, double top,
double zNear, double zFar)
{
Matrixd m;
m.makeOrtho(left,right,bottom,top,zNear,zFar);
@@ -372,7 +437,7 @@ inline Matrixd Matrixd::ortho(double left, double right,
}
inline Matrixd Matrixd::ortho2D(double left, double right,
double bottom, double top)
double bottom, double top)
{
Matrixd m;
m.makeOrtho2D(left,right,bottom,top);
@@ -380,8 +445,8 @@ inline Matrixd Matrixd::ortho2D(double left, double right,
}
inline Matrixd Matrixd::frustum(double left, double right,
double bottom, double top,
double zNear, double zFar)
double bottom, double top,
double zNear, double zFar)
{
Matrixd m;
m.makeFrustum(left,right,bottom,top,zNear,zFar);
@@ -396,74 +461,136 @@ inline Matrixd Matrixd::perspective(double fovy,double aspectRatio,
return m;
}
inline Matrixd Matrixd::lookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
inline Matrixd Matrixd::lookAt(const Vec3f& eye,const Vec3f& center,const Vec3f& up)
{
Matrixd m;
m.makeLookAt(eye,center,up);
return m;
}
inline Matrixd Matrixd::lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up)
{
Matrixd m;
m.makeLookAt(eye,center,up);
return m;
}
inline Vec3 Matrixd::postMult( const Vec3& v ) const
inline Vec3f Matrixd::postMult( const Vec3f& v ) const
{
value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
return Vec3( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
return Vec3f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
}
inline Vec3d Matrixd::postMult( const Vec3d& v ) const
{
value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
return Vec3d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
}
inline Vec3 Matrixd::preMult( const Vec3& v ) const
inline Vec3f Matrixd::preMult( const Vec3f& v ) const
{
value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
return Vec3( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
return Vec3f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
}
inline Vec3d Matrixd::preMult( const Vec3d& v ) const
{
value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
return Vec3d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
}
inline Vec4 Matrixd::postMult( const Vec4& v ) const
inline Vec4f Matrixd::postMult( const Vec4f& v ) const
{
return Vec4( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
return Vec4f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
}
inline Vec4d Matrixd::postMult( const Vec4d& v ) const
{
return Vec4d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
}
inline Vec4 Matrixd::preMult( const Vec4& v ) const
inline Vec4f Matrixd::preMult( const Vec4f& v ) const
{
return Vec4( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
return Vec4f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
(_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
}
inline Vec3 Matrixd::transform3x3(const Vec3& v,const Matrixd& m)
inline Vec4d Matrixd::preMult( const Vec4d& v ) const
{
return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
return Vec4d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
(_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
}
inline Vec3f Matrixd::transform3x3(const Vec3f& v,const Matrixd& m)
{
return Vec3f( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
}
inline Vec3d Matrixd::transform3x3(const Vec3d& v,const Matrixd& m)
{
return Vec3d( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
}
inline Vec3 Matrixd::transform3x3(const Matrixd& m,const Vec3& v)
inline Vec3f Matrixd::transform3x3(const Matrixd& m,const Vec3f& v)
{
return Vec3( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
return Vec3f( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
}
inline Vec3d Matrixd::transform3x3(const Matrixd& m,const Vec3d& v)
{
return Vec3d( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
}
inline Vec3 operator* (const Vec3& v, const Matrixd& m )
inline Vec3f operator* (const Vec3f& v, const Matrixd& m )
{
return m.preMult(v);
}
inline Vec4 operator* (const Vec4& v, const Matrixd& m )
inline Vec3d operator* (const Vec3d& v, const Matrixd& m )
{
return m.preMult(v);
}
inline Vec4f operator* (const Vec4f& v, const Matrixd& m )
{
return m.preMult(v);
}
inline Vec4d operator* (const Vec4d& v, const Matrixd& m )
{
return m.preMult(v);
}
inline Vec3 Matrixd::operator* (const Vec3& v) const
inline Vec3f Matrixd::operator* (const Vec3f& v) const
{
return postMult(v);
}
inline Vec4 Matrixd::operator* (const Vec4& v) const
inline Vec3d Matrixd::operator* (const Vec3d& v) const
{
return postMult(v);
}
inline Vec4f Matrixd::operator* (const Vec4f& v) const
{
return postMult(v);
}
inline Vec4d Matrixd::operator* (const Vec4d& v) const
{
return postMult(v);
}

View File

@@ -15,8 +15,10 @@
#define OSG_MATRIXF 1
#include <osg/Object>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec3f>
#include <osg/Vec3d>
#include <osg/Vec4f>
#include <osg/Vec4d>
#include <osg/Quat>
#include <string.h>
@@ -26,12 +28,14 @@
namespace osg {
class Matrixd;
class SG_EXPORT Matrixf
{
public:
typedef float value_type;
typedef double value_type;
inline Matrixf() { makeIdentity(); }
inline Matrixf( const Matrixf& mat) { set(mat.ptr()); }
@@ -68,13 +72,13 @@ class SG_EXPORT Matrixf
set(rhs.ptr());
return *this;
}
Matrixf& operator = (const Matrixd& rhs);
void set(const Matrixd& rhs);
Matrixf& operator = (const Matrixd& other);
inline void set(const Matrixf& rhs) { set(rhs.ptr()); }
void set(const Matrixd& rhs);
inline void set(float const * const ptr)
{
value_type* local_ptr = (value_type*)_mat;
@@ -101,19 +105,26 @@ class SG_EXPORT Matrixf
void makeIdentity();
void makeScale( const Vec3& );
void makeScale( const Vec3f& );
void makeScale( const Vec3d& );
void makeScale( value_type, value_type, value_type );
void makeTranslate( const Vec3& );
void makeTranslate( const Vec3f& );
void makeTranslate( const Vec3d& );
void makeTranslate( value_type, value_type, value_type );
void makeRotate( const Vec3& from, const Vec3& to );
void makeRotate( value_type angle, const Vec3& axis );
void makeRotate( const Vec3f& from, const Vec3f& to );
void makeRotate( const Vec3d& from, const Vec3d& to );
void makeRotate( value_type angle, const Vec3f& axis );
void makeRotate( value_type angle, const Vec3d& axis );
void makeRotate( value_type angle, value_type x, value_type y, value_type z );
void makeRotate( const Quat& );
void makeRotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3);
void makeRotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3);
void makeRotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3);
@@ -142,7 +153,7 @@ class SG_EXPORT Matrixf
double zNear, double zFar);
/** Get the frustum setting of a perspective projection matrix.
* Returns false if matrix is not an orthographic matrix, where parameter values are undefined.*/
* Note, if matrix is not an perspective matrix then invalid values will be returned.*/
bool getFrustum(double& left, double& right,
double& bottom, double& top,
double& zNear, double& zFar) const;
@@ -160,14 +171,16 @@ class SG_EXPORT Matrixf
bool getPerspective(double& fovy,double& aspectRatio,
double& zNear, double& zFar) const;
/** Set to the position and orientation modelview matrix, using the same convention as gluLookAt. */
void makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
void getLookAt(Vec3& eye,Vec3& center,Vec3& up,value_type lookDistance=1.0f) const;
void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
/** invert the matrix rhs placing result in this matrix.*/
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
void getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,value_type lookDistance=1.0f) const;
/** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */
void getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,value_type lookDistance=1.0f) const;
/** invert the matrix rhs. */
bool invert( const Matrixf& rhs);
/** full 4x4 matrix invert. */
@@ -178,16 +191,23 @@ class SG_EXPORT Matrixf
//basic utility functions to create new matrices
inline static Matrixf identity( void );
inline static Matrixf scale( const Vec3& sv);
inline static Matrixf scale( const Vec3f& sv);
inline static Matrixf scale( const Vec3d& sv);
inline static Matrixf scale( value_type sx, value_type sy, value_type sz);
inline static Matrixf translate( const Vec3& dv);
inline static Matrixf translate( const Vec3f& dv);
inline static Matrixf translate( const Vec3d& dv);
inline static Matrixf translate( value_type x, value_type y, value_type z);
inline static Matrixf rotate( const Vec3& from, const Vec3& to);
inline static Matrixf rotate( const Vec3f& from, const Vec3f& to);
inline static Matrixf rotate( const Vec3d& from, const Vec3d& to);
inline static Matrixf rotate( value_type angle, value_type x, value_type y, value_type z);
inline static Matrixf rotate( value_type angle, const Vec3& axis);
inline static Matrixf rotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3);
inline static Matrixf rotate( value_type angle, const Vec3f& axis);
inline static Matrixf rotate( value_type angle, const Vec3d& axis);
inline static Matrixf rotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3);
inline static Matrixf rotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3);
inline static Matrixf rotate( const Quat& quat);
inline static Matrixf inverse( const Matrixf& matrix);
@@ -211,29 +231,45 @@ class SG_EXPORT Matrixf
double zNear, double zFar);
/** Create the position and orientation as per a camera, using the same convention as gluLookAt. */
inline static Matrixf lookAt(const Vec3& eye,const Vec3& center,const Vec3& up);
inline static Matrixf lookAt(const Vec3f& eye,const Vec3f& center,const Vec3f& up);
/** Create the position and orientation as per a camera, using the same convention as gluLookAt. */
inline static Matrixf lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);
inline Vec3 preMult( const Vec3& v ) const;
inline Vec3 postMult( const Vec3& v ) const;
inline Vec3 operator* ( const Vec3& v ) const;
inline Vec4 preMult( const Vec4& v ) const;
inline Vec4 postMult( const Vec4& v ) const;
inline Vec4 operator* ( const Vec4& v ) const;
inline Vec3f preMult( const Vec3f& v ) const;
inline Vec3d preMult( const Vec3d& v ) const;
inline Vec3f postMult( const Vec3f& v ) const;
inline Vec3d postMult( const Vec3d& v ) const;
inline Vec3f operator* ( const Vec3f& v ) const;
inline Vec3d operator* ( const Vec3d& v ) const;
inline Vec4f preMult( const Vec4f& v ) const;
inline Vec4d preMult( const Vec4d& v ) const;
inline Vec4f postMult( const Vec4f& v ) const;
inline Vec4d postMult( const Vec4d& v ) const;
inline Vec4f operator* ( const Vec4f& v ) const;
inline Vec4d operator* ( const Vec4d& v ) const;
void setTrans( value_type tx, value_type ty, value_type tz );
void setTrans( const Vec3& v );
inline Vec3 getTrans() const { return Vec3(_mat[3][0],_mat[3][1],_mat[3][2]); }
void setTrans( const Vec3f& v );
void setTrans( const Vec3d& v );
inline Vec3 getScale() const { return Vec3(_mat[0][0],_mat[1][1],_mat[2][2]); }
inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); }
inline Vec3d getScale() const { return Vec3d(_mat[0][0],_mat[1][1],_mat[2][2]); }
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
inline static Vec3 transform3x3(const Vec3& v,const Matrixf& m);
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
inline static Vec3 transform3x3(const Matrixf& m,const Vec3& v);
inline static Vec3f transform3x3(const Vec3f& v,const Matrixf& m);
/** apply apply an 3x3 transform of v*M[0..2,0..2] */
inline static Vec3d transform3x3(const Vec3d& v,const Matrixf& m);
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
inline static Vec3f transform3x3(const Matrixf& m,const Vec3f& v);
/** apply apply an 3x3 transform of M[0..2,0..2]*v */
inline static Vec3d transform3x3(const Matrixf& m,const Vec3d& v);
// basic Matrixf multiplication, our workhorse methods.
void mult( const Matrixf&, const Matrixf& );
@@ -306,7 +342,12 @@ inline Matrixf Matrixf::scale(value_type sx, value_type sy, value_type sz)
return m;
}
inline Matrixf Matrixf::scale(const Vec3& v )
inline Matrixf Matrixf::scale(const Vec3f& v )
{
return scale(v.x(), v.y(), v.z() );
}
inline Matrixf Matrixf::scale(const Vec3d& v )
{
return scale(v.x(), v.y(), v.z() );
}
@@ -318,7 +359,12 @@ inline Matrixf Matrixf::translate(value_type tx, value_type ty, value_type tz)
return m;
}
inline Matrixf Matrixf::translate(const Vec3& v )
inline Matrixf Matrixf::translate(const Vec3f& v )
{
return translate(v.x(), v.y(), v.z() );
}
inline Matrixf Matrixf::translate(const Vec3d& v )
{
return translate(v.x(), v.y(), v.z() );
}
@@ -333,21 +379,41 @@ inline Matrixf Matrixf::rotate(value_type angle, value_type x, value_type y, val
m.makeRotate(angle,x,y,z);
return m;
}
inline Matrixf Matrixf::rotate(value_type angle, const Vec3& axis )
inline Matrixf Matrixf::rotate(value_type angle, const Vec3f& axis )
{
Matrixf m;
m.makeRotate(angle,axis);
return m;
}
inline Matrixf Matrixf::rotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3)
inline Matrixf Matrixf::rotate(value_type angle, const Vec3d& axis )
{
Matrixf m;
m.makeRotate(angle,axis);
return m;
}
inline Matrixf Matrixf::rotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3)
{
Matrixf m;
m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
return m;
}
inline Matrixf Matrixf::rotate(const Vec3& from, const Vec3& to )
inline Matrixf Matrixf::rotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3)
{
Matrixf m;
m.makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
return m;
}
inline Matrixf Matrixf::rotate(const Vec3f& from, const Vec3f& to )
{
Matrixf m;
m.makeRotate(from,to);
return m;
}
inline Matrixf Matrixf::rotate(const Vec3d& from, const Vec3d& to )
{
Matrixf m;
m.makeRotate(from,to);
@@ -395,74 +461,136 @@ inline Matrixf Matrixf::perspective(double fovy,double aspectRatio,
return m;
}
inline Matrixf Matrixf::lookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
inline Matrixf Matrixf::lookAt(const Vec3f& eye,const Vec3f& center,const Vec3f& up)
{
Matrixf m;
m.makeLookAt(eye,center,up);
return m;
}
inline Matrixf Matrixf::lookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up)
{
Matrixf m;
m.makeLookAt(eye,center,up);
return m;
}
inline Vec3 Matrixf::postMult( const Vec3& v ) const
inline Vec3f Matrixf::postMult( const Vec3f& v ) const
{
value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
return Vec3( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
return Vec3f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
}
inline Vec3d Matrixf::postMult( const Vec3d& v ) const
{
value_type d = 1.0f/(_mat[3][0]*v.x()+_mat[3][1]*v.y()+_mat[3][2]*v.z()+_mat[3][3]) ;
return Vec3d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3])*d,
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3])*d,
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3])*d) ;
}
inline Vec3 Matrixf::preMult( const Vec3& v ) const
inline Vec3f Matrixf::preMult( const Vec3f& v ) const
{
value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
return Vec3( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
return Vec3f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
}
inline Vec3d Matrixf::preMult( const Vec3d& v ) const
{
value_type d = 1.0f/(_mat[0][3]*v.x()+_mat[1][3]*v.y()+_mat[2][3]*v.z()+_mat[3][3]) ;
return Vec3d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0])*d,
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1])*d,
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2])*d);
}
inline Vec4 Matrixf::postMult( const Vec4& v ) const
inline Vec4f Matrixf::postMult( const Vec4f& v ) const
{
return Vec4( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
return Vec4f( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
}
inline Vec4d Matrixf::postMult( const Vec4d& v ) const
{
return Vec4d( (_mat[0][0]*v.x() + _mat[0][1]*v.y() + _mat[0][2]*v.z() + _mat[0][3]*v.w()),
(_mat[1][0]*v.x() + _mat[1][1]*v.y() + _mat[1][2]*v.z() + _mat[1][3]*v.w()),
(_mat[2][0]*v.x() + _mat[2][1]*v.y() + _mat[2][2]*v.z() + _mat[2][3]*v.w()),
(_mat[3][0]*v.x() + _mat[3][1]*v.y() + _mat[3][2]*v.z() + _mat[3][3]*v.w())) ;
}
inline Vec4 Matrixf::preMult( const Vec4& v ) const
inline Vec4f Matrixf::preMult( const Vec4f& v ) const
{
return Vec4( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
return Vec4f( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
(_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
}
inline Vec3 Matrixf::transform3x3(const Vec3& v,const Matrixf& m)
inline Vec4d Matrixf::preMult( const Vec4d& v ) const
{
return Vec3( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
return Vec4d( (_mat[0][0]*v.x() + _mat[1][0]*v.y() + _mat[2][0]*v.z() + _mat[3][0]*v.w()),
(_mat[0][1]*v.x() + _mat[1][1]*v.y() + _mat[2][1]*v.z() + _mat[3][1]*v.w()),
(_mat[0][2]*v.x() + _mat[1][2]*v.y() + _mat[2][2]*v.z() + _mat[3][2]*v.w()),
(_mat[0][3]*v.x() + _mat[1][3]*v.y() + _mat[2][3]*v.z() + _mat[3][3]*v.w()));
}
inline Vec3f Matrixf::transform3x3(const Vec3f& v,const Matrixf& m)
{
return Vec3f( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
}
inline Vec3d Matrixf::transform3x3(const Vec3d& v,const Matrixf& m)
{
return Vec3d( (m._mat[0][0]*v.x() + m._mat[1][0]*v.y() + m._mat[2][0]*v.z()),
(m._mat[0][1]*v.x() + m._mat[1][1]*v.y() + m._mat[2][1]*v.z()),
(m._mat[0][2]*v.x() + m._mat[1][2]*v.y() + m._mat[2][2]*v.z()));
}
inline Vec3 Matrixf::transform3x3(const Matrixf& m,const Vec3& v)
inline Vec3f Matrixf::transform3x3(const Matrixf& m,const Vec3f& v)
{
return Vec3( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
return Vec3f( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
}
inline Vec3d Matrixf::transform3x3(const Matrixf& m,const Vec3d& v)
{
return Vec3d( (m._mat[0][0]*v.x() + m._mat[0][1]*v.y() + m._mat[0][2]*v.z()),
(m._mat[1][0]*v.x() + m._mat[1][1]*v.y() + m._mat[1][2]*v.z()),
(m._mat[2][0]*v.x() + m._mat[2][1]*v.y() + m._mat[2][2]*v.z()) ) ;
}
inline Vec3 operator* (const Vec3& v, const Matrixf& m )
inline Vec3f operator* (const Vec3f& v, const Matrixf& m )
{
return m.preMult(v);
}
inline Vec4 operator* (const Vec4& v, const Matrixf& m )
inline Vec3d operator* (const Vec3d& v, const Matrixf& m )
{
return m.preMult(v);
}
inline Vec4f operator* (const Vec4f& v, const Matrixf& m )
{
return m.preMult(v);
}
inline Vec4d operator* (const Vec4d& v, const Matrixf& m )
{
return m.preMult(v);
}
inline Vec3 Matrixf::operator* (const Vec3& v) const
inline Vec3f Matrixf::operator* (const Vec3f& v) const
{
return postMult(v);
}
inline Vec4 Matrixf::operator* (const Vec4& v) const
inline Vec3d Matrixf::operator* (const Vec3d& v) const
{
return postMult(v);
}
inline Vec4f Matrixf::operator* (const Vec4f& v) const
{
return postMult(v);
}
inline Vec4d Matrixf::operator* (const Vec4d& v) const
{
return postMult(v);
}

View File

@@ -17,6 +17,7 @@
#include <osg/Group>
#include <osg/Transform>
#include <osg/AnimationPath>
#include <osg/Vec3d>
#include <osg/Quat>
namespace osg {
@@ -42,20 +43,20 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
virtual PositionAttitudeTransform* asPositionAttitudeTransform() { return this; }
virtual const PositionAttitudeTransform* asPositionAttitudeTransform() const { return this; }
inline void setPosition(const Vec3& pos) { _position = pos; dirtyBound(); }
inline const Vec3& getPosition() const { return _position; }
inline void setPosition(const Vec3d& pos) { _position = pos; dirtyBound(); }
inline const Vec3d& getPosition() const { return _position; }
inline void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); }
inline const Quat& getAttitude() const { return _attitude; }
inline void setScale(const Vec3& scale) { _scale = scale; dirtyBound(); }
inline const Vec3& getScale() const { return _scale; }
inline void setScale(const Vec3d& scale) { _scale = scale; dirtyBound(); }
inline const Vec3d& getScale() const { return _scale; }
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; dirtyBound(); }
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; dirtyBound(); }
inline const Vec3d& getPivotPoint() const { return _pivotPoint; }
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
@@ -66,10 +67,10 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
virtual ~PositionAttitudeTransform() {}
Vec3 _position;
Vec3d _position;
Quat _attitude;
Vec3 _scale;
Vec3 _pivotPoint;
Vec3d _scale;
Vec3d _pivotPoint;
};
}

View File

@@ -15,8 +15,10 @@
#define OSG_QUAT 1
#include <osg/Export>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec3f>
#include <osg/Vec4f>
#include <osg/Vec3d>
#include <osg/Vec4d>
namespace osg {
@@ -43,7 +45,7 @@ class SG_EXPORT Quat
_v[3]=w;
}
inline Quat( const Vec4& v )
inline Quat( const Vec4f& v )
{
_v[0]=v.x();
_v[1]=v.y();
@@ -51,19 +53,38 @@ class SG_EXPORT Quat
_v[3]=v.w();
}
inline Quat( value_type angle, const Vec3& axis)
inline Quat( const Vec4d& v )
{
_v[0]=v.x();
_v[1]=v.y();
_v[2]=v.z();
_v[3]=v.w();
}
inline Quat( value_type angle, const Vec3f& axis)
{
makeRotate(angle,axis);
}
inline Quat( value_type angle, const Vec3d& axis)
{
makeRotate(angle,axis);
}
inline Quat( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3)
inline Quat( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3)
{
makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
}
inline bool operator == (const Quat& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }
inline Quat( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3)
{
makeRotate(angle1,axis1,angle2,axis2,angle3,axis3);
}
inline bool operator == (const Quat& 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 Quat& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2] || _v[3]!=v._v[3]; }
@@ -82,14 +103,14 @@ class SG_EXPORT Quat
Methods to access data members
---------------------------------- */
inline Vec4 asVec4() const
inline Vec4d asVec4() const
{
return Vec4(_v[0], _v[1], _v[2], _v[3]);
return Vec4d(_v[0], _v[1], _v[2], _v[3]);
}
inline Vec3 asVec3() const
inline Vec3d asVec3() const
{
return Vec3(_v[0], _v[1], _v[2]);
return Vec3d(_v[0], _v[1], _v[2]);
}
inline void set(value_type x, value_type y, value_type z, value_type w)
@@ -100,7 +121,15 @@ class SG_EXPORT Quat
_v[3]=w;
}
inline void set(const osg::Vec4& v)
inline void set(const osg::Vec4f& v)
{
_v[0]=v.x();
_v[1]=v.y();
_v[2]=v.z();
_v[3]=v.w();
}
inline void set(const osg::Vec4d& v)
{
_v[0]=v.x();
_v[1]=v.y();
@@ -215,7 +244,7 @@ class SG_EXPORT Quat
/// Binary addition
inline const Quat operator + (const Quat& rhs) const
{
return Vec4(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
return Quat(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
@@ -289,23 +318,37 @@ class SG_EXPORT Quat
-------------------------------------------------------- */
void makeRotate( value_type angle,
value_type x, value_type y, value_type z );
void makeRotate ( value_type angle, const Vec3& vec );
void makeRotate ( value_type angle, const Vec3f& vec );
void makeRotate ( value_type angle, const Vec3d& vec );
void makeRotate ( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3);
void makeRotate ( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3);
void makeRotate ( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3);
/** Make a rotation Quat which will rotate vec1 to vec2.
Generally take adot product to get the angle between these
and then use a cross product to get the rotation axis
Watch out for the two special cases of when the vectors
are co-incident or opposite in direction.*/
void makeRotate( const Vec3& vec1, const Vec3& vec2 );
void makeRotate( const Vec3f& vec1, const Vec3f& vec2 );
/** Make a rotation Quat which will rotate vec1 to vec2.
Generally take adot product to get the angle between these
and then use a cross product to get the rotation axis
Watch out for the two special cases of when the vectors
are co-incident or opposite in direction.*/
void makeRotate( const Vec3d& vec1, const Vec3d& vec2 );
/** Return the angle and vector components represented by the quaternion.*/
void getRotate ( value_type & angle, value_type & x, value_type & y, value_type & z ) const;
/** Return the angle and vector represented by the quaternion.*/
void getRotate ( value_type & angle, Vec3& vec ) const;
void getRotate ( value_type & angle, Vec3f& vec ) const;
/** Return the angle and vector represented by the quaternion.*/
void getRotate ( value_type & angle, Vec3d& vec ) const;
/** Spherical Linear Interpolation.
As t goes from 0 to 1, the Quat object goes from "from" to "to". */

View File

@@ -14,159 +14,12 @@
#ifndef OSG_VEC2
#define OSG_VEC2 1
#include <osg/Math>
#include <ostream>
#include <osg/Vec2f>
namespace osg {
/** General purpose float pair, uses include representation of
texture coordinates.
No support yet added for float * Vec2 - is it necessary?
Need to define a non-member non-friend operator* etc.
BTW: Vec2 * float is okay
*/
typedef Vec2f Vec2;
class Vec2
{
public:
}
Vec2() {_v[0]=0.0f; _v[1]=0.0f;}
Vec2(float x,float y) { _v[0]=x; _v[1]=y; }
float _v[2];
inline bool operator == (const Vec2& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline float* ptr() { return _v; }
inline const float* ptr() const { return _v; }
inline void set( float x, float y ) { _v[0]=x; _v[1]=y; }
inline float& operator [] (int i) { return _v[i]; }
inline float operator [] (int i) const { return _v[i]; }
inline float& x() { return _v[0]; }
inline float& y() { return _v[1]; }
inline float x() const { return _v[0]; }
inline float y() const { return _v[1]; }
inline bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
/// dot product
inline float operator * (const Vec2& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
}
/// multiply by scalar
inline const Vec2 operator * (float rhs) const
{
return Vec2(_v[0]*rhs, _v[1]*rhs);
}
/// unary multiply by scalar
inline Vec2& operator *= (float rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
return *this;
}
/// divide by scalar
inline const Vec2 operator / (float rhs) const
{
return Vec2(_v[0]/rhs, _v[1]/rhs);
}
/// unary divide by scalar
inline Vec2& operator /= (float rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
return *this;
}
/// binary vector add
inline const Vec2 operator + (const Vec2& rhs) const
{
return Vec2(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object.*/
inline Vec2& operator += (const Vec2& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
/// binary vector subtract
inline const Vec2 operator - (const Vec2& rhs) const
{
return Vec2(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/// unary vector subtract
inline Vec2& operator -= (const Vec2& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
/// negation operator. Returns the negative of the Vec2
inline const Vec2 operator - () const
{
return Vec2 (-_v[0], -_v[1]);
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] );
}
/// Length squared of the vector = vec . vec
inline float length2( void ) const
{
return _v[0]*_v[0] + _v[1]*_v[1];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline float normalize()
{
float norm = Vec2::length();
if (norm>0.0f)
{
float inv = 1.0f/norm;
_v[0] *= inv;
_v[1] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec2& vec)
{
output << vec._v[0] << " "
<< vec._v[1];
return output; // to enable cascading
}
}; // end of class Vec2
} // end of namespace osg
#endif

179
include/osg/Vec2d Normal file
View File

@@ -0,0 +1,179 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_VEC2D
#define OSG_VEC2D 1
#include <osg/Vec2f>
#include <ostream>
namespace osg {
/** General purpose float pair, uses include representation of
texture coordinates.
No support yet added for float * Vec2d - is it necessary?
Need to define a non-member non-friend operator* etc.
BTW: Vec2d * float is okay
*/
class Vec2d
{
public:
typedef float value_type;
value_type _v[2];
Vec2d() {_v[0]=0.0; _v[1]=0.0;}
Vec2d(float x,float y) { _v[0]=x; _v[1]=y; }
inline Vec2d(const Vec2f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]}
inline operator Vec3f() const { return Vec2f(_v[0],_v[1]);}
inline bool operator == (const Vec2d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2d& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2d& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline float* ptr() { return _v; }
inline const float* ptr() const { return _v; }
inline void set( float x, float y ) { _v[0]=x; _v[1]=y; }
inline float& operator [] (int i) { return _v[i]; }
inline float operator [] (int i) const { return _v[i]; }
inline float& x() { return _v[0]; }
inline float& y() { return _v[1]; }
inline float x() const { return _v[0]; }
inline float y() const { return _v[1]; }
inline bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
/// dot product
inline float operator * (const Vec2d& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
}
/// multiply by scalar
inline const Vec2d operator * (float rhs) const
{
return Vec2d(_v[0]*rhs, _v[1]*rhs);
}
/// unary multiply by scalar
inline Vec2d& operator *= (float rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
return *this;
}
/// divide by scalar
inline const Vec2d operator / (float rhs) const
{
return Vec2d(_v[0]/rhs, _v[1]/rhs);
}
/// unary divide by scalar
inline Vec2d& operator /= (float rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
return *this;
}
/// binary vector add
inline const Vec2d operator + (const Vec2d& rhs) const
{
return Vec2d(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object.*/
inline Vec2d& operator += (const Vec2d& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
/// binary vector subtract
inline const Vec2d operator - (const Vec2d& rhs) const
{
return Vec2d(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/// unary vector subtract
inline Vec2d& operator -= (const Vec2d& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
/// negation operator. Returns the negative of the Vec2d
inline const Vec2d operator - () const
{
return Vec2d (-_v[0], -_v[1]);
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] );
}
/// Length squared of the vector = vec . vec
inline float length2( void ) const
{
return _v[0]*_v[0] + _v[1]*_v[1];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline float normalize()
{
float norm = Vec2d::length();
if (norm>0.0)
{
float inv = 1.0/norm;
_v[0] *= inv;
_v[1] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec2d& vec)
{
output << vec._v[0] << " "
<< vec._v[1];
return output; // to enable cascading
}
}; // end of class Vec2d
} // end of namespace osg
#endif

174
include/osg/Vec2f Normal file
View File

@@ -0,0 +1,174 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_VEC2F
#define OSG_VEC2F 1
#include <osg/Math>
#include <ostream>
namespace osg {
/** General purpose float pair, uses include representation of
texture coordinates.
No support yet added for float * Vec2f - is it necessary?
Need to define a non-member non-friend operator* etc.
BTW: Vec2f * float is okay
*/
class Vec2f
{
public:
typedef float value_type;
value_type _v[2];
Vec2f() {_v[0]=0.0; _v[1]=0.0;}
Vec2f(float x,float y) { _v[0]=x; _v[1]=y; }
inline bool operator == (const Vec2f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
inline bool operator != (const Vec2f& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; }
inline bool operator < (const Vec2f& v) const
{
if (_v[0]<v._v[0]) return true;
else if (_v[0]>v._v[0]) return false;
else return (_v[1]<v._v[1]);
}
inline float* ptr() { return _v; }
inline const float* ptr() const { return _v; }
inline void set( float x, float y ) { _v[0]=x; _v[1]=y; }
inline float& operator [] (int i) { return _v[i]; }
inline float operator [] (int i) const { return _v[i]; }
inline float& x() { return _v[0]; }
inline float& y() { return _v[1]; }
inline float x() const { return _v[0]; }
inline float y() const { return _v[1]; }
inline bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
/// dot product
inline float operator * (const Vec2f& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
}
/// multiply by scalar
inline const Vec2f operator * (float rhs) const
{
return Vec2f(_v[0]*rhs, _v[1]*rhs);
}
/// unary multiply by scalar
inline Vec2f& operator *= (float rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
return *this;
}
/// divide by scalar
inline const Vec2f operator / (float rhs) const
{
return Vec2f(_v[0]/rhs, _v[1]/rhs);
}
/// unary divide by scalar
inline Vec2f& operator /= (float rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
return *this;
}
/// binary vector add
inline const Vec2f operator + (const Vec2f& rhs) const
{
return Vec2f(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object.*/
inline Vec2f& operator += (const Vec2f& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
return *this;
}
/// binary vector subtract
inline const Vec2f operator - (const Vec2f& rhs) const
{
return Vec2f(_v[0]-rhs._v[0], _v[1]-rhs._v[1]);
}
/// unary vector subtract
inline Vec2f& operator -= (const Vec2f& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
return *this;
}
/// negation operator. Returns the negative of the Vec2f
inline const Vec2f operator - () const
{
return Vec2f (-_v[0], -_v[1]);
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] );
}
/// Length squared of the vector = vec . vec
inline float length2( void ) const
{
return _v[0]*_v[0] + _v[1]*_v[1];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline float normalize()
{
float norm = Vec2f::length();
if (norm>0.0)
{
float inv = 1.0/norm;
_v[0] *= inv;
_v[1] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)
{
output << vec._v[0] << " "
<< vec._v[1];
return output; // to enable cascading
}
}; // end of class Vec2f
} // end of namespace osg
#endif

View File

@@ -14,191 +14,12 @@
#ifndef OSG_VEC3
#define OSG_VEC3 1
#include <osg/Math>
#include <ostream>
#include <osg/Vec3f>
namespace osg {
/** General purpose float triple for use as vertices, vectors and normals.
Provides general maths operations from addition through to cross products.
No support yet added for float * Vec3 - is it necessary?
Need to define a non-member non-friend operator* etc.
Vec3 * float is okay
*/
class Vec3
{
public:
typedef Vec3f Vec3;
Vec3() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f;}
Vec3(float x,float y,float z) { _v[0]=x; _v[1]=y; _v[2]=z; }
float _v[3];
inline bool operator == (const Vec3& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3& 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 float* ptr() { return _v; }
inline const float* ptr() const { return _v; }
inline void set( float x, float y, float z)
{
_v[0]=x; _v[1]=y; _v[2]=z;
}
inline void set( const Vec3& rhs)
{
_v[0]=rhs._v[0]; _v[1]=rhs._v[1]; _v[2]=rhs._v[2];
}
inline float& operator [] (int i) { return _v[i]; }
inline float operator [] (int i) const { return _v[i]; }
inline float& x() { return _v[0]; }
inline float& y() { return _v[1]; }
inline float& z() { return _v[2]; }
inline float x() const { return _v[0]; }
inline float y() const { return _v[1]; }
inline float 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]); }
/// dot product
inline float operator * (const Vec3& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1]+_v[2]*rhs._v[2];
}
/// cross product
inline const Vec3 operator ^ (const Vec3& rhs) const
{
return Vec3(_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]);
}
/// multiply by scalar
inline const Vec3 operator * (float rhs) const
{
return Vec3(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
/// unary multiply by scalar
inline Vec3& operator *= (float rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
return *this;
}
/// divide by scalar
inline const Vec3 operator / (float rhs) const
{
return Vec3(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
/// unary divide by scalar
inline Vec3& operator /= (float rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
return *this;
}
/// binary vector add
inline const Vec3 operator + (const Vec3& rhs) const
{
return Vec3(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object*/
inline Vec3& operator += (const Vec3& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/// binary vector subtract
inline const Vec3 operator - (const Vec3& rhs) const
{
return Vec3(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
/// unary vector subtract
inline Vec3& operator -= (const Vec3& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
/// negation operator. Returns the negative of the Vec3
inline const Vec3 operator - () const
{
return Vec3 (-_v[0], -_v[1], -_v[2]);
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
/// Length squared of the vector = vec . vec
inline float length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline float normalize()
{
float norm = Vec3::length();
if (norm>0.0f)
{
float inv = 1.0f/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec3& vec);
}; // end of class Vec3
inline std::ostream& operator << (std::ostream& output, const Vec3& vec)
{
output << vec._v[0] << " "
<< vec._v[1] << " "
<< vec._v[2];
return output; // to enable cascading
}
const Vec3 X_AXIS(1.0f,0.0f,0.0f);
const Vec3 Y_AXIS(0.0f,1.0f,0.0f);
const Vec3 Z_AXIS(0.0f,0.0f,1.0f);
} // end of namespace osg
#endif

207
include/osg/Vec3d Normal file
View File

@@ -0,0 +1,207 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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/Vec3f>
#include <ostream>
namespace osg {
/** General purpose float triple for use as vertices, vectors and normals.
Provides general maths operations from addition through to cross products.
No support yet added for float * Vec3d - is it necessary?
Need to define a non-member non-friend operator* etc.
Vec3d * float is okay
*/
class Vec3d
{
public:
typedef float value_type;
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(_v[0],_v[1],_v[2]);}
Vec3d(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; }
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]); }
/// dot product
inline value_type operator * (const Vec3d& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1]+_v[2]*rhs._v[2];
}
/// cross product
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]);
}
/// multiply by scalar
inline const Vec3d operator * (value_type rhs) const
{
return Vec3d(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
/// unary multiply by scalar
inline Vec3d& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
return *this;
}
/// divide by scalar
inline const Vec3d operator / (value_type rhs) const
{
return Vec3d(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
/// unary divide by scalar
inline Vec3d& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
return *this;
}
/// binary vector add
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]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object*/
inline Vec3d& operator += (const Vec3d& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/// binary vector subtract
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]);
}
/// unary vector subtract
inline Vec3d& operator -= (const Vec3d& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
/// negation operator. Returns the negative of the Vec3d
inline const Vec3d operator - () const
{
return Vec3d (-_v[0], -_v[1], -_v[2]);
}
/// Length of the vector = sqrt( vec . vec )
inline value_type length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
/// Length squared of the vector = vec . vec
inline value_type length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
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 );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec3d& vec);
}; // end of class Vec3d
inline std::ostream& operator << (std::ostream& output, const Vec3d& vec)
{
output << vec._v[0] << " "
<< vec._v[1] << " "
<< vec._v[2];
return output; // to enable cascading
}
} // end of namespace osg
#endif

206
include/osg/Vec3f Normal file
View File

@@ -0,0 +1,206 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_VEC3F
#define OSG_VEC3F 1
#include <osg/Math>
#include <ostream>
namespace osg {
/** General purpose float triple for use as vertices, vectors and normals.
Provides general maths operations from addition through to cross products.
No support yet added for float * Vec3f - is it necessary?
Need to define a non-member non-friend operator* etc.
Vec3f * float is okay
*/
class Vec3f
{
public:
typedef float value_type;
value_type _v[3];
Vec3f() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0;}
Vec3f(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; }
inline bool operator == (const Vec3f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2]; }
inline bool operator != (const Vec3f& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1] || _v[2]!=v._v[2]; }
inline bool operator < (const Vec3f& 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 Vec3f& 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]); }
/// dot product
inline value_type operator * (const Vec3f& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1]+_v[2]*rhs._v[2];
}
/// cross product
inline const Vec3f operator ^ (const Vec3f& rhs) const
{
return Vec3f(_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]);
}
/// multiply by scalar
inline const Vec3f operator * (value_type rhs) const
{
return Vec3f(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs);
}
/// unary multiply by scalar
inline Vec3f& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
return *this;
}
/// divide by scalar
inline const Vec3f operator / (value_type rhs) const
{
return Vec3f(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs);
}
/// unary divide by scalar
inline Vec3f& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
return *this;
}
/// binary vector add
inline const Vec3f operator + (const Vec3f& rhs) const
{
return Vec3f(_v[0]+rhs._v[0], _v[1]+rhs._v[1], _v[2]+rhs._v[2]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object*/
inline Vec3f& operator += (const Vec3f& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
return *this;
}
/// binary vector subtract
inline const Vec3f operator - (const Vec3f& rhs) const
{
return Vec3f(_v[0]-rhs._v[0], _v[1]-rhs._v[1], _v[2]-rhs._v[2]);
}
/// unary vector subtract
inline Vec3f& operator -= (const Vec3f& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
return *this;
}
/// negation operator. Returns the negative of the Vec3f
inline const Vec3f operator - () const
{
return Vec3f (-_v[0], -_v[1], -_v[2]);
}
/// Length of the vector = sqrt( vec . vec )
inline value_type length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] );
}
/// Length squared of the vector = vec . vec
inline value_type length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline value_type normalize()
{
value_type norm = Vec3f::length();
if (norm>0.0)
{
value_type inv = 1.0/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec3f& vec);
}; // end of class Vec3f
inline std::ostream& operator << (std::ostream& output, const Vec3f& vec)
{
output << vec._v[0] << " "
<< vec._v[1] << " "
<< vec._v[2];
return output; // to enable cascading
}
const Vec3f X_AXIS(1.0,0.0,0.0);
const Vec3f Y_AXIS(0.0,1.0,0.0);
const Vec3f Z_AXIS(0.0,0.0,1.0);
} // end of namespace osg
#endif

View File

@@ -14,234 +14,12 @@
#ifndef OSG_VEC4
#define OSG_VEC4 1
#include <osg/Vec3>
#include <ostream>
#include <osg/Vec4f>
namespace osg {
/** General purpose float quad, uses include representation
of colour coordinates.
No support yet added for float * Vec4 - is it necessary?
Need to define a non-member non-friend operator* etc.
Vec4 * float is okay
*/
class Vec4
{
public:
typedef Vec4f Vec4;
// Methods are defined here so that they are implicitly inlined
Vec4() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f; _v[3]=0.0f;}
Vec4(float x, float y, float z, float w)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
_v[3]=w;
}
Vec4(const Vec3& v3,float w)
{
_v[0]=v3[0];
_v[1]=v3[1];
_v[2]=v3[2];
_v[3]=w;
}
float _v[4];
inline bool operator == (const Vec4& 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 Vec4& 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 Vec4& 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 float* ptr() { return _v; }
inline const float* ptr() const { return _v; }
inline void set( float x, float y, float z, float w)
{
_v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w;
}
inline float& operator [] (unsigned int i) { return _v[i]; }
inline float operator [] (unsigned int i) const { return _v[i]; }
inline float& x() { return _v[0]; }
inline float& y() { return _v[1]; }
inline float& z() { return _v[2]; }
inline float& w() { return _v[3]; }
inline float x() const { return _v[0]; }
inline float y() const { return _v[1]; }
inline float z() const { return _v[2]; }
inline float w() const { return _v[3]; }
inline unsigned long asABGR() const
{
return (unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f)<<24 |
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<16 |
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<8 |
(unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f);
}
inline unsigned long asRGBA() const
{
return (unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f)<<24 |
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<16 |
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<8 |
(unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f);
}
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]); }
/// dot product
inline float operator * (const Vec4& rhs) const
{
return _v[0]*rhs._v[0]+
_v[1]*rhs._v[1]+
_v[2]*rhs._v[2]+
_v[3]*rhs._v[3] ;
}
/// multiply by scalar
inline Vec4 operator * (float rhs) const
{
return Vec4(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
/// unary multiply by scalar
inline Vec4& operator *= (float rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
_v[3]*=rhs;
return *this;
}
/// divide by scalar
inline Vec4 operator / (float rhs) const
{
return Vec4(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
/// unary divide by scalar
inline Vec4& operator /= (float rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
_v[3]/=rhs;
return *this;
}
/// binary vector add
inline Vec4 operator + (const Vec4& rhs) const
{
return Vec4(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object*/
inline Vec4& operator += (const Vec4& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
_v[3] += rhs._v[3];
return *this;
}
/// binary vector subtract
inline Vec4 operator - (const Vec4& rhs) const
{
return Vec4(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
}
/// unary vector subtract
inline Vec4& operator -= (const Vec4& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
_v[3]-=rhs._v[3];
return *this;
}
/// negation operator. Returns the negative of the Vec4
inline const Vec4 operator - () const
{
return Vec4 (-_v[0], -_v[1], -_v[2], -_v[3]);
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3]);
}
/// Length squared of the vector = vec . vec
inline float length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline float normalize()
{
float norm = Vec4::length();
if (norm>0.0f)
{
float inv = 1.0f/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
_v[3] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec4& vec)
{
output << vec._v[0] << " "
<< vec._v[1] << " "
<< vec._v[2] << " "
<< vec._v[3];
return output; // to enable cascading
}
}; // end of class Vec4
/** Compute the dot product of a (Vec3,1.0) and a Vec4.*/
inline float operator * (const Vec3& lhs,const Vec4& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3];
}
/** Compute the dot product of a Vec4 and a (Vec3,1.0).*/
inline float operator * (const Vec4& lhs,const Vec3& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
}
} // end of namespace osg
#endif

252
include/osg/Vec4d Normal file
View File

@@ -0,0 +1,252 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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 {
/** General purpose float quad, uses include representation
of colour coordinates.
No support yet added for float * Vec4d - is it necessary?
Need to define a non-member non-friend operator* etc.
Vec4d * float is okay
*/
class Vec4d
{
public:
typedef float value_type;
value_type _v[4];
// Methods are defined here so that they are implicitly inlined
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(_v[0],_v[1],_v[2],_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 unsigned long asABGR() const
{
return (unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f)<<24 |
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<16 |
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<8 |
(unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f);
}
inline unsigned long asRGBA() const
{
return (unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f)<<24 |
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<16 |
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<8 |
(unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f);
}
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]); }
/// dot product
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] ;
}
/// multiply by scalar
inline Vec4d operator * (value_type rhs) const
{
return Vec4d(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
/// unary multiply by scalar
inline Vec4d& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
_v[3]*=rhs;
return *this;
}
/// divide by scalar
inline Vec4d operator / (value_type rhs) const
{
return Vec4d(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
/// unary divide by scalar
inline Vec4d& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
_v[3]/=rhs;
return *this;
}
/// binary vector add
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]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object*/
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;
}
/// binary vector subtract
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] );
}
/// unary vector subtract
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;
}
/// negation operator. Returns the negative of the Vec4d
inline const Vec4d operator - () const
{
return Vec4d (-_v[0], -_v[1], -_v[2], -_v[3]);
}
/// Length of the vector = sqrt( vec . vec )
inline value_type length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3]);
}
/// Length squared of the vector = vec . vec
inline value_type length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline value_type normalize()
{
value_type norm = Vec4d::length();
if (norm>0.0f)
{
value_type inv = 1.0f/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
_v[3] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec4d& vec)
{
output << vec._v[0] << " "
<< vec._v[1] << " "
<< vec._v[2] << " "
<< vec._v[3];
return output; // to enable cascading
}
}; // end of class Vec4d
/** Compute the dot product of a (Vec3,1.0) and a 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];
}
/** Compute the dot product of a Vec4d and a (Vec3,1.0).*/
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];
}
} // end of namespace osg
#endif

248
include/osg/Vec4f Normal file
View File

@@ -0,0 +1,248 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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_VEC4F
#define OSG_VEC4F 1
#include <osg/Vec3f>
#include <ostream>
namespace osg {
/** General purpose float quad, uses include representation
of colour coordinates.
No support yet added for float * Vec4f - is it necessary?
Need to define a non-member non-friend operator* etc.
Vec4f * float is okay
*/
class Vec4f
{
public:
typedef float value_type;
value_type _v[4];
// Methods are defined here so that they are implicitly inlined
Vec4f() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=0.0;}
Vec4f(value_type x, value_type y, value_type z, value_type w)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
_v[3]=w;
}
Vec4f(const Vec3f& v3,value_type w)
{
_v[0]=v3[0];
_v[1]=v3[1];
_v[2]=v3[2];
_v[3]=w;
}
inline bool operator == (const Vec4f& 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 Vec4f& 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 Vec4f& 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 unsigned long asABGR() const
{
return (unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f)<<24 |
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<16 |
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<8 |
(unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f);
}
inline unsigned long asRGBA() const
{
return (unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f)<<24 |
(unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<16 |
(unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<8 |
(unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f);
}
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]); }
/// dot product
inline value_type operator * (const Vec4f& rhs) const
{
return _v[0]*rhs._v[0]+
_v[1]*rhs._v[1]+
_v[2]*rhs._v[2]+
_v[3]*rhs._v[3] ;
}
/// multiply by scalar
inline Vec4f operator * (value_type rhs) const
{
return Vec4f(_v[0]*rhs, _v[1]*rhs, _v[2]*rhs, _v[3]*rhs);
}
/// unary multiply by scalar
inline Vec4f& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
_v[2]*=rhs;
_v[3]*=rhs;
return *this;
}
/// divide by scalar
inline Vec4f operator / (value_type rhs) const
{
return Vec4f(_v[0]/rhs, _v[1]/rhs, _v[2]/rhs, _v[3]/rhs);
}
/// unary divide by scalar
inline Vec4f& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
_v[2]/=rhs;
_v[3]/=rhs;
return *this;
}
/// binary vector add
inline Vec4f operator + (const Vec4f& rhs) const
{
return Vec4f(_v[0]+rhs._v[0], _v[1]+rhs._v[1],
_v[2]+rhs._v[2], _v[3]+rhs._v[3]);
}
/** unary vector add. Slightly more efficient because no temporary
intermediate object*/
inline Vec4f& operator += (const Vec4f& rhs)
{
_v[0] += rhs._v[0];
_v[1] += rhs._v[1];
_v[2] += rhs._v[2];
_v[3] += rhs._v[3];
return *this;
}
/// binary vector subtract
inline Vec4f operator - (const Vec4f& rhs) const
{
return Vec4f(_v[0]-rhs._v[0], _v[1]-rhs._v[1],
_v[2]-rhs._v[2], _v[3]-rhs._v[3] );
}
/// unary vector subtract
inline Vec4f& operator -= (const Vec4f& rhs)
{
_v[0]-=rhs._v[0];
_v[1]-=rhs._v[1];
_v[2]-=rhs._v[2];
_v[3]-=rhs._v[3];
return *this;
}
/// negation operator. Returns the negative of the Vec4f
inline const Vec4f operator - () const
{
return Vec4f (-_v[0], -_v[1], -_v[2], -_v[3]);
}
/// Length of the vector = sqrt( vec . vec )
inline value_type length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3]);
}
/// Length squared of the vector = vec . vec
inline value_type length2() const
{
return _v[0]*_v[0] + _v[1]*_v[1] + _v[2]*_v[2] + _v[3]*_v[3];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline value_type normalize()
{
value_type norm = Vec4f::length();
if (norm>0.0f)
{
value_type inv = 1.0f/norm;
_v[0] *= inv;
_v[1] *= inv;
_v[2] *= inv;
_v[3] *= inv;
}
return( norm );
}
friend inline std::ostream& operator << (std::ostream& output, const Vec4f& vec)
{
output << vec._v[0] << " "
<< vec._v[1] << " "
<< vec._v[2] << " "
<< vec._v[3];
return output; // to enable cascading
}
}; // end of class Vec4f
/** Compute the dot product of a (Vec3,1.0) and a Vec4f.*/
inline Vec4f::value_type operator * (const Vec3f& lhs,const Vec4f& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+rhs[3];
}
/** Compute the dot product of a Vec4f and a (Vec3,1.0).*/
inline Vec4f::value_type operator * (const Vec4f& lhs,const Vec3f& rhs)
{
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
}
} // end of namespace osg
#endif

View File

@@ -14,9 +14,9 @@
#ifndef OSGDB_FIELDREADERITERATOR
#define OSGDB_FIELDREADERITERATOR 1
#include <osg/Vec2>
#include <osg/Vec2>
#include <osg/Vec4>
#include <osg/Vec2f>
#include <osg/Vec2f>
#include <osg/Vec4f>
#include <osgDB/Field>
#include <osgDB/FieldReader>
@@ -66,17 +66,17 @@ class OSGDB_EXPORT FieldReaderIterator
bool readSequence(const char* keyword,unsigned int& value);
bool readSequence(const char* keyword,int& value);
bool readSequence(const char* keyword,float& value);
bool readSequence(const char* keyword,osg::Vec2& value);
bool readSequence(const char* keyword,osg::Vec3& value);
bool readSequence(const char* keyword,osg::Vec4& value);
bool readSequence(const char* keyword,osg::Vec2f& value);
bool readSequence(const char* keyword,osg::Vec3f& value);
bool readSequence(const char* keyword,osg::Vec4f& value);
bool readSequence(std::string& value);
bool readSequence(unsigned int& value);
bool readSequence(int& value);
bool readSequence(float& value);
bool readSequence(osg::Vec2& value);
bool readSequence(osg::Vec3& value);
bool readSequence(osg::Vec4& value);
bool readSequence(osg::Vec2f& value);
bool readSequence(osg::Vec3f& value);
bool readSequence(osg::Vec4f& value);
private:

View File

@@ -71,7 +71,7 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/
@@ -83,10 +83,10 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _velocity;
float _height;
float _buffer;
double _modelScale;
double _velocity;
double _height;
double _buffer;
enum SpeedControlMode {
USE_MOUSE_Y_FOR_SPEED,
@@ -95,9 +95,9 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator
SpeedControlMode _speedMode;
osg::Vec3 _eye;
osg::Quat _rotation;
float _distance;
osg::Vec3d _eye;
osg::Quat _rotation;
double _distance;
};
}

View File

@@ -92,14 +92,14 @@ class OSGGA_EXPORT FlightManipulator : public MatrixManipulator
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _velocity;
double _modelScale;
double _velocity;
YawControlMode _yawMode;
osg::Vec3 _eye;
osg::Vec3d _eye;
osg::Quat _rotation;
float _distance;
double _distance;
};

View File

@@ -45,7 +45,7 @@ public:
class CoordinateFrameCallback : public osg::Referenced
{
public:
virtual osg::CoordinateFrame getCoordinateFrame(double X, double Y, double Z) const = 0;
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0;
protected:
virtual ~CoordinateFrameCallback() {}
};
@@ -60,15 +60,15 @@ public:
const CoordinateFrameCallback* getCoordinateFrameCallback() const { return _coordinateFrameCallback.get(); }
/** get the coordinate frame.*/
osg::CoordinateFrame getCoordinateFrame(double X, double Y, double Z) const
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const
{
if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(X,Y,Z);
if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position);
return osg::CoordinateFrame();
}
osg::Vec3 getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(0,0),cf(0,1),cf(0,2)); }
osg::Vec3 getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(1,0),cf(1,1),cf(1,2)); }
osg::Vec3 getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3(cf(2,0),cf(2,1),cf(2,2)); }
osg::Vec3d getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(0,0),cf(0,1),cf(0,2)); }
osg::Vec3d getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(1,0),cf(1,1),cf(1,2)); }
osg::Vec3d getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(2,0),cf(2,1),cf(2,2)); }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrixd& matrix) = 0;

View File

@@ -98,14 +98,14 @@ class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/
bool calcMovement();
void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
float tb_project_to_sphere(float r, float x, float y);
void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y);
double tb_project_to_sphere(double r, double x, double y);
/** Check the speed at which the mouse is moving.
@@ -122,14 +122,14 @@ class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator
osg::ref_ptr<osg::Node> _node;
float _modelScale;
double _modelScale;
RotationMode _rotationMode;
float _minimumZoomScale;
double _minimumZoomScale;
bool _thrown;
double _center[3];
osg::Vec3d _center;
osg::Quat _rotation;
float _distance;

View File

@@ -106,14 +106,14 @@ class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator
osg::ref_ptr<osg::Node> _node;
float _modelScale;
float _minimumZoomScale;
double _modelScale;
double _minimumZoomScale;
bool _thrown;
osg::Vec3 _center;
osg::Quat _rotation;
float _distance;
osg::Vec3d _center;
osg::Quat _rotation;
double _distance;
};