Added new Matrixf and Matrixd implementations.

Made Matrix be a typedef to either Matrixf or Matrixd.  Defaults to Matrixf.

Converted the osgGA::MatrixManipulators and osgProducer::Viewer/OsgCameraGroup
across to using exclusively Matrixd for internal computations and passing betwen
Manipulators, Producer and SceneView. Note, SceneView still uses Matrix internally
so will depend on what is set as the default in include/osg/Matrix.

Added the ability to osgProducer::setDone/getDone(), kept done() as the
method that the viewer main loop uses for detecting the exit condition.
This commit is contained in:
Robert Osfield
2003-09-05 22:35:34 +00:00
parent a2834d74d2
commit 792bba05b9
23 changed files with 203 additions and 129 deletions

View File

@@ -12,9 +12,26 @@
*/
#include <osg/Matrixd>
#include <osg/Matrixf>
// specialise Matrix_implementaiton to be Matrixd
#define Matrix_implementation Matrixd
osg::Matrixd::Matrixd( const osg::Matrixf& mat )
{
set(mat.ptr());
}
osg::Matrixd& osg::Matrixd::operator = (const osg::Matrixf& rhs)
{
set(rhs.ptr());
return *this;
}
void osg::Matrixd::set(const osg::Matrixf& rhs)
{
set(rhs.ptr());
}
// now compile up Matrix via Matrix_implementation
#include "Matrix_implementation.cpp"

View File

@@ -12,9 +12,26 @@
*/
#include <osg/Matrixf>
#include <osg/Matrixd>
// specialise Matrix_implementaiton to be Matrixf
#define Matrix_implementation Matrixf
osg::Matrixf::Matrixf( const osg::Matrixd& mat )
{
set(mat.ptr());
}
osg::Matrixf& osg::Matrixf::operator = (const osg::Matrixd& rhs)
{
set(rhs.ptr());
return *this;
}
void osg::Matrixf::set(const osg::Matrixd& rhs)
{
set(rhs.ptr());
}
// now compile up Matrix via Matrix_implementation
#include "Matrix_implementation.cpp"

View File

@@ -166,7 +166,7 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
osg::Vec3 ep = _eye;
Matrix rotation_matrix;
Matrixd rotation_matrix;
rotation_matrix.get(_rotation);
osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix;
osg::Vec3 bp = ep;
@@ -353,20 +353,20 @@ void DriveManipulator::addMouseEvent(const GUIEventAdapter& ea)
_ga_t0 = &ea;
}
void DriveManipulator::setByMatrix(const osg::Matrix& matrix)
void DriveManipulator::setByMatrix(const osg::Matrixd& matrix)
{
_eye = matrix.getTrans();
matrix.get(_rotation);
}
osg::Matrix DriveManipulator::getMatrix() const
osg::Matrixd DriveManipulator::getMatrix() const
{
return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye);
return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_eye);
}
osg::Matrix DriveManipulator::getInverseMatrix() const
osg::Matrixd DriveManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse());
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)

View File

@@ -180,21 +180,21 @@ void FlightManipulator::addMouseEvent(const GUIEventAdapter& ea)
}
void FlightManipulator::setByMatrix(const osg::Matrix& matrix)
void FlightManipulator::setByMatrix(const osg::Matrixd& matrix)
{
_eye = matrix.getTrans();
matrix.get(_rotation);
_distance = 1.0f;
}
osg::Matrix FlightManipulator::getMatrix() const
osg::Matrixd FlightManipulator::getMatrix() const
{
return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye);
return osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_eye);
}
osg::Matrix FlightManipulator::getInverseMatrix() const
osg::Matrixd FlightManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse());
return osg::Matrixd::translate(-_eye)*osg::Matrixd::rotate(_rotation.inverse());
}
void FlightManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
@@ -206,7 +206,7 @@ void FlightManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv
osg::Vec3 u(s^f);
u.normalize();
osg::Matrix rotation_matrix(s[0], u[0], -f[0], 0.0f,
osg::Matrixd 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);
@@ -258,7 +258,7 @@ bool FlightManipulator::calcMovement()
float dy = _ga_t0->getYnormalized();
osg::Matrix rotation_matrix;
osg::Matrixd rotation_matrix;
rotation_matrix.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * rotation_matrix;

View File

