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

@ -911,6 +911,30 @@ SOURCE=..\..\Include\Osg\Vec4
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec2f
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec3f
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec4f
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec2d
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec3d
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Vec4d
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Version
# End Source File
# Begin Source File

View File

@ -2,12 +2,47 @@
#include <osg/Group>
#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Texture2D>
#include <osg/PositionAttitudeTransform>
#include <osgDB/ReadFile>
#include <osgParticle/ExplosionEffect>
#include <osgParticle/SmokeEffect>
#include <osgParticle/FireEffect>
#include <osgParticle/ParticleSystemUpdater>
// for the grid data..
#include "../osghangglide/terrain_coords.h"
osg::Vec3 computeTerrainIntersection(osg::Node* subgraph,float x,float y)
{
osgUtil::IntersectVisitor iv;
osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;
const osg::BoundingSphere& bs = subgraph->getBound();
float zMax = bs.center().z()+bs.radius();
float zMin = bs.center().z()-bs.radius();
segDown->set(osg::Vec3(x,y,zMin),osg::Vec3(x,y,zMax));
iv.addLineSegment(segDown.get());
subgraph->accept(iv);
if (iv.hits())
{
osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get());
if (!hitList.empty())
{
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
return ip;
}
}
return osg::Vec3(x,y,0.0f);
}
//////////////////////////////////////////////////////////////////////////////
// MAIN SCENE GRAPH BUILDING FUNCTION
@ -16,13 +51,57 @@
void build_world(osg::Group *root)
{
osg::Geode* terrainGeode = new osg::Geode;
{
osg::StateSet* stateset = new osg::StateSet();
osg::Image* image = osgDB::readImageFile("Images/lz.rgb");
if (image)
{
osg::Texture2D* texture = new osg::Texture2D;
texture->setImage(image);
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
}
terrainGeode->setStateSet( stateset );
float size = 1000; // 10km;
float scale = size/39.0f; // 10km;
float z_scale = scale*3.0f;
osg::HeightField* grid = new osg::HeightField;
grid->allocateGrid(38,39);
grid->setXInterval(scale);
grid->setYInterval(scale);
for(unsigned int r=0;r<39;++r)
{
for(unsigned int c=0;c<38;++c)
{
grid->setHeight(c,r,z_scale*vertex[r+c*39][2]);
}
}
terrainGeode->addDrawable(new osg::ShapeDrawable(grid));
root->addChild(terrainGeode);
}
osg::PositionAttitudeTransform* positionEffects = new osg::PositionAttitudeTransform;
positionEffects->setPosition(computeTerrainIntersection(terrainGeode,100.0f,100.0f));
root->addChild(positionEffects);
osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect;
osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect;
osgParticle::FireEffect* fire = new osgParticle::FireEffect;
root->addChild(explosion);
root->addChild(smoke);
root->addChild(fire);
osg::Geode* geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),10.0f)));
positionEffects->addChild(geode);
positionEffects->addChild(explosion);
positionEffects->addChild(smoke);
positionEffects->addChild(fire);
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;

View File

@ -2,6 +2,7 @@
#include <osg/ArgumentParser>
#include <osg/ApplicationUsage>
#include <osg/Vec3>
#include <osg/Matrix>
#include <iostream>

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;
};

View File

@ -111,7 +111,7 @@ class AnimationPathCallbackVisitor : public NodeVisitor
{
public:
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, const osg::Vec3& pivotPoint, bool useInverseMatrix):
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, const osg::Vec3d& pivotPoint, bool useInverseMatrix):
_cp(cp),
_pivotPoint(pivotPoint),
_useInverseMatrix(useInverseMatrix) {}
@ -149,7 +149,7 @@ class AnimationPathCallbackVisitor : public NodeVisitor
}
AnimationPath::ControlPoint _cp;
osg::Vec3 _pivotPoint;
osg::Vec3d _pivotPoint;
bool _useInverseMatrix;
};

View File

@ -32,41 +32,31 @@ CoordinateSystemNode::CoordinateSystemNode(const CoordinateSystemNode& csn,const
_ellipsoidModel = csn._ellipsoidModel;
}
CoordinateFrame CoordinateSystemNode::computeLocalCoordinateFrame(const Vec3& position) const
{
return computeLocalCoordinateFrame(position.x(), position.y(), position.z());
}
CoordinateFrame CoordinateSystemNode::computeLocalCoordinateFrame(double X, double Y, double Z) const
CoordinateFrame CoordinateSystemNode::computeLocalCoordinateFrame(const Vec3d& position) const
{
if (_ellipsoidModel.valid())
{
Matrixd localToWorld;
_ellipsoidModel->computeLocalToWorldTransformFromXYZ(X,Y,Z, localToWorld);
_ellipsoidModel->computeLocalToWorldTransformFromXYZ(position.x(),position.y(),position.z(), localToWorld);
return localToWorld;
}
else
{
return Matrixd::translate(X,Y,Z);
return Matrixd::translate(position);
}
}
osg::Vec3 CoordinateSystemNode::computeLocalUpVector(const Vec3& position) const
{
return computeLocalUpVector(position.x(), position.y(), position.z());
}
osg::Vec3 CoordinateSystemNode::computeLocalUpVector(double X, double Y, double Z) const
osg::Vec3d CoordinateSystemNode::computeLocalUpVector(const Vec3d& position) const
{
if (_ellipsoidModel.valid())
{
return _ellipsoidModel->computeLocalUpVector(X,Y,Z);
return _ellipsoidModel->computeLocalUpVector(position.x(),position.y(),position.z());
}
else
{
return osg::Vec3(0.0f,0.0f,1.0f);
return osg::Vec3d(0.0f,0.0f,1.0f);
}
}

