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

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