@@ -189,24 +189,20 @@ void TrackballManipulator::addMouseEvent(const GUIEventAdapter& ea)
_ga_t0 = &ea;
}
void TrackballManipulator::setByMatrix(const osg::Matrix& matrix)
void TrackballManipulator::setByMatrix(const osg::Matrixd& matrix)
{
_center = osg::Vec3(0.0f,0.0f,-_distance)*matrix;//matrix.getTrans();
_center = osg::Vec3(0.0f,0.0f,-_distance)*matrix;
matrix.get(_rotation);
osg::Matrix rotation_matrix(_rotation);
// _center -= osg::Vec3(0.0f,0.0f,_distance)*rotation_matrix;
}
osg::Matrix TrackballManipulator::getMatrix() const
osg::Matrixd TrackballManipulator::getMatrix() const
{
return osg::Matrix::translate(0.0f,0.0f,_distance)*osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_center);
return osg::Matrixd::translate(0.0,0.0,_distance)*osg::Matrixd::rotate(_rotation)*osg::Matrixd::translate(_center);
}
osg::Matrix TrackballManipulator::getInverseMatrix() const
osg::Matrixd TrackballManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_center)*osg::Matrix::rotate(_rotation.inverse())*osg::Matrix::translate(0.0f,0.0f,-_distance);
return osg::Matrixd::translate(-_center)*osg::Matrixd::rotate(_rotation.inverse())*osg::Matrixd::translate(0.0,0.0,-_distance);
}
void TrackballManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)

View File

@@ -436,19 +436,16 @@ const osg::Node* OsgCameraGroup::getTopMostSceneData() const
return _scene_data.get();
}
void OsgCameraGroup::setView(const osg::Matrix& matrix)
void OsgCameraGroup::setView(const osg::Matrixd& matrix)
{
Producer::Matrix pm;//(matrix.ptr());
for(int i=0;i<4;++i)
for(int j=0;j<4;++j)
pm(i,j)=matrix(i,j);
Producer::Matrix pm(matrix.ptr());
setViewByMatrix(pm);
}
const osg::Matrix OsgCameraGroup::getViewMatrix() const
osg::Matrixd OsgCameraGroup::getViewMatrix() const
{
osg::Matrix matrix;
osg::Matrixd matrix;
if (_cfg.valid() && _cfg->getNumberOfCameras()>=1)
{
const Producer::Camera *cam = _cfg->getCamera(0);

View File

@@ -72,7 +72,7 @@ public:
virtual void apply(osg::Projection& pr)
{ // stack the intersect rays, transform to new projection, traverse
// Assumes that the Projection is an absolute projection
osg::Matrix mt;
osg::Matrixd mt;
mt.invert(pr.getMatrix());
osg::Vec3 npt=osg::Vec3(xp,yp,-1.0f) * mt, farpt=osg::Vec3(xp,yp,1.0f) * mt;
@@ -105,11 +105,11 @@ public:
return _PIVsegHitList;
}
osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Matrix &projm, const float x, const float y)
osgUtil::IntersectVisitor::HitList& getHits(osg::Node *node, const osg::Matrixd &projm, const float x, const float y)
{
// utility for non=sceneview viewers
// x,y are values returned by
osg::Matrix inverseMVPW;
osg::Matrixd inverseMVPW;
inverseMVPW.invert(projm);
osg::Vec3 near_point = osg::Vec3(x,y,-1.0f)*inverseMVPW;
osg::Vec3 far_point = osg::Vec3(x,y,1.0f)*inverseMVPW;
@@ -303,7 +303,7 @@ void Viewer::setViewByMatrix( const Producer::Matrix & pm)
// now convert Producer matrix to an osg::Matrix so we can update
// the internal camera...
osg::Matrix matrix(pm.ptr());
osg::Matrixd matrix(pm.ptr());
_keyswitchManipulator->setByInverseMatrix(matrix);
}
}
@@ -439,7 +439,7 @@ void Viewer::update()
if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentMatrixManipulator())
{
osgGA::MatrixManipulator* mm = _keyswitchManipulator->getCurrentMatrixManipulator();
osg::Matrix matrix = mm->getInverseMatrix();
osg::Matrixd matrix = mm->getInverseMatrix();
CameraGroup::setViewByMatrix(Producer::Matrix(matrix.ptr()));
setFusionDistance(mm->getFusionDistanceMode(),mm->getFusionDistanceValue());
@@ -452,7 +452,7 @@ void Viewer::frame()
if (getRecordingAnimationPath() && getAnimationPath())
{
osg::Matrix matrix;
osg::Matrixd matrix;
matrix.invert(getViewMatrix());
osg::Quat quat;
matrix.get(quat);
@@ -538,7 +538,7 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil
osgProducer::OsgSceneHandler* sh = dynamic_cast<osgProducer::OsgSceneHandler*>(camera->getSceneHandler());
osgUtil::SceneView* sv = sh?sh->getSceneView():0;
osg::Matrix vum;
osg::Matrixd vum;
if (sv!=0)
{
vum.set(sv->getViewMatrix() *
@@ -546,8 +546,8 @@ bool Viewer::computeIntersections(float x,float y,unsigned int cameraNum,osgUtil
}
else
{
vum.set(osg::Matrix(camera->getViewMatrix()) *
osg::Matrix(camera->getProjectionMatrix()));
vum.set(osg::Matrixd(camera->getViewMatrix()) *
osg::Matrixd(camera->getProjectionMatrix()));
}
PickVisitor iv;