View File

@ -214,7 +214,7 @@ void CullStack::pushModelViewMatrix(RefMatrix* matrix)
pushCullingSet();
#if 1
osg::Vec3 slow_eyepoint(osg::Matrix::inverse(*matrix).getTrans());
osg::Vec3f slow_eyepoint = osg::Matrix::inverse(*matrix).getTrans();
_eyePointStack.push_back(slow_eyepoint);
#else

View File

@ -175,7 +175,13 @@ void Matrix_implementation::setTrans( value_type tx, value_type ty, value_type t
}
void Matrix_implementation::setTrans( const Vec3& v )
void Matrix_implementation::setTrans( const Vec3f& v )
{
_mat[3][0] = v[0];
_mat[3][1] = v[1];
_mat[3][2] = v[2];
}
void Matrix_implementation::setTrans( const Vec3d& v )
{
_mat[3][0] = v[0];
_mat[3][1] = v[1];
@ -190,7 +196,12 @@ void Matrix_implementation::makeIdentity()
SET_ROW(3, 0, 0, 0, 1 )
}
void Matrix_implementation::makeScale( const Vec3& v )
void Matrix_implementation::makeScale( const Vec3f& v )
{
makeScale(v[0], v[1], v[2] );
}
void Matrix_implementation::makeScale( const Vec3d& v )
{
makeScale(v[0], v[1], v[2] );
}
@ -203,7 +214,12 @@ void Matrix_implementation::makeScale( value_type x, value_type y, value_type z
SET_ROW(3, 0, 0, 0, 1 )
}
void Matrix_implementation::makeTranslate( const Vec3& v )
void Matrix_implementation::makeTranslate( const Vec3f& v )
{
makeTranslate( v[0], v[1], v[2] );
}
void Matrix_implementation::makeTranslate( const Vec3d& v )
{
makeTranslate( v[0], v[1], v[2] );
}
@ -216,14 +232,26 @@ void Matrix_implementation::makeTranslate( value_type x, value_type y, value_typ
SET_ROW(3, x, y, z, 1 )
}
void Matrix_implementation::makeRotate( const Vec3& from, const Vec3& to )
void Matrix_implementation::makeRotate( const Vec3f& from, const Vec3f& to )
{
Quat quat;
quat.makeRotate(from,to);
set(quat);
}
void Matrix_implementation::makeRotate( const Vec3d& from, const Vec3d& to )
{
Quat quat;
quat.makeRotate(from,to);
set(quat);
}
void Matrix_implementation::makeRotate( value_type angle, const Vec3& axis )
void Matrix_implementation::makeRotate( value_type angle, const Vec3f& axis )
{
Quat quat;
quat.makeRotate( angle, axis);
set(quat);
}
void Matrix_implementation::makeRotate( value_type angle, const Vec3d& axis )
{
Quat quat;
quat.makeRotate( angle, axis);
@ -242,9 +270,20 @@ void Matrix_implementation::makeRotate( const Quat& quat )
set(quat);
}
void Matrix_implementation::makeRotate( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3)
void Matrix_implementation::makeRotate( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3)
{
Quat quat;
quat.makeRotate(angle1, axis1,
angle2, axis2,
angle3, axis3);
set(quat);
}
void Matrix_implementation::makeRotate( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3)
{
Quat quat;
quat.makeRotate(angle1, axis1,
@ -688,13 +727,13 @@ bool Matrix_implementation::getPerspective(double& fovy,double& aspectRatio,
return false;
}
void Matrix_implementation::makeLookAt(const Vec3& eye,const Vec3& center,const Vec3& up)
void Matrix_implementation::makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up)
{
Vec3 f(center-eye);
Vec3d f(center-eye);
f.normalize();
Vec3 s(f^up);
Vec3d s(f^up);
s.normalize();
Vec3 u(s^f);
Vec3d u(s^f);
u.normalize();
set(
@ -706,13 +745,25 @@ void Matrix_implementation::makeLookAt(const Vec3& eye,const Vec3& center,const
preMult(Matrix_implementation::translate(-eye));
}
void Matrix_implementation::getLookAt(Vec3& eye,Vec3& center,Vec3& up,value_type lookDistance) const
void Matrix_implementation::getLookAt(Vec3f& eye,Vec3f& center,Vec3f& up,value_type lookDistance) const
{
Matrix_implementation inv;
inv.invert(*this);
eye = osg::Vec3(0.0,0.0,0.0)*inv;
up = transform3x3(*this,osg::Vec3(0.0,1.0,0.0));
center = transform3x3(*this,osg::Vec3(0.0,0.0,-1));
eye = osg::Vec3f(0.0,0.0,0.0)*inv;
up = transform3x3(*this,osg::Vec3f(0.0,1.0,0.0));
center = transform3x3(*this,osg::Vec3f(0.0,0.0,-1));
center.normalize();
center = eye + center*lookDistance;
}
void Matrix_implementation::getLookAt(Vec3d& eye,Vec3d& center,Vec3d& up,value_type lookDistance) const
{
Matrix_implementation inv;
inv.invert(*this);
eye = osg::Vec3d(0.0,0.0,0.0)*inv;
up = transform3x3(*this,osg::Vec3d(0.0,1.0,0.0));
center = transform3x3(*this,osg::Vec3d(0.0,0.0,-1));
center.normalize();
center = eye + center*lookDistance;
}

View File

@ -12,8 +12,6 @@
*/
#include <stdio.h>
#include <osg/Quat>
#include <osg/Vec4>
#include <osg/Vec3>
#include <osg/Matrixf>
#include <osg/Matrixd>
@ -62,15 +60,28 @@ void Quat::makeRotate( value_type angle, value_type x, value_type y, value_type
}
void Quat::makeRotate( value_type angle, const Vec3& vec )
void Quat::makeRotate( value_type angle, const Vec3f& vec )
{
makeRotate( angle, vec[0], vec[1], vec[2] );
}
void Quat::makeRotate( value_type angle, const Vec3d& vec )
{
makeRotate( angle, vec[0], vec[1], vec[2] );
}
void Quat::makeRotate ( value_type angle1, const Vec3& axis1,
value_type angle2, const Vec3& axis2,
value_type angle3, const Vec3& axis3)
void Quat::makeRotate ( value_type angle1, const Vec3f& axis1,
value_type angle2, const Vec3f& axis2,
value_type angle3, const Vec3f& axis3)
{
makeRotate(angle1,Vec3d(axis1),
angle2,Vec3d(axis2),
angle3,Vec3d(axis3));
}
void Quat::makeRotate ( value_type angle1, const Vec3d& axis1,
value_type angle2, const Vec3d& axis2,
value_type angle3, const Vec3d& axis3)
{
Quat q1; q1.makeRotate(angle1,axis1);
Quat q2; q2.makeRotate(angle2,axis2);
@ -79,12 +90,18 @@ void Quat::makeRotate ( value_type angle1, const Vec3& axis1,
*this = q1*q2*q3;
}
void Quat::makeRotate( const Vec3f& from, const Vec3f& to )
{
makeRotate( Vec3d(from), Vec3d(to) );
}
// 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 Quat::makeRotate( const Vec3& from, const Vec3& to )
void Quat::makeRotate( const Vec3d& from, const Vec3d& to )
{
const value_type epsilon = 0.00001;
@ -106,15 +123,17 @@ void Quat::makeRotate( const Vec3& from, const Vec3& to )
{
// vectors are close to being opposite, so will need to find a
// vector orthongonal to from to rotate about.
osg::Vec3 tmp;
Vec3d tmp;
if (fabs(from.x())<fabs(from.y()))
if (fabs(from.x())<fabs(from.z())) tmp.set(1.0,0.0,0.0); // use x axis.
else tmp.set(0.0,0.0,1.0);
else if (fabs(from.y())<fabs(from.z())) tmp.set(0.0,1.0,0.0);
else tmp.set(0.0,0.0,1.0);
Vec3d fromd(from.x(),from.y(),from.z());
// find orthogonal axis.
Vec3 axis(from^tmp);
Vec3d axis(fromd^tmp);
axis.normalize();
_v[0] = axis[0]; // sin of half angle of PI is 1.0.
@ -127,14 +146,22 @@ void Quat::makeRotate( const Vec3& from, const Vec3& to )
{
// This is the usual situation - take a cross-product of vec1 and vec2
// and that is the axis around which to rotate.
Vec3 axis(from^to);
Vec3d axis(from^to);
value_type angle = acos( cosangle );
makeRotate( angle, axis );
}
}
void Quat::getRotate( value_type& angle, Vec3& vec ) const
void Quat::getRotate( value_type& angle, Vec3f& vec ) const
{
value_type x,y,z;
getRotate(angle,x,y,z);
vec[0]=x;
vec[1]=y;
vec[2]=z;
}
void Quat::getRotate( value_type& angle, Vec3d& vec ) const
{
value_type x,y,z;
getRotate(angle,x,y,z);

View File

@ -1,5 +1,6 @@
#include <osgDB/DatabasePager>
#include <osgDB/ReadFile>
#include <osg/Geode>
#include <osg/Timer>
#include <osg/Texture>

View File

@ -433,7 +433,7 @@ bool FieldReaderIterator::readSequence(const char* keyword,float& value)
return false;
}
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2& value)
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2f& value)
{
if ((*this)[0].matchWord(keyword) &&
(*this)[1].getFloat(value[0]) &&
@ -445,7 +445,7 @@ bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2& value)
return false;
}
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3& value)
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3f& value)
{
if ((*this)[0].matchWord(keyword) &&
(*this)[1].getFloat(value[0]) &&
@ -458,7 +458,7 @@ bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3& value)
return false;
}
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec4& value)
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec4f& value)
{
if ((*this)[0].matchWord(keyword) &&
(*this)[1].getFloat(value[0]) &&
@ -513,7 +513,7 @@ bool FieldReaderIterator::readSequence(float& value)
return false;
}
bool FieldReaderIterator::readSequence(osg::Vec2& value)
bool FieldReaderIterator::readSequence(osg::Vec2f& value)
{
if ((*this)[0].getFloat(value[0]) &&
(*this)[1].getFloat(value[1]))
@ -524,7 +524,7 @@ bool FieldReaderIterator::readSequence(osg::Vec2& value)
return false;
}
bool FieldReaderIterator::readSequence(osg::Vec3& value)
bool FieldReaderIterator::readSequence(osg::Vec3f& value)
{
if ((*this)[0].getFloat(value[0]) &&
(*this)[1].getFloat(value[1]) &&
@ -536,7 +536,7 @@ bool FieldReaderIterator::readSequence(osg::Vec3& value)
return false;
}
bool FieldReaderIterator::readSequence(osg::Vec4& value)
bool FieldReaderIterator::readSequence(osg::Vec4f& value)
{
if ((*this)[0].getFloat(value[0]) &&
(*this)[1].getFloat(value[1]) &&

View File

@ -74,12 +74,12 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
const osg::BoundingSphere& boundingSphere=_node->getBound();
osg::Vec3 ep = boundingSphere._center;
osg::Vec3 bp = ep;
osg::Vec3d ep = boundingSphere._center;
osg::Vec3d bp = ep;
osg::CoordinateFrame cf=getCoordinateFrame(ep.x(), ep.y(), ep.z());
osg::CoordinateFrame cf=getCoordinateFrame(ep);
ep -= getUpVector(cf)* _modelScale*0.0001f;
ep -= getUpVector(cf)* _modelScale*0.0001;
bp -= getUpVector(cf)* _modelScale;
// check to see if any obstruction in front.
@ -99,16 +99,16 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (!hitList.empty())
{
// notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3 np = hitList.front().getWorldIntersectNormal();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d np = hitList.front().getWorldIntersectNormal();
osg::Vec3 uv;
if (np * getUpVector(cf)>0.0f) uv = np;
osg::Vec3d uv;
if (np * getUpVector(cf)>0.0) uv = np;
else uv = -np;
ep = ip;
ep += getUpVector(cf)*_height;
osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f);
osg::Vec3 lv = uv^osg::Vec3d(1.0,0.0,0.0);
computePosition(ep,lv,uv);
@ -135,16 +135,16 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (!hitList.empty())
{
// notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3 np = hitList.front().getWorldIntersectNormal();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d np = hitList.front().getWorldIntersectNormal();
osg::Vec3 uv;
if (np*getUpVector(cf)>0.0f) uv = np;
osg::Vec3d uv;
if (np*getUpVector(cf)>0.0) uv = np;
else uv = -np;
ep = ip;
ep += getUpVector(cf)*_height;
osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f);
osg::Vec3 lv = uv^osg::Vec3d(1.0,0.0,0.0);
computePosition(ep,lv,uv);
positionSet = true;
@ -157,14 +157,14 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (!positionSet)
{
computePosition(
boundingSphere._center+osg::Vec3( 0.0,-2.0f * boundingSphere._radius,0.0f),
osg::Vec3(0.0f,1.0f,0.0f),
osg::Vec3(0.0f,0.0f,1.0f));
boundingSphere._center+osg::Vec3d( 0.0,-2.0 * boundingSphere._radius,0.0),
osg::Vec3d(0.0,1.0,0.0),
osg::Vec3d(0.0,0.0,1.0));
}
}
_velocity = 0.0f;
_velocity = 0.0;
us.requestRedraw();
@ -181,14 +181,14 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
_velocity = 0.0f;
osg::Vec3 ep = _eye;
osg::Vec3d ep = _eye;
osg::CoordinateFrame cf=getCoordinateFrame(ep.x(), ep.y(), ep.z());
osg::CoordinateFrame cf=getCoordinateFrame(ep);
Matrixd rotation_matrix;
rotation_matrix.set(_rotation);
osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix;
osg::Vec3 bp = ep;
osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix;
osg::Vec3d bp = ep;
bp -= getUpVector(cf)*_modelScale;
// check to see if any obstruction in front.
@ -208,15 +208,15 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (!hitList.empty())
{
// notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3 np = hitList.front().getWorldIntersectNormal();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d np = hitList.front().getWorldIntersectNormal();
osg::Vec3 uv;
if (np*getUpVector(cf)>0.0f) uv = np;
osg::Vec3d uv;
if (np*getUpVector(cf)>0.0) uv = np;
else uv = -np;
ep = ip+uv*_height;
osg::Vec3 lv = uv^sv;
osg::Vec3d lv = uv^sv;
computePosition(ep,lv,uv);
@ -386,19 +386,19 @@ osg::Matrixd DriveManipulator::getInverseMatrix() const
return osg::Matrixd::translate(-_eye)*osg::Matrixd::rotate(_rotation.inverse());
}
void DriveManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
void DriveManipulator::computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up)
{
osg::Vec3 f(lv);
osg::Vec3d f(lv);
f.normalize();
osg::Vec3 s(f^up);
osg::Vec3d s(f^up);
s.normalize();
osg::Vec3 u(s^f);
osg::Vec3d u(s^f);
u.normalize();
osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0f,
s[1], u[1], -f[1], 0.0f,
s[2], u[2], -f[2], 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0,
s[1], u[1], -f[1], 0.0,
s[2], u[2], -f[2], 0.0,
0.0, 0.0, 0.0, 1.0);
_eye = eye;
rotation_matrix.get(_rotation);
@ -423,7 +423,7 @@ bool DriveManipulator::calcMovement()
{
case(USE_MOUSE_Y_FOR_SPEED):
{
float dy = _ga_t0->getYnormalized();
double dy = _ga_t0->getYnormalized();
_velocity = _modelScale*0.2f*dy;
break;
}
@ -434,53 +434,53 @@ bool DriveManipulator::calcMovement()
{
// pan model.
_velocity += dt*_modelScale*0.02f;
_velocity += dt*_modelScale*0.02;
}
else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON))
{
_velocity = 0.0f;
_velocity = 0.0;
}
else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON)
{
_velocity -= dt*_modelScale*0.02f;
_velocity -= dt*_modelScale*0.02;
}
break;
}
}
osg::CoordinateFrame cf=getCoordinateFrame(_eye.x(), _eye.y(), _eye.z());
osg::CoordinateFrame cf=getCoordinateFrame(_eye);
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix;
osg::Vec3 lv = osg::Vec3(0.0f,0.0f,-1.0f) * rotation_matrix;
osg::Vec3d up = osg::Vec3d(0.0,1.0,0.0) * rotation_matrix;
osg::Vec3d lv = osg::Vec3d(0.0,0.0,-1.0) * rotation_matrix;
// rotate the camera.
float dx = _ga_t0->getXnormalized();
double dx = _ga_t0->getXnormalized();
float yaw = -inDegrees(dx*50.0f*dt);
double yaw = -inDegrees(dx*50.0f*dt);
osg::Quat yaw_rotation;
yaw_rotation.makeRotate(yaw,up);
_rotation *= yaw_rotation;
rotation_matrix.makeRotate(_rotation);
osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix;
osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0) * rotation_matrix;
// movement is big enough the move the eye point along the look vector.
if (fabsf(_velocity*dt)>1e-8)
if (fabs(_velocity*dt)>1e-8)
{
float distanceToMove = _velocity*dt;
double distanceToMove = _velocity*dt;
float signedBuffer;
if (distanceToMove>=0.0f) signedBuffer=_buffer;
double signedBuffer;
if (distanceToMove>=0.0) signedBuffer=_buffer;
else signedBuffer=-_buffer;
// check to see if any obstruction in front.
@ -497,16 +497,16 @@ bool DriveManipulator::calcMovement()
if (!hitList.empty())
{
// notify(INFO) << "Hit obstruction"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
distanceToMove = (ip-_eye).length()-_buffer;
_velocity = 0.0f;
_velocity = 0.0;
}
}
// check to see if forward point is correct height above terrain.
osg::Vec3 fp = _eye+lv*distanceToMove;
osg::Vec3 lfp = fp-up*_height*5;
osg::Vec3d fp = _eye+lv*distanceToMove;
osg::Vec3d lfp = fp-up*_height*5;
iv.reset();
@ -522,10 +522,10 @@ bool DriveManipulator::calcMovement()
if (!hitList.empty())
{
// notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3 np = hitList.front().getWorldIntersectNormal();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d np = hitList.front().getWorldIntersectNormal();
if (up*np>0.0f) up = np;
if (up*np>0.0) up = np;
else up = -np;
_eye = ip+up*_height;
@ -542,7 +542,7 @@ bool DriveManipulator::calcMovement()
// no hit on the terrain found therefore resort to a fall under
// under the influence of gravity.
osg::Vec3 dp = lfp;
osg::Vec3d dp = lfp;
dp -= getUpVector(cf)* (2*_modelScale);
iv.reset();
@ -560,10 +560,10 @@ bool DriveManipulator::calcMovement()
{
notify(INFO) << "Hit terrain on decent ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3 np = hitList.front().getWorldIntersectNormal();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d np = hitList.front().getWorldIntersectNormal();
if (up*np>0.0f) up = np;
if (up*np>0.0) up = np;
else up = -np;
_eye = ip+up*_height;

View File

@ -257,19 +257,19 @@ bool FlightManipulator::calcMovement()
float dx = _ga_t0->getXnormalized();
float dy = _ga_t0->getYnormalized();
osg::CoordinateFrame cf=getCoordinateFrame(_eye.x(), _eye.y(), _eye.z());
osg::CoordinateFrame cf=getCoordinateFrame(_eye);
osg::Matrixd rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix;
osg::Vec3 lv = osg::Vec3(0.0f,0.0f,-1.0f) * rotation_matrix;
osg::Vec3d up = osg::Vec3(0.0,1.0,0.0) * rotation_matrix;
osg::Vec3d lv = osg::Vec3(0.0,0.0,-1.0) * rotation_matrix;
osg::Vec3 sv = lv^up;
osg::Vec3d sv = lv^up;
sv.normalize();
float pitch = -inDegrees(dy*75.0f*dt);
float roll = inDegrees(dx*50.0f*dt);
double pitch = -inDegrees(dy*75.0f*dt);
double roll = inDegrees(dx*50.0f*dt);
osg::Quat delta_rotate;
@ -284,8 +284,8 @@ bool FlightManipulator::calcMovement()
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
{
//float bank = asinf(sv.z());
float bank = asinf(sv *getUpVector(cf));
float yaw = inRadians(bank)*dt;
double bank = asinf(sv *getUpVector(cf));
double yaw = inRadians(bank)*dt;
osg::Quat yaw_rotate;
//yaw_rotate.makeRotate(yaw,0.0f,0.0f,1.0f);

View File

@ -211,8 +211,8 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
const osg::BoundingSphere& bs = _node->getBound();
float distance = (eye-bs.center()).length() + _node->getBound().radius();
osg::Vec3 start_segment = eye;
osg::Vec3 end_segment = eye + lookVector*distance;
osg::Vec3d start_segment = eye;
osg::Vec3d end_segment = eye + lookVector*distance;
//CoordinateFrame coordinateFrame = getCoordinateFrame(_center.x(), _center.y(), _center.z());
//osg::notify(INFO)<<"start="<<start_segment<<"\tend="<<end_segment<<"\tupVector="<<getUpVector(coordinateFrame)<<std::endl;
@ -230,17 +230,15 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
if (!hitList.empty())
{
notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
_center[0] = ip.x();
_center[1] = ip.y();
_center[2] = ip.z();
_center = ip;
_distance = (eye-ip).length();
osg::Matrix rotation_matrix = osg::Matrixd::translate(0.0,0.0,-_distance)*
matrix*
osg::Matrixd::translate(-_center[0],-_center[1],-_center[2]);
osg::Matrixd::translate(-_center);
rotation_matrix.get(_rotation);
@ -250,7 +248,7 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
if (!hitFound)
{
CoordinateFrame eyePointCoordFrame = getCoordinateFrame( eye.x(), eye.y(), eye.z());
CoordinateFrame eyePointCoordFrame = getCoordinateFrame( eye );
// clear the intersect visitor ready for a new test
iv.reset();
@ -269,11 +267,9 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
if (!hitList.empty())
{
notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
_center[0] = ip.x();
_center[1] = ip.y();
_center[2] = ip.z();
_center = ip;
_distance = (eye-ip).length();
@ -290,15 +286,15 @@ void TerrainManipulator::setByMatrix(const osg::Matrixd& matrix)
osg::Matrixd TerrainManipulator::getMatrix() const
{
return osg::Matrixd::translate(0.0,0.0,_distance)*osg::Matrixd::rotate(_rotation)*osg::Matrix::translate(_center[0],_center[1],_center[2]);
return osg::Matrixd::translate(0.0,0.0,_distance)*osg::Matrixd::rotate(_rotation)*osg::Matrix::translate(_center);
}
osg::Matrixd TerrainManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_center[0],-_center[1],-_center[2])*osg::Matrixd::rotate(_rotation.inverse())*osg::Matrixd::translate(0.0,0.0,-_distance);
return osg::Matrix::translate(-_center)*osg::Matrixd::rotate(_rotation.inverse())*osg::Matrixd::translate(0.0,0.0,-_distance);
}
void TerrainManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
void TerrainManipulator::computePosition(const osg::Vec3d& eye,const osg::Vec3d& center,const osg::Vec3d& up)
{
// compute rotation matrix
osg::Vec3 lv(center-eye);
@ -320,12 +316,9 @@ void TerrainManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& c
if (!hitList.empty())
{
osg::notify(osg::INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
osg::Vec3 np = hitList.front().getWorldIntersectNormal();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
_center[0] = ip.x();
_center[1] = ip.y();
_center[2] = ip.z();
_center = ip;
_distance = (ip-eye).length();
hitFound = true;
@ -335,9 +328,7 @@ void TerrainManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& c
if (!hitFound)
{
// ??
_center[0] = center.x();
_center[1] = center.y();
_center[2] = center.z();
_center = center;
}
@ -358,8 +349,8 @@ bool TerrainManipulator::calcMovement()
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
double dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
double dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
// return if there is no movement.
@ -373,13 +364,13 @@ bool TerrainManipulator::calcMovement()
{
// rotate camera.
osg::Vec3 axis;
float angle;
double angle;
float px0 = _ga_t0->getXnormalized();
float py0 = _ga_t0->getYnormalized();
double px0 = _ga_t0->getXnormalized();
double py0 = _ga_t0->getYnormalized();
float px1 = _ga_t1->getXnormalized();
float py1 = _ga_t1->getYnormalized();
double px1 = _ga_t1->getXnormalized();
double py1 = _ga_t1->getYnormalized();
trackball(axis,angle,px1,py1,px0,py0);
@ -394,15 +385,15 @@ bool TerrainManipulator::calcMovement()
osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation);
osg::Vec3 lookVector = -getUpVector(rotation_matrix);
osg::Vec3 sideVector = getSideVector(rotation_matrix);
osg::Vec3 upVector = getFrontVector(rotation_matrix);
osg::Vec3d lookVector = -getUpVector(rotation_matrix);
osg::Vec3d sideVector = getSideVector(rotation_matrix);
osg::Vec3d upVector = getFrontVector(rotation_matrix);
CoordinateFrame coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]);
osg::Vec3 localUp = getUpVector(coordinateFrame);
CoordinateFrame coordinateFrame = getCoordinateFrame(_center);
osg::Vec3d localUp = getUpVector(coordinateFrame);
osg::Vec3 forwardVector = localUp^sideVector;
osg::Vec3d forwardVector = localUp^sideVector;
sideVector = forwardVector^localUp;
forwardVector.normalize();
@ -425,44 +416,41 @@ bool TerrainManipulator::calcMovement()
{
// pan model.
float scale = -0.5f*_distance;
double scale = -0.5f*_distance;
osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation);
// compute look vector.
osg::Vec3 lookVector = -getUpVector(rotation_matrix);
osg::Vec3 sideVector = getSideVector(rotation_matrix);
osg::Vec3 upVector = getFrontVector(rotation_matrix);
osg::Vec3d lookVector = -getUpVector(rotation_matrix);
osg::Vec3d sideVector = getSideVector(rotation_matrix);
osg::Vec3d upVector = getFrontVector(rotation_matrix);
CoordinateFrame coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]);
osg::Vec3 localUp = getUpVector(coordinateFrame);
CoordinateFrame coordinateFrame = getCoordinateFrame(_center);
osg::Vec3d localUp = getUpVector(coordinateFrame);
osg::Vec3 forwardVector =localUp^sideVector;
osg::Vec3d forwardVector =localUp^sideVector;
sideVector = forwardVector^localUp;
forwardVector.normalize();
sideVector.normalize();
osg::Vec3 dv = forwardVector * (dy*scale) + sideVector * (dx*scale);
osg::Vec3d dv = forwardVector * (dy*scale) + sideVector * (dx*scale);
_center[0] += dv.x();
_center[1] += dv.y();
_center[2] += dv.z();
_center += dv;
// need to recompute the itersection point along the look vector.
// now reorientate the coordinate frame to the frame coords.
coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]);
coordinateFrame = getCoordinateFrame(_center);
// need to reintersect with the terrain
osgUtil::IntersectVisitor iv;
float distance = _node->getBound().radius();
osg::Vec3 start_segment = osg::Vec3(_center[0],_center[1],_center[2]) + getUpVector(coordinateFrame) * distance;
osg::Vec3 end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance);
//end_segment.set(0.0f,0.0f,0.0f);
double distance = _node->getBound().radius();
osg::Vec3d start_segment = osg::Vec3d(_center[0],_center[1],_center[2]) + getUpVector(coordinateFrame) * distance;
osg::Vec3d end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance);
osg::notify(INFO)<<"start="<<start_segment<<"\tend="<<end_segment<<"\tupVector="<<getUpVector(coordinateFrame)<<std::endl;
@ -479,10 +467,8 @@ bool TerrainManipulator::calcMovement()
if (!hitList.empty())
{
notify(INFO) << "Hit terrain ok"<< std::endl;
osg::Vec3 ip = hitList.front().getWorldIntersectPoint();
_center[0] = ip.x();
_center[1] = ip.y();
_center[2] = ip.z();
osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
_center = ip;
hitFound = true;
}
@ -494,14 +480,16 @@ bool TerrainManipulator::calcMovement()
osg::notify(INFO)<<"TerrainManipulator unable to intersect with terrain."<<std::endl;
}
coordinateFrame = getCoordinateFrame(_center[0], _center[1], _center[2]);
osg::Vec3 new_localUp = getUpVector(coordinateFrame);
coordinateFrame = getCoordinateFrame(_center);
osg::Vec3d new_localUp = getUpVector(coordinateFrame);
osg::Quat pan_rotation;
pan_rotation.makeRotate(localUp,new_localUp);
_rotation = _rotation * pan_rotation;
osg::notify(osg::NOTICE)<<"Rotating from "<<localUp<<" to "<<new_localUp<<" angle = "<<acos(localUp*new_localUp/(localUp.length()*new_localUp.length()))<<std::endl;
// clampOrientation();
//clampOrientation();
return true;
}
@ -510,8 +498,8 @@ bool TerrainManipulator::calcMovement()
// zoom model.
float fd = _distance;
float scale = 1.0f+dy;
double fd = _distance;
double scale = 1.0f+dy;
if (fd*scale>_modelScale*_minimumZoomScale)
{
@ -533,13 +521,13 @@ void TerrainManipulator::clampOrientation()
osg::Matrix rotation_matrix;
rotation_matrix.set(_rotation);
osg::Vec3 lookVector = -getUpVector(rotation_matrix);
osg::Vec3 upVector = getFrontVector(rotation_matrix);
osg::Vec3d lookVector = -getUpVector(rotation_matrix);
osg::Vec3d upVector = getFrontVector(rotation_matrix);
CoordinateFrame coordinateFrame = getCoordinateFrame(_center[0],_center[1],_center[2]);
osg::Vec3 localUp = getUpVector(coordinateFrame);
CoordinateFrame coordinateFrame = getCoordinateFrame(_center);
osg::Vec3d localUp = getUpVector(coordinateFrame);
osg::Vec3 sideVector = lookVector ^ localUp;
osg::Vec3d sideVector = lookVector ^ localUp;
if (sideVector.length()<0.1)
{
@ -550,7 +538,7 @@ void TerrainManipulator::clampOrientation()
}
Vec3 newUpVector = sideVector^lookVector;
Vec3d newUpVector = sideVector^lookVector;
newUpVector.normalize();
osg::Quat rotate_roll;
@ -582,7 +570,7 @@ const float TRACKBALLSIZE = 0.8f;
* It is assumed that the arguments to this routine are in the range
* (-1.0 ... 1.0)
*/
void TerrainManipulator::trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y)
void TerrainManipulator::trackball(osg::Vec3& axis,double & angle, double p1x, double p1y, double p2x, double p2y)
{
/*
* First, figure out z-coordinates for projection of P1 and P2 to
@ -592,12 +580,12 @@ void TerrainManipulator::trackball(osg::Vec3& axis,float& angle, float p1x, floa
osg::Matrix rotation_matrix(_rotation);
osg::Vec3 uv = osg::Vec3(0.0f,1.0f,0.0f)*rotation_matrix;
osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f)*rotation_matrix;
osg::Vec3 lv = osg::Vec3(0.0f,0.0f,-1.0f)*rotation_matrix;
osg::Vec3d uv = osg::Vec3d(0.0,1.0,0.0)*rotation_matrix;
osg::Vec3d sv = osg::Vec3d(1.0,0.0,0.0)*rotation_matrix;
osg::Vec3d lv = osg::Vec3d(0.0,0.0,-1.0)*rotation_matrix;
osg::Vec3 p1 = sv*p1x+uv*p1y-lv*tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y);
osg::Vec3 p2 = sv*p2x+uv*p2y-lv*tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y);
osg::Vec3d p1 = sv*p1x+uv*p1y-lv*tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y);
osg::Vec3d p2 = sv*p2x+uv*p2y-lv*tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y);
/*
* Now, we want the cross product of P1 and P2
@ -615,7 +603,7 @@ axis = p2^p1;
/*
* Figure out how much to rotate around that axis.
*/
float t = (p2-p1).length() / (2.0*TRACKBALLSIZE);
double t = (p2-p1).length() / (2.0*TRACKBALLSIZE);
/*
* Avoid problems with out-of-control values...
@ -631,7 +619,7 @@ axis = p2^p1;
* Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
* if we are away from the center of the sphere.
*/
float TerrainManipulator::tb_project_to_sphere(float r, float x, float y)
double TerrainManipulator::tb_project_to_sphere(double r, double x, double y)
{
float d, t, z;

View File

@ -18,7 +18,6 @@ class LOD;
class Geode;
class Material;
class Texture;
class Vec4;
};

View File

@ -11,6 +11,8 @@
#include <osg/Group>
#include <osg/Vec3>
#include <osg/AnimationPath>
#include <osg/Vec3>
#include <osg/Vec4>
#include <string>
#include <vector>

View File

@ -487,7 +487,7 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable_useSeperateIndices(GLMmodel* obj, G
// geometry
osg::Geometry* geom = new osg::Geometry;
geom->setUseDisplayList(false);
// geom->setUseDisplayList(false);
// geom->setUseVertexBufferObjects(true);
// the following code for mapping the coords, normals and texcoords

View File

@ -179,9 +179,9 @@ public:
_viewer(viewer) {}
virtual osg::CoordinateFrame getCoordinateFrame(double X, double Y, double Z) const
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const
{
osg::notify(osg::INFO)<<"getCoordinateFrame("<<X<<","<<Y<<","<<Z<<")"<<std::endl;
osg::notify(osg::INFO)<<"getCoordinateFrame("<<position<<")"<<std::endl;
const Viewer::RefNodePath& refNodePath = _viewer->getCoordindateSystemNodePath();
@ -202,7 +202,7 @@ public:
osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(tmpPath.back());
if (csn)
{
coordinateFrame = csn->computeLocalCoordinateFrame(X,Y,Z)* osg::computeLocalToWorld(tmpPath);
coordinateFrame = csn->computeLocalCoordinateFrame(position)* osg::computeLocalToWorld(tmpPath);
}
else
{
@ -212,7 +212,7 @@ public:
}
else
{
return osg::Matrixd::translate(X,Y,Z);
return osg::Matrixd::translate(position);
}
}

View File

@ -718,7 +718,7 @@ ViewerEventHandler::ViewerEventHandler(OsgCameraGroup* cg):
if (cfg->getNumberOfCameras()==1)
{
SnapImageDrawCallback* snapImageDrawCallback = new SnapImageDrawCallback("saved_image.jpg");
SnapImageDrawCallback* snapImageDrawCallback = new SnapImageDrawCallback("saved_image.dds");
cam->addPostDrawCallback(snapImageDrawCallback);
_snapImageDrawCallbackList.push_back(snapImageDrawCallback);
}