Removed remaining dependancies on osg::Camera.

This commit is contained in:
Robert Osfield
2003-05-19 15:15:17 +00:00
parent 4151312dc5
commit 940ce67133
31 changed files with 506 additions and 616 deletions

View File

@@ -129,10 +129,6 @@ SOURCE=..\..\src\osg\BoundingSphere.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Camera.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\ClipNode.cpp
# End Source File
# Begin Source File
@@ -501,10 +497,6 @@ SOURCE=..\..\include\osg\BoundsChecking
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Camera
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\ClipNode
# End Source File
# Begin Source File

View File

@@ -97,7 +97,7 @@ SOURCE=..\..\src\osgGA\AnimationPathManipulator.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgGA\CameraManipulator.cpp
SOURCE=..\..\src\osgGA\MatrixManipulator.cpp
# End Source File
# Begin Source File
@@ -117,7 +117,7 @@ SOURCE=..\..\src\osgGA\GUIEventHandlerVisitor.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osgGA\KeySwitchCameraManipulator.cpp
SOURCE=..\..\src\osgGA\KeySwitchMatrixManipulator.cpp
# End Source File
# Begin Source File
@@ -145,7 +145,7 @@ SOURCE=..\..\Include\osgGA\AnimationPathManipulator
# End Source File
# Begin Source File
SOURCE=..\..\Include\osgGA\CameraManipulator
SOURCE=..\..\Include\osgGA\MatrixManipulator
# End Source File
# Begin Source File
@@ -177,7 +177,7 @@ SOURCE=..\..\Include\osgGA\GUIEventHandlerVisitor
# End Source File
# Begin Source File
SOURCE=..\..\Include\osgGA\KeySwitchCameraManipulator
SOURCE=..\..\Include\osgGA\KeySwitchMatrixManipulator
# End Source File
# Begin Source File

View File

@@ -1,5 +1,4 @@
#include "GliderManipulator.h"
#include <osg/Notify>
using namespace osg;
@@ -10,6 +9,8 @@ GliderManipulator::GliderManipulator()
_modelScale = 0.01f;
_velocity = 0.0f;
_yawMode = YAW_AUTOMATICALLY_WHEN_BANKED;
_distance = 1.0f;
}
@@ -35,17 +36,23 @@ const osg::Node* GliderManipulator::getNode() const
}
osg::Node* GliderManipulator::getNode()
{
return _node.get();
}
void GliderManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(_node.get() && _camera.get())
if(_node.get())
{
const osg::BoundingSphere& boundingSphere=_node->getBound();
osg::Vec3 eye = boundingSphere._center+osg::Vec3(-boundingSphere._radius*0.25f,-boundingSphere._radius*0.25f,-boundingSphere._radius*0.03f);
_camera->setView(eye,
eye+osg::Vec3(1.0f,1.0f,-0.1f),
computePosition(eye,
osg::Vec3(1.0f,1.0f,-0.1f),
osg::Vec3(0.0f,0.0f,1.0f));
_velocity = boundingSphere._radius*0.01f;
@@ -67,23 +74,17 @@ void GliderManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestContinuousUpdate(false);
const osg::BoundingSphere& boundingSphere=_node->getBound();
_velocity = boundingSphere._radius*0.01f;
_velocity = 0.0f;
if (ea.getEventType()!=GUIEventAdapter::RESIZE)
{
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
}
_camera->setFusionDistanceRatio(1/1000.0f);
}
bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(!_camera.get()) return false;
switch(ea.getEventType())
{
case(GUIEventAdapter::PUSH):
@@ -132,6 +133,16 @@ bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestContinuousUpdate(false);
return true;
}
else if (ea.getKey()=='q')
{
_yawMode = YAW_AUTOMATICALLY_WHEN_BANKED;
return true;
}
else if (ea.getKey()=='a')
{
_yawMode = NO_AUTOMATIC_YAW;
return true;
}
return false;
case(GUIEventAdapter::FRAME):
@@ -149,6 +160,12 @@ bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
}
}
void GliderManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("Flight: Space","Reset the viewing position to home");
usage.addKeyboardMouseBinding("Flight: q","Automatically yaw when banked (default)");
usage.addKeyboardMouseBinding("Flight: a","No yaw when banked");
}
void GliderManipulator::flushMouseEventStack()
{
@@ -164,16 +181,53 @@ void GliderManipulator::addMouseEvent(const GUIEventAdapter& ea)
}
void GliderManipulator::setByMatrix(const osg::Matrix& matrix)
{
_eye = matrix.getTrans();
_rotation.set(matrix);
_distance = 1.0f;
}
osg::Matrix GliderManipulator::getMatrix() const
{
return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye);
}
osg::Matrix GliderManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse());
}
void GliderManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
{
osg::Vec3 f(lv);
f.normalize();
osg::Vec3 s(f^up);
s.normalize();
osg::Vec3 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);
_eye = eye;
_distance = lv.length();
_rotation.set(rotation_matrix);
_rotation = _rotation.inverse();
}
bool GliderManipulator::calcMovement()
{
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
_camera->setFusionDistanceRatio(1/300.0f);
//_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
float dt = _ga_t0->time()-_ga_t1->time();
double dt = _ga_t0->time()-_ga_t1->time();
if (dt<0.0f)
{
@@ -206,29 +260,44 @@ bool GliderManipulator::calcMovement()
float dx = _ga_t0->getXnormalized();
float dy = _ga_t0->getYnormalized();
osg::Vec3 center = _camera->getEyePoint();
osg::Vec3 sv = _camera->getSideVector();
osg::Vec3 lv = _camera->getLookVector();
float pitch = inDegrees(-dy*70.0f*dt);
float roll = inDegrees(dx*60.0f*dt);
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::Vec3 sv = lv^up;
sv.normalize();
float pitch = -inDegrees(dy*75.0f*dt);
float roll = inDegrees(dx*50.0f*dt);
osg::Quat delta_rotate;
osg::Quat roll_rotate;
osg::Quat pitch_rotate;
pitch_rotate.makeRotate(pitch,sv.x(),sv.y(),sv.z());
roll_rotate.makeRotate(roll,lv.x(),lv.y(),lv.z());
delta_rotate = pitch_rotate*roll_rotate;
osg::Matrix mat;
mat.makeTranslate(-center);
mat *= Matrix::rotate(pitch,sv.x(),sv.y(),sv.z());
mat *= Matrix::rotate(roll,lv.x(),lv.y(),lv.z());
if (_yawMode==YAW_AUTOMATICALLY_WHEN_BANKED)
{
float bank = asinf(sv.z());
float yaw = inRadians(bank)*dt;
mat *= Matrix::rotate(yaw,0.0f,0.0f,1.0f);
osg::Quat yaw_rotate;
yaw_rotate.makeRotate(yaw,0.0f,0.0f,1.0f);
delta_rotate = delta_rotate*yaw_rotate;
}
lv *= (_velocity*dt);
mat *= Matrix::translate(center+lv);
_camera->transformLookAt(mat);
_eye += lv;
_rotation = _rotation*delta_rotate;
return true;
}

View File

@@ -1,53 +1,89 @@
#ifndef HANGGLIDE_GLIDERMANIPULATOR
#define HANGGLIDE_GLIDERMANIPULATOR 1
/* -*-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.
*/
#include <osgGA/CameraManipulator>
#ifndef OSGGA_GliderMANIPULATOR
#define OSGGA_GliderMANIPULATOR 1
class GliderManipulator : public osgGA::CameraManipulator
#include <osgGA/MatrixManipulator>
#include <osg/Quat>
/**
GliderManipulator is a MatrixManipulator which provides Glider simulator-like
updating of the camera position & orientation. By default, the left mouse
button accelerates, the right mouse button decelerates, and the middle mouse
button (or left and right simultaneously) stops dead.
*/
class OSGGA_EXPORT GliderManipulator : public osgGA::MatrixManipulator
{
public:
GliderManipulator();
virtual ~GliderManipulator();
GliderManipulator();
virtual const char* className() const { return "Glider"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
/** Attach a node to the manipulator.
Automatically detaches previously attached node.
setNode(NULL) detaches previously nodes.
Is ignored by manipulators which do not require a reference model.*/
virtual void setNode(osg::Node*);
/** Return node if attached.*/
virtual const osg::Node* getNode() const;
/** Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.*/
virtual osg::Node* getNode();
virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
/** Start/restart the manipulator.*/
virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
/** handle events, return true if handled, false otherwise.*/
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
/** Get the keyboard and mouse usage of this manipulator.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
enum YawControlMode {
YAW_AUTOMATICALLY_WHEN_BANKED,
NO_AUTOMATIC_YAW
YAW_AUTOMATICALLY_WHEN_BANKED,
NO_AUTOMATIC_YAW
};
/** Set the yaw control between no yaw and yawing when banked.*/
/** Configure the Yaw control for the Glider model. */
void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
private:
protected:
virtual ~GliderManipulator();
/** Reset the internal GUIEvent stack.*/
void flushMouseEventStack();
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const osgGA::GUIEventAdapter& ea);
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& 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();
// Internal event stack comprising last three mouse events.
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
@@ -56,8 +92,12 @@ class GliderManipulator : public osgGA::CameraManipulator
float _modelScale;
float _velocity;
YawControlMode _yawMode;
osg::Vec3 _eye;
osg::Quat _rotation;
float _distance;
};

View File

@@ -45,17 +45,15 @@ osg::Node* TestManipulator::getNode()
/*ea*/
void TestManipulator::home(const GUIEventAdapter& ,GUIActionAdapter& us)
{
if(_node.get() && _camera.get())
if(_node.get())
{
const osg::BoundingSphere& boundingSphere=_node->getBound();
_camera->setView(boundingSphere.center()+osg::Vec3(0.0f, 0.0f, 20.0f),
boundingSphere.center()+osg::Vec3(0.0f, 1.0f, 20.0f),
computePosition(boundingSphere.center()+osg::Vec3(0.0f, 0.0f, 20.0f),
osg::Vec3(0.0f, 1.0f, 20.0f),
osg::Vec3(0.0f, 0.0f, 1.0f));
computeLocalDataFromCamera();
us.requestRedraw();
}
}
@@ -64,14 +62,10 @@ void TestManipulator::home(const GUIEventAdapter& ,GUIActionAdapter& us)
void TestManipulator::init(const GUIEventAdapter& ,GUIActionAdapter& )
{
flushMouseEventStack();
computeLocalDataFromCamera();
}
bool TestManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(!_camera.get()) return false;
switch(ea.getEventType())
{
case(GUIEventAdapter::PUSH):
@@ -142,26 +136,9 @@ bool TestManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestRedraw();
us.requestContinuousUpdate(false);
return true;
} else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
// this is quick hack to test out othographic projection.
// else if (ea.getKey()=='O')
// {
// float dist = _camera->getLookDistance();
// _camera->setOrtho(-dist,dist,-dist,dist,-dist,dist);
// return true;
// }
}
return false;
case(GUIEventAdapter::FRAME):
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_LOOK_DISTANCE);
if (_thrown)
{
if (calcMovement()) us.requestRedraw();
@@ -202,39 +179,41 @@ void TestManipulator::addMouseEvent(const GUIEventAdapter& ea)
_ga_t0 = &ea;
}
void TestManipulator::computeLocalDataFromCamera()
void TestManipulator::setByMatrix(const osg::Matrix& matrix)
{
// maths from gluLookAt/osg::Matrix::makeLookAt
osg::Vec3 f(_camera->getCenterPoint()-_camera->getEyePoint());
_center = matrix.getTrans();
_rotation.set(matrix);
_distance = 1.0f;
}
osg::Matrix TestManipulator::getMatrix() const
{
return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_center);
}
osg::Matrix TestManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_center)*osg::Matrix::rotate(_rotation.inverse());
}
void TestManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
{
osg::Vec3 f(lv);
f.normalize();
osg::Vec3 s(f^_camera->getUpVector());
osg::Vec3 s(f^up);
s.normalize();
osg::Vec3 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);
_center = _camera->getCenterPoint();
_distance = _camera->getLookDistance();
_center = eye+lv;
_distance = lv.length();
_rotation.set(rotation_matrix);
_rotation = _rotation.inverse();
}
void TestManipulator::computeCameraFromLocalData()
{
osg::Matrix new_rotation;
new_rotation.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * new_rotation;
osg::Vec3 eye = (osg::Vec3(0.0f,0.0f,_distance) * new_rotation) + _center;
_camera->setLookAt(eye,_center,up);
}
@@ -262,8 +241,6 @@ bool TestManipulator::calcMovement()
_rotation = _rotation*new_rotate;
computeCameraFromLocalData();
return true;
}
@@ -276,104 +253,24 @@ bool TestManipulator::calcMovement()
_center += dv;
computeCameraFromLocalData();
return true;
}
else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON)
{
osg::Vec3 uv = _camera->getUpVector();
osg::Vec3 sv = _camera->getSideVector();
osg::Matrix rotation_matrix;
_rotation.get(rotation_matrix);
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 fv = uv ^ sv;
osg::Vec3 dv = fv*(dy*-500.0f)-sv*(dx*500.0f);
_center += dv;
computeCameraFromLocalData();
return true;
}
return false;
}
/*
* This size should really be based on the distance from the center of
* rotation to the point on the object underneath the mouse. That
* point would then track the mouse as closely as possible. This is a
* simple example, though, so that is left as an Exercise for the
* Programmer.
*/
const float TRACKBALLSIZE = 0.8f;
/*
* Ok, simulate a track-ball. Project the points onto the virtual
* trackball, then figure out the axis of rotation, which is the cross
* product of P1 P2 and O P1 (O is the center of the ball, 0,0,0)
* Note: This is a deformed trackball-- is a trackball in the center,
* but is deformed into a hyperbolic sheet of rotation away from the
* center. This particular function was chosen after trying out
* several variations.
*
* It is assumed that the arguments to this routine are in the range
* (-1.0 ... 1.0)
*/
void TestManipulator::trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y)
{
/*
* First, figure out z-coordinates for projection of P1 and P2 to
* deformed sphere
*/
osg::Vec3 uv = _camera->getUpVector();
osg::Vec3 sv = _camera->getSideVector();
osg::Vec3 lv = _camera->getLookVector();
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);
/*
* Now, we want the cross product of P1 and P2
*/
axis = p2^p1;
axis.normalize();
/*
* Figure out how much to rotate around that axis.
*/
float t = (p2-p1).length() / (2.0*TRACKBALLSIZE);
/*
* Avoid problems with out-of-control values...
*/
if (t > 1.0) t = 1.0;
if (t < -1.0) t = -1.0;
angle = inRadians(asin(t));
}
/*
* 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 TestManipulator::tb_project_to_sphere(float r, float x, float y)
{
float d, t, z;
d = sqrt(x*x + y*y);
/* Inside sphere */
if (d < r * 0.70710678118654752440)
{
z = sqrt(r*r - d*d);
} /* On hyperbola */
else
{
t = r / 1.41421356237309504880;
z = t*t / d;
}
return z;
}

View File

@@ -5,15 +5,28 @@
#ifndef OSGGA_TESTMANIPULATOR
#define OSGGA_TESTMANIPULATOR 1
#include <osgGA/CameraManipulator>
#include <osgGA/MatrixManipulator>
#include <osg/Quat>
class TestManipulator : public osgGA::CameraManipulator
class TestManipulator : public osgGA::MatrixManipulator
{
public:
TestManipulator();
virtual ~TestManipulator();
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
/** Attach a node to the manipulator.
Automatically detaches previously attached node.
setNode(NULL) detaches previously nodes.
@@ -44,18 +57,12 @@ class TestManipulator : public osgGA::CameraManipulator
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const osgGA::GUIEventAdapter& ea);
void computeLocalDataFromCamera();
void computeCameraFromLocalData();
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& 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);
/** Check the speed at which the mouse is moving.
If speed is below a threshold then return false, otherwise return true.*/
bool isMouseMoving();

View File

@@ -386,9 +386,7 @@ int main(int argc, char **argv)
viewer.setSceneData(root);
// create the windows and run the threads.
// viewer.realize();
// run single threaded since osgParticle still writes during cull.
viewer.realize(Producer::CameraGroup::SingleThreaded);
viewer.realize();
while( !viewer.done() )
{

View File

@@ -513,7 +513,6 @@ int main( int argc, char **argv )
sceneview->setCullMaskLeft(0x00000001);
sceneview->setCullMaskRight(0x00000002);
sceneview->setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE,radius);
sceneview->setCamera(0);
}

View File

@@ -16,7 +16,7 @@
#include <osg/AnimationPath>
#include <osg/Notify>
#include <osgGA/CameraManipulator>
#include <osgGA/MatrixManipulator>
namespace osgGA{
@@ -31,7 +31,7 @@ namespace osgGA{
// px py pz = World position in catesian coordinates
// ax ay az aw = Orientation (attitude) defined as a quaternion
class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
class OSGGA_EXPORT AnimationPathManipulator : public MatrixManipulator
{
public:
@@ -41,6 +41,19 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
virtual const char* className() const { return "AnimationPath"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix) { _matrix = matrix; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { _matrix.invert(matrix); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const { return _matrix; }
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const { return osg::Matrix::inverse(_matrix); }
void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; }
osg::AnimationPath* getAnimationPath() { return _animationPath.get(); }
@@ -74,6 +87,8 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
double _realStartOfTimedPeriod;
double _animStartOfTimedPeriod;
int _numOfFramesSinceStartOfTimedPeriod;
osg::Matrix _matrix;
};

View File

@@ -14,7 +14,8 @@
#ifndef OSGGA_DRIVEMANIPULATOR
#define OSGGA_DRIVEMANIPULATOR 1
#include <osgGA/CameraManipulator>
#include <osgGA/MatrixManipulator>
#include <osg/Quat>
namespace osgGA{
@@ -25,7 +26,7 @@ mouse button decelerates, and the middle mouse button (or left and
right simultaneously) stops dead.
*/
class OSGGA_EXPORT DriveManipulator : public CameraManipulator
class OSGGA_EXPORT DriveManipulator : public MatrixManipulator
{
public:
@@ -33,6 +34,18 @@ class OSGGA_EXPORT DriveManipulator : public CameraManipulator
virtual const char* className() const { return "Drive"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
virtual void setNode(osg::Node*);
virtual const osg::Node* getNode() const;
@@ -58,10 +71,7 @@ class OSGGA_EXPORT DriveManipulator : public CameraManipulator
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computeLocalDataFromCamera();
void computeCameraFromLocalData();
void computeCameraFromLocalData(const osg::Vec3& lv,const osg::Vec3& up);
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/

View File

@@ -14,18 +14,19 @@
#ifndef OSGGA_FLIGHTMANIPULATOR
#define OSGGA_FLIGHTMANIPULATOR 1
#include <osgGA/CameraManipulator>
#include <osgGA/MatrixManipulator>
#include <osg/Quat>
namespace osgGA{
/**
FlightManipulator is a CameraManipulator which provides flight simulator-like
FlightManipulator is a MatrixManipulator which provides flight simulator-like
updating of the camera position & orientation. By default, the left mouse
button accelerates, the right mouse button decelerates, and the middle mouse
button (or left and right simultaneously) stops dead.
*/
class OSGGA_EXPORT FlightManipulator : public CameraManipulator
class OSGGA_EXPORT FlightManipulator : public MatrixManipulator
{
public:
@@ -33,6 +34,19 @@ class OSGGA_EXPORT FlightManipulator : public CameraManipulator
virtual const char* className() const { return "Flight"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
virtual void setNode(osg::Node*);
virtual const osg::Node* getNode() const;
@@ -65,9 +79,7 @@ class OSGGA_EXPORT FlightManipulator : public CameraManipulator
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computeLocalDataFromCamera();
void computeCameraFromLocalData();
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/

View File

@@ -62,7 +62,7 @@ public:
/**
requestContinousUpdate(bool) is for en/disabling a throw or idle
callback to be requested by a GUIEventHandler (typically a CameraManipulator,
callback to be requested by a GUIEventHandler (typically a MatrixManipulator,
though other GUIEventHandler's may also provide functionality).
GUI toolkits can respond to this immediately by registering an idle/timed
callback, or can delay setting the callback and update at their own leisure.

View File

@@ -23,7 +23,7 @@ namespace osgGA{
class GUIActionAdapter;
class GUIEventHandler;
class CompositeGUIEventHandler;
class CameraManipulator;
class MatrixManipulator;
class StateSetManipulator;
/**
@@ -42,7 +42,7 @@ class OSGGA_EXPORT GUIEventHandlerVisitor
virtual void visit(GUIEventHandler&) {}
virtual void visit(CompositeGUIEventHandler&);
virtual void visit(CameraManipulator&) {};
virtual void visit(MatrixManipulator&) {};
virtual void visit(StateSetManipulator&) {};
// Accessors

View File

@@ -11,11 +11,13 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGGA_CAMERAMANIPULATOR
#define OSGGA_CAMERAMANIPULATOR 1
#ifndef OSGGA_MatrixManipulator
#define OSGGA_MatrixManipulator 1
#include <osg/Camera>
#include <osg/Node>
#include <osg/Matrix>
#include <osgUtil/SceneView>
#include <osgGA/Export>
#include <osgGA/GUIEventHandler>
@@ -26,26 +28,36 @@ namespace osgGA{
/**
CameraManipulator is an abstract base class defining the interface, and a certain
MatrixManipulator is an abstract base class defining the interface, and a certain
amount of default functionality, for classes which wish to control OSG cameras
in response to GUI events.
*/
class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
class OSGGA_EXPORT MatrixManipulator : public GUIEventHandler
{
public:
virtual const char* className() const { return "CameraManipulator"; }
virtual const char* className() const { return "MatrixManipulator"; }
/** Attach a camera to the manipulator to be used for specifying view.*/
virtual void setCamera(osg::Camera*);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix) = 0;
/** Get the attached camera.*/
virtual const osg::Camera * getCamera() const;
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) = 0;
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const = 0;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const = 0;
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE; }
/** Get the FusionDistanceValue. Used by SceneView for setting up setereo convergence.*/
virtual float getFusionDistanceValue() const { return 1.0f; }
/** Get the attached camera.*/
virtual osg::Camera * getCamera();
/**
Attach a node to the manipulator, automatically detaching any previously attached node.
@@ -80,11 +92,8 @@ public:
protected:
CameraManipulator();
virtual ~CameraManipulator();
// Reference pointer to a camera
osg::ref_ptr<osg::Camera> _camera;
MatrixManipulator();
virtual ~MatrixManipulator();
};

View File

@@ -21,7 +21,7 @@ namespace osgGA{
// Some forward declarations
class GUIEventHandler;
class CameraManipulator;
class MatrixManipulator;
/**
SetSceneViewGUIEventHandlerVisitor which visits various types of
@@ -40,7 +40,7 @@ class OSGGA_EXPORT SetSceneViewVisitor: public GUIEventHandlerVisitor
virtual ~SetSceneViewVisitor() {}
virtual void visit(CameraManipulator& cm);
virtual void visit(MatrixManipulator& cm);
virtual void visit(StateSetManipulator& cm);
private:

View File

@@ -14,11 +14,12 @@
#ifndef OSGGA_TRACKBALLMANIPULATOR
#define OSGGA_TRACKBALLMANIPULATOR 1
#include <osgGA/CameraManipulator>
#include <osgGA/MatrixManipulator>
#include <osg/Quat>
namespace osgGA{
class OSGGA_EXPORT TrackballManipulator : public CameraManipulator
class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator
{
public:
@@ -26,6 +27,24 @@ class OSGGA_EXPORT TrackballManipulator : public CameraManipulator
virtual const char* className() const { return "Trackball"; }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix);
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { setByMatrix(osg::Matrix::inverse(matrix)); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix getMatrix() const;
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrix getInverseMatrix() const;
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
/** Get the FusionDistanceValue. Used by SceneView for setting up setereo convergence.*/
virtual float getFusionDistanceValue() const { return _distance; }
/** Attach a node to the manipulator.
Automatically detaches previously attached node.
setNode(NULL) detaches previously nodes.
@@ -60,9 +79,7 @@ class OSGGA_EXPORT TrackballManipulator : public CameraManipulator
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computeLocalDataFromCamera();
void computeCameraFromLocalData();
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
/** For the give mouse movement calculate the movement of the camera.
Return true is camera has moved and a redraw is required.*/

View File

@@ -23,7 +23,7 @@
#include <osgGA/GUIActionAdapter>
#include <osgGA/GUIEventHandler>
#include <osgGA/KeySwitchCameraManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgProducer/OsgCameraGroup>
#include <osgProducer/KeyboardMouseCallback>
@@ -117,10 +117,10 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
EventHandlerList& getEventHandlerList() { return _eventHandlerList; }
const EventHandlerList& getEventHandlerList() const { return _eventHandlerList; }
osgGA::KeySwitchCameraManipulator* getKeySwitchCameraManipulator() { return _keyswitchManipulator.get(); }
const osgGA::KeySwitchCameraManipulator* getKeySwitchCameraManipulator() const { return _keyswitchManipulator.get(); }
osgGA::KeySwitchMatrixManipulator* getKeySwitchMatrixManipulator() { return _keyswitchManipulator.get(); }
const osgGA::KeySwitchMatrixManipulator* getKeySwitchMatrixManipulator() const { return _keyswitchManipulator.get(); }
unsigned int addCameraManipulator(osgGA::CameraManipulator* cm);
unsigned int addCameraManipulator(osgGA::MatrixManipulator* cm);
void selectCameraManipulator(unsigned int no);
@@ -143,13 +143,10 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
osgProducer::KeyboardMouseCallback* _kbmcb;
EventHandlerList _eventHandlerList;
osg::ref_ptr<osgGA::KeySwitchCameraManipulator> _keyswitchManipulator;
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> _keyswitchManipulator;
osg::ref_ptr<osg::Camera> _old_style_osg_camera;
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
bool _recordingAnimationPath;
osg::ref_ptr<osg::AnimationPath> _animationPath;

View File

@@ -17,7 +17,6 @@
#include <osg/Node>
#include <osg/StateSet>
#include <osg/Light>
#include <osg/Camera>
#include <osg/FrameStamp>
#include <osg/DisplaySettings>
@@ -28,7 +27,7 @@ namespace osgUtil {
/**
* SceneView is literally a view of a scene, encapsulating the
* camera, global state, lights and the scene itself. Provides
* camera (modelview+projection matrices), global state, lights and the scene itself. Provides
* methods for setting up the view and rendering it.
*/
class OSGUTIL_EXPORT SceneView : public osg::Referenced
@@ -129,15 +128,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
const osg::State* getState() const { return _state.get(); }
/** set an osg::Camera for the scene view to use for setting projection and modelview matrices internaly.
* However, the projection matrix from the camera will be overriden by a projection matrix which is set explicitly
* via setProjectionMatrix(..), see below.
* Also, the model matrix from the camera will be overriden by a modelview matrix which is set explicitly
* via setModelViewMatrix(..), see below.*/
void setCamera(osg::Camera* camera) { _camera = camera; }
osg::Camera* getCamera() { return _camera.get(); }
const osg::Camera* getCamera() const { return _camera.get(); }
/** set a projection matrix. Note, this will override a camera's projection matrix if it is not NULL.*/
void setProjectionMatrix(osg::RefMatrix* matrix) { _projectionMatrix = matrix; }
osg::RefMatrix* getProjectionMatrix() { return _projectionMatrix.get(); }
@@ -206,8 +196,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
/** FusionDistanceMode is used only when working in stereo.*/
enum FusionDistanceMode
{
/** Use fusion distance from the attached camera if one exist.*/
USE_CAMERA_FUSION_DISTANCE,
/** Use fusion distance from the value set on the SceneView.*/
USE_FUSION_DISTANCE_VALUE,
/** Compute the fusion distance by multiplying the screen distance by the fusion distance value.*/
@@ -306,7 +294,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
osg::ref_ptr<osg::StateSet> _globalStateSet;
osg::ref_ptr<osg::StateSet> _localStateSet;
osg::ref_ptr<osg::Light> _light;
osg::ref_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::RefMatrix> _projectionMatrix;
osg::ref_ptr<osg::RefMatrix> _modelviewMatrix;
osg::ref_ptr<osg::DisplaySettings> _displaySettings;

View File

@@ -12,7 +12,6 @@ CXXFILES =\
BoundingBox.cpp\
BoundingSphere.cpp\
BlendFunc.cpp\
Camera.cpp\
ClipNode.cpp\
ClipPlane.cpp\
ColorMask.cpp\

View File

@@ -154,12 +154,5 @@ void AnimationPathManipulator::handleFrame( double time )
_numOfFramesSinceStartOfTimedPeriod = 0;
}
osg::Matrix matrix;
cp.getMatrix( matrix );
if (_camera.valid())
{
_camera->home();
_camera->transformLookAt(matrix);
}
cp.getMatrix( _matrix );
}

View File

@@ -1,37 +0,0 @@
#include <osg/GL>
#include <osg/Matrix>
#include <osgGA/CameraManipulator>
using namespace osg;
using namespace osgGA;
CameraManipulator::CameraManipulator(): _camera(NULL)
{
}
CameraManipulator::~CameraManipulator()
{
}
void CameraManipulator::setCamera(Camera *camera)
{
_camera=camera;
}
const Camera *CameraManipulator::getCamera() const
{
return _camera.get();
}
Camera *CameraManipulator::getCamera()
{
return _camera.get();
}
bool CameraManipulator::handle(const GUIEventAdapter&,GUIActionAdapter&)
{
return false;
}

View File

@@ -55,7 +55,7 @@ osg::Node* DriveManipulator::getNode()
void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(_node.get() && _camera.get())
if(_node.get())
{
const osg::BoundingSphere& boundingSphere=_node->getBound();
@@ -68,7 +68,7 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
// check to see if any obstruction in front.
osgUtil::IntersectVisitor iv;
bool cameraSet = false;
bool positionSet = false;
osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;
segDown->set(ep,bp);
@@ -89,22 +89,19 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (np.z()>0.0f) uv = np;
else uv = -np;
float lookDistance = _modelScale*0.1f;
ep = ip;
ep.z() += _height;
osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f);
osg::Vec3 cp = ep+lv*lookDistance;
_camera->setLookAt(ep,cp,uv);
computePosition(ep,lv,uv);
cameraSet = true;
positionSet = true;
}
}
if (!cameraSet)
if (!positionSet)
{
bp = ep;
bp.z() += _modelScale;
@@ -128,29 +125,23 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (np.z()>0.0f) uv = np;
else uv = -np;
float lookDistance = _modelScale*0.1f;
ep = ip;
ep.z() += _height;
osg::Vec3 lv = uv^osg::Vec3(1.0f,0.0f,0.0f);
osg::Vec3 cp = ep+lv*lookDistance;
computePosition(ep,lv,uv);
_camera->setLookAt(ep,cp,uv);
cameraSet = true;
positionSet = true;
}
}
}
if (!cameraSet)
if (!positionSet)
{
// eye
_camera->setLookAt(boundingSphere._center+osg::Vec3( 0.0,-2.0f * boundingSphere._radius,0.0f),
// look
boundingSphere._center,
// up
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));
}
@@ -163,8 +154,6 @@ void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
flushMouseEventStack();
computeLocalDataFromCamera();
}
void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
@@ -175,15 +164,18 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
_velocity = 0.0f;
osg::Vec3 ep = _camera->getEyePoint();
osg::Vec3 sv = _camera->getSideVector();
osg::Vec3 ep = _eye;
Matrix rotation_matrix;
_rotation.get(rotation_matrix);
osg::Vec3 sv = osg::Vec3(1.0f,0.0f,0.0f) * rotation_matrix;
osg::Vec3 bp = ep;
bp.z() -= _modelScale;
// check to see if any obstruction in front.
osgUtil::IntersectVisitor iv;
bool cameraSet = false;
bool positionSet = false;
osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;
segDown->set(ep,bp);
@@ -204,22 +196,18 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (np.z()>0.0f) uv = np;
else uv = -np;
float lookDistance = _modelScale*0.1f;
ep = ip+uv*_height;
osg::Vec3 lv = uv^sv;
osg::Vec3 lp = ep+lv*lookDistance;
_camera->setLookAt(ep,lp,uv);
_camera->ensureOrthogonalUpVector();
computePosition(ep,lv,uv);
cameraSet = true;
positionSet = true;
}
}
if (!cameraSet)
if (!positionSet)
{
bp = ep;
bp.z() += _modelScale;
@@ -243,16 +231,12 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
if (np.z()>0.0f) uv = np;
else uv = -np;
float lookDistance = _modelScale*0.1f;
ep = ip+uv*_height;
osg::Vec3 lv = uv^sv;
osg::Vec3 lp = ep+lv*lookDistance;
_camera->setLookAt(ep,lp,uv);
_camera->ensureOrthogonalUpVector();
computePosition(ep,lv,uv);
cameraSet = true;
positionSet = true;
}
@@ -263,15 +247,11 @@ void DriveManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
}
computeLocalDataFromCamera();
}
bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(!_camera.get()) return false;
switch(ea.getEventType())
{
case(GUIEventAdapter::PUSH):
@@ -330,16 +310,6 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
_speedMode = USE_MOUSE_BUTTONS_FOR_SPEED;
return true;
}
else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
return false;
}
@@ -365,8 +335,6 @@ bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
void DriveManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("Drive: Space","Reset the viewing position to home");
usage.addKeyboardMouseBinding("Drive: +","When in stereo, increase the fusion distance");
usage.addKeyboardMouseBinding("Drive: -","When in stereo, reduse the fusion distance");
usage.addKeyboardMouseBinding("Drive: q","Use mouse y for controlling speed");
usage.addKeyboardMouseBinding("Drive: a","Use mouse middle,right mouse buttons for speed");
}
@@ -385,40 +353,23 @@ void DriveManipulator::addMouseEvent(const GUIEventAdapter& ea)
_ga_t0 = &ea;
}
void DriveManipulator::computeLocalDataFromCamera()
void DriveManipulator::setByMatrix(const osg::Matrix& matrix)
{
// maths from gluLookAt/osg::Matrix::makeLookAt
osg::Vec3 f(_camera->getCenterPoint()-_camera->getEyePoint());
f.normalize();
osg::Vec3 s(f^_camera->getUpVector());
s.normalize();
osg::Vec3 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);
_eye = _camera->getEyePoint();
_distance = _camera->getLookDistance();
_rotation.set(rotation_matrix);
_rotation = _rotation.inverse();
_eye = matrix.getTrans();
_rotation.set(matrix);
}
void DriveManipulator::computeCameraFromLocalData()
osg::Matrix DriveManipulator::getMatrix() const
{
osg::Matrix new_rotation;
new_rotation.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * new_rotation;
osg::Vec3 center = (osg::Vec3(0.0f,0.0f,-_distance) * new_rotation) + _eye;
_camera->setLookAt(_eye,center,up);
return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye);
}
void DriveManipulator::computeCameraFromLocalData(const osg::Vec3& lv,const osg::Vec3& up)
osg::Matrix DriveManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse());
}
void DriveManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
{
osg::Vec3 f(lv);
f.normalize();
@@ -432,17 +383,14 @@ void DriveManipulator::computeCameraFromLocalData(const osg::Vec3& lv,const osg:
s[2], u[2], -f[2], 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
_eye = eye;
_rotation.set(rotation_matrix);
_rotation = _rotation.inverse();
computeCameraFromLocalData();
}
bool DriveManipulator::calcMovement()
{
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
@@ -564,7 +512,7 @@ bool DriveManipulator::calcMovement()
_eye = ip+up*_height;
lv = up^sv;
computeCameraFromLocalData(lv,up);
computePosition(_eye,lv,up);
return true;
@@ -601,7 +549,7 @@ bool DriveManipulator::calcMovement()
_eye = ip+up*_height;
lv = up^sv;
computeCameraFromLocalData(lv,up);
computePosition(_eye,lv,up);
return true;
}
@@ -616,7 +564,5 @@ bool DriveManipulator::calcMovement()
}
computeCameraFromLocalData();
return true;
}

View File

@@ -44,14 +44,14 @@ osg::Node* FlightManipulator::getNode()
void FlightManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(_node.get() && _camera.get())
if(_node.get())
{
const osg::BoundingSphere& boundingSphere=_node->getBound();
_camera->setLookAt(
computePosition(
boundingSphere._center+osg::Vec3( 0.0,-3.5f * boundingSphere._radius,0.0f),
boundingSphere._center,
osg::Vec3(0.0f,1.0f,0.0f),
osg::Vec3(0.0f,0.0f,1.0f));
_velocity = 0.0f;
@@ -60,8 +60,6 @@ void FlightManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
computeLocalDataFromCamera();
flushMouseEventStack();
}
@@ -81,15 +79,11 @@ void FlightManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
}
computeLocalDataFromCamera();
}
bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(!_camera.get()) return false;
switch(ea.getEventType())
{
case(GUIEventAdapter::PUSH):
@@ -138,16 +132,6 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
us.requestContinuousUpdate(false);
return true;
}
else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
else if (ea.getKey()=='q')
{
_yawMode = YAW_AUTOMATICALLY_WHEN_BANKED;
@@ -178,8 +162,6 @@ bool FlightManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
void FlightManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("Flight: Space","Reset the viewing position to home");
usage.addKeyboardMouseBinding("Flight: +","When in stereo, increase the fusion distance");
usage.addKeyboardMouseBinding("Flight: -","When in stereo, reduse the fusion distance");
usage.addKeyboardMouseBinding("Flight: q","Automatically yaw when banked (default)");
usage.addKeyboardMouseBinding("Flight: a","No yaw when banked");
}
@@ -198,43 +180,46 @@ void FlightManipulator::addMouseEvent(const GUIEventAdapter& ea)
}
void FlightManipulator::computeLocalDataFromCamera()
void FlightManipulator::setByMatrix(const osg::Matrix& matrix)
{
// maths from gluLookAt/osg::Matrix::makeLookAt
osg::Vec3 f(_camera->getCenterPoint()-_camera->getEyePoint());
_eye = matrix.getTrans();
_rotation.set(matrix);
_distance = 1.0f;
}
osg::Matrix FlightManipulator::getMatrix() const
{
return osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_eye);
}
osg::Matrix FlightManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_eye)*osg::Matrix::rotate(_rotation.inverse());
}
void FlightManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up)
{
osg::Vec3 f(lv);
f.normalize();
osg::Vec3 s(f^_camera->getUpVector());
osg::Vec3 s(f^up);
s.normalize();
osg::Vec3 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);
_eye = _camera->getEyePoint();
_distance = _camera->getLookDistance();
_eye = eye;
_distance = lv.length();
_rotation.set(rotation_matrix);
_rotation = _rotation.inverse();
}
void FlightManipulator::computeCameraFromLocalData()
{
osg::Matrix new_rotation;
new_rotation.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * new_rotation;
osg::Vec3 center = (osg::Vec3(0.0f,0.0f,-_distance) * new_rotation) + _eye;
_camera->setLookAt(_eye,center,up);
}
bool FlightManipulator::calcMovement()
{
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_SCREEN_DISTANCE);
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
@@ -311,7 +296,5 @@ bool FlightManipulator::calcMovement()
_eye += lv;
_rotation = _rotation*delta_rotate;
computeCameraFromLocalData();
return true;
}

View File

@@ -4,12 +4,12 @@ include $(TOPDIR)/Make/makedefs
CXXFILES = \
AnimationPathManipulator.cpp\
CameraManipulator.cpp\
MatrixManipulator.cpp\
DriveManipulator.cpp\
FlightManipulator.cpp\
GUIEventHandler.cpp\
GUIEventHandlerVisitor.cpp\
KeySwitchCameraManipulator.cpp\
KeySwitchMatrixManipulator.cpp\
SetSceneViewVisitor.cpp\
StateSetManipulator.cpp\
TrackballManipulator.cpp\

View File

@@ -0,0 +1,22 @@
#include <osg/GL>
#include <osg/Matrix>
#include <osgGA/MatrixManipulator>
using namespace osg;
using namespace osgGA;
MatrixManipulator::MatrixManipulator()
{
}
MatrixManipulator::~MatrixManipulator()
{
}
bool MatrixManipulator::handle(const GUIEventAdapter&,GUIActionAdapter&)
{
return false;
}

View File

@@ -1,11 +1,14 @@
#include <osgGA/SetSceneViewVisitor>
#include <osgGA/CameraManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/MatrixManipulator>
void osgGA::SetSceneViewVisitor::visit(osgGA::CameraManipulator& cm)
void osgGA::SetSceneViewVisitor::visit(osgGA::MatrixManipulator& cm)
{
cm.setNode(_sceneView->getSceneData());
cm.setCamera(_sceneView->getCamera());
if (_sceneView->getModelViewMatrix())
{
cm.setByInverseMatrix(*(_sceneView->getModelViewMatrix()));
}
cm.init(*getGUIEventAdapter(),*getGUIActionAdapter());
cm.home(*getGUIEventAdapter(),*getGUIActionAdapter());
}

View File

@@ -1,4 +1,5 @@
#include <osgGA/TrackballManipulator>
#include <osg/Quat>
#include <osg/Notify>
using namespace osg;
@@ -45,17 +46,15 @@ osg::Node* TrackballManipulator::getNode()
/*ea*/
void TrackballManipulator::home(const GUIEventAdapter& ,GUIActionAdapter& us)
{
if(_node.get() && _camera.get())
if(_node.get())
{
const osg::BoundingSphere& boundingSphere=_node->getBound();
_camera->setView(boundingSphere._center+osg::Vec3( 0.0,-3.5f * boundingSphere._radius,0.0f),
computePosition(boundingSphere._center+osg::Vec3( 0.0,-3.5f * boundingSphere._radius,0.0f),
boundingSphere._center,
osg::Vec3(0.0f,0.0f,1.0f));
computeLocalDataFromCamera();
us.requestRedraw();
}
@@ -65,8 +64,6 @@ void TrackballManipulator::home(const GUIEventAdapter& ,GUIActionAdapter& us)
void TrackballManipulator::init(const GUIEventAdapter& ,GUIActionAdapter& )
{
flushMouseEventStack();
computeLocalDataFromCamera();
}
@@ -79,8 +76,6 @@ void TrackballManipulator::getUsage(osg::ApplicationUsage& usage) const
bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(!_camera.get()) return false;
switch(ea.getEventType())
{
case(GUIEventAdapter::PUSH):
@@ -151,26 +146,9 @@ bool TrackballManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us
us.requestRedraw();
us.requestContinuousUpdate(false);
return true;
} else if (ea.getKey()=='+')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
else if (ea.getKey()=='-')
{
_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
// this is quick hack to test out othographic projection.
// else if (ea.getKey()=='O')
// {
// float dist = _camera->getLookDistance();
// _camera->setOrtho(-dist,dist,-dist,dist,-dist,dist);
// return true;
// }
return false;
case(GUIEventAdapter::FRAME):
_camera->setFusionDistanceMode(osg::Camera::PROPORTIONAL_TO_LOOK_DISTANCE);
if (_thrown)
{
if (calcMovement()) us.requestRedraw();
@@ -211,39 +189,48 @@ void TrackballManipulator::addMouseEvent(const GUIEventAdapter& ea)
_ga_t0 = &ea;
}
void TrackballManipulator::computeLocalDataFromCamera()
void TrackballManipulator::setByMatrix(const osg::Matrix& matrix)
{
// maths from gluLookAt/osg::Matrix::makeLookAt
osg::Vec3 f(_camera->getCenterPoint()-_camera->getEyePoint());
_center = osg::Vec3(0.0f,0.0f,-_distance)*matrix;//matrix.getTrans();
_rotation.set(matrix);
osg::Matrix rotation_matrix;
_rotation.get(rotation_matrix);
// _center -= osg::Vec3(0.0f,0.0f,_distance)*rotation_matrix;
}
osg::Matrix TrackballManipulator::getMatrix() const
{
return osg::Matrix::translate(0.0f,0.0f,_distance)*osg::Matrix::rotate(_rotation)*osg::Matrix::translate(_center);
}
osg::Matrix TrackballManipulator::getInverseMatrix() const
{
return osg::Matrix::translate(-_center)*osg::Matrix::rotate(_rotation.inverse())*osg::Matrix::translate(0.0f,0.0f,-_distance);
}
void TrackballManipulator::computePosition(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
{
osg::Vec3 lv(center-eye);
osg::Vec3 f(lv);
f.normalize();
osg::Vec3 s(f^_camera->getUpVector());
osg::Vec3 s(f^up);
s.normalize();
osg::Vec3 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);
_center = _camera->getCenterPoint();
_distance = _camera->getLookDistance();
_center = center;
_distance = lv.length();
_rotation.set(rotation_matrix);
_rotation = _rotation.inverse();
}
void TrackballManipulator::computeCameraFromLocalData()
{
osg::Matrix new_rotation;
new_rotation.makeRotate(_rotation);
osg::Vec3 up = osg::Vec3(0.0f,1.0f,0.0) * new_rotation;
osg::Vec3 eye = (osg::Vec3(0.0f,0.0f,_distance) * new_rotation) + _center;
_camera->setLookAt(eye,_center,up);
}
@@ -260,7 +247,6 @@ bool TrackballManipulator::calcMovement()
// return if there is no movement.
if (dx==0 && dy==0) return false;
float focalLength = (_camera->getCenterPoint()-_camera->getEyePoint()).length();
unsigned int buttonMask = _ga_t1->getButtonMask();
if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON)
{
@@ -284,8 +270,6 @@ bool TrackballManipulator::calcMovement()
_rotation = _rotation*new_rotate;
computeCameraFromLocalData();
return true;
}
@@ -295,16 +279,15 @@ bool TrackballManipulator::calcMovement()
// pan model.
float scale = -0.5f*focalLength;
float scale = -0.5f*_distance;
osg::Vec3 uv = _camera->getUpVector();
osg::Vec3 sv = _camera->getSideVector();
osg::Vec3 dv = uv*(dy*scale)+sv*(dx*scale);
osg::Matrix rotation_matrix;
_rotation.get(rotation_matrix);
_center += dv;
osg::Vec3 dv(dx*scale,dy*scale,0.0f);
_center += dv*rotation_matrix;
computeCameraFromLocalData();
return true;
}
@@ -313,15 +296,13 @@ bool TrackballManipulator::calcMovement()
// zoom model.
float fd = focalLength;
float fd = _distance;
float scale = 1.0f+dy;
if (fd*scale>_modelScale*_minimumZoomScale)
{
_distance *= scale;
computeCameraFromLocalData();
}
else
{
@@ -329,12 +310,14 @@ bool TrackballManipulator::calcMovement()
// notify(DEBUG_INFO) << "Pushing forward"<<std::endl;
// push the camera forward.
float scale = -fd;
osg::Vec3 dv = _camera->getLookVector()*(dy*scale);
osg::Matrix rotation_matrix;
_rotation.get(rotation_matrix);
osg::Vec3 dv = (osg::Vec3(0.0f,0.0f,-1.0f)*rotation_matrix)*(dy*scale);
_center += dv;
computeCameraFromLocalData();
}
return true;
@@ -373,9 +356,13 @@ void TrackballManipulator::trackball(osg::Vec3& axis,float& angle, float p1x, fl
* deformed sphere
*/
osg::Vec3 uv = _camera->getUpVector();
osg::Vec3 sv = _camera->getSideVector();
osg::Vec3 lv = _camera->getLookVector();
osg::Matrix rotation_matrix;
_rotation.get(rotation_matrix);
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::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);

View File

@@ -131,7 +131,7 @@ void OsgCameraGroup::_init()
_background_color.set( 0.2f, 0.2f, 0.4f, 1.0f );
_LODScale = 1.0f;
_fusionDistanceMode = osgUtil::SceneView::USE_CAMERA_FUSION_DISTANCE;
_fusionDistanceMode = osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE;
_fusionDistanceValue = 1.0f;
_initialized = false;

View File

@@ -235,9 +235,6 @@ void Viewer::setUpViewer(unsigned int options)
_updateVisitor = new osgUtil::UpdateVisitor;
_updateVisitor->setFrameStamp(_frameStamp.get());
// create a camera to use with the manipulators.
_old_style_osg_camera = new osg::Camera;
if (options&TRACKBALL_MANIPULATOR) addCameraManipulator(new osgGA::TrackballManipulator);
if (options&FLIGHT_MANIPULATOR) addCameraManipulator(new osgGA::FlightManipulator);
if (options&DRIVE_MANIPULATOR) addCameraManipulator(new osgGA::DriveManipulator);
@@ -256,19 +253,19 @@ void Viewer::setUpViewer(unsigned int options)
}
unsigned int Viewer::addCameraManipulator(osgGA::CameraManipulator* cm)
unsigned int Viewer::addCameraManipulator(osgGA::MatrixManipulator* cm)
{
if (!cm) return 0xfffff;
// create a key switch manipulator if one doesn't already exist.
if (!_keyswitchManipulator)
{
_keyswitchManipulator = new osgGA::KeySwitchCameraManipulator;
_keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
_eventHandlerList.push_back(_keyswitchManipulator.get());
}
unsigned int num = _keyswitchManipulator->getNumCameraManipualtors();
_keyswitchManipulator->addNumberedCameraManipulator(cm);
unsigned int num = _keyswitchManipulator->getNumMatrixManipualtors();
_keyswitchManipulator->addNumberedMatrixManipulator(cm);
return num;
}
@@ -282,17 +279,13 @@ void Viewer::setViewByMatrix( const Producer::Matrix & pm)
{
CameraGroup::setViewByMatrix(pm);
if (_keyswitchManipulator.valid() && _old_style_osg_camera.valid())
if (_keyswitchManipulator.valid())
{
// now convert Producer matrix to an osg::Matrix so we can update
// the internal camera...
osg::Matrix matrix(pm.ptr());
_old_style_osg_camera->home();
_old_style_osg_camera->transformLookAt(matrix);
osg::ref_ptr<osgProducer::EventAdapter> init_event = _kbmcb->createEventAdapter();
_keyswitchManipulator->init(*init_event,*this);
_keyswitchManipulator->setByInverseMatrix(matrix);
}
}
@@ -314,12 +307,11 @@ bool Viewer::realize()
// any work on them.
OsgCameraGroup::sync();
if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentCameraManipulator())
if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentMatrixManipulator())
{
osg::ref_ptr<osgProducer::EventAdapter> init_event = _kbmcb->createEventAdapter();
init_event->adaptFrame(0.0);
_keyswitchManipulator->setCamera(_old_style_osg_camera.get());
_keyswitchManipulator->setNode(getSceneDecorator());
_keyswitchManipulator->home(*init_event,*this);
}
@@ -329,7 +321,6 @@ bool Viewer::realize()
for(SceneHandlerList::iterator p=_shvec.begin(); p!=_shvec.end(); p++ )
{
(*p)->getState()->setAbortRenderingPtr(&_done);
(*p)->setCamera(_old_style_osg_camera.get());
}
return _realized;
@@ -371,9 +362,18 @@ void Viewer::update()
}
// update the main producer camera
if (_old_style_osg_camera.valid())
if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentMatrixManipulator())
{
CameraGroup::setViewByMatrix(Producer::Matrix(_old_style_osg_camera->getModelViewMatrix().ptr()));
osgGA::MatrixManipulator* mm = _keyswitchManipulator->getCurrentMatrixManipulator();
osg::Matrix matrix = mm->getInverseMatrix();
CameraGroup::setViewByMatrix(Producer::Matrix(matrix.ptr()));
for(SceneHandlerList::iterator p=_shvec.begin(); p!=_shvec.end(); p++ )
{
(*p)->setFusionDistance(mm->getFusionDistanceMode(),mm->getFusionDistanceValue());
}
}
}
@@ -505,7 +505,7 @@ bool Viewer::computeIntersections(float x,float y,osgUtil::IntersectVisitor::Hit
void Viewer::selectCameraManipulator(unsigned int no)
{
if (_keyswitchManipulator.valid()) _keyswitchManipulator->selectCameraManipulator(no);
if (_keyswitchManipulator.valid()) _keyswitchManipulator->selectMatrixManipulator(no);
}
void Viewer::requestWarpPointer(float x,float y)

View File

@@ -829,6 +829,16 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
return true;
}
case '+' :
{
//_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f);
return true;
}
case '-' :
{
//_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f);
return true;
}
case osgGA::GUIEventAdapter::KEY_Help :
case 'h' :
@@ -880,12 +890,12 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
osgGA::AnimationPathManipulator* apm = 0;
unsigned int apmNo = 0;
osgGA::KeySwitchCameraManipulator* kscm = viewer->getKeySwitchCameraManipulator();
osgGA::KeySwitchMatrixManipulator* kscm = viewer->getKeySwitchMatrixManipulator();
if (kscm)
{
for(apmNo=0;apmNo<kscm->getNumCameraManipualtors() && apm==0;++apmNo)
for(apmNo=0;apmNo<kscm->getNumMatrixManipualtors() && apm==0;++apmNo)
{
apm = dynamic_cast<osgGA::AnimationPathManipulator*>(kscm->getCameraManipulator(apmNo));
apm = dynamic_cast<osgGA::AnimationPathManipulator*>(kscm->getMatrixManipulator(apmNo));
}
}
@@ -930,4 +940,6 @@ void ViewerEventHandler::getUsage(osg::ApplicationUsage& usage) const
usage.addKeyboardMouseBinding("v","Toggle block and vsync");
usage.addKeyboardMouseBinding("z","Start recording camera path.");
usage.addKeyboardMouseBinding("Z","If recording camera path stop recording camera path, save to \"saved_animation.path\"\nThen start viewing from being on animation path");
// usage.addKeyboardMouseBinding("+","When in stereo, increase the fusion distance");
// usage.addKeyboardMouseBinding("-","When in stereo, reduse the fusion distance");
}

View File

@@ -40,7 +40,7 @@ SceneView::SceneView(DisplaySettings* ds)
_LODScale = 1.0f;
_smallFeatureCullingPixelSize = 3.0f;
_fusionDistanceMode = USE_CAMERA_FUSION_DISTANCE;
_fusionDistanceMode = PROPORTIONAL_TO_SCREEN_DISTANCE;
_fusionDistanceValue = 1.0f;
_lightingMode=HEADLIGHT;
@@ -76,8 +76,6 @@ void SceneView::setDefaults()
_state = new State;
_camera = new Camera(_displaySettings.get());
_rendergraph = new RenderGraph;
_renderStage = new RenderStage;
@@ -209,40 +207,7 @@ void SceneView::cull()
osg::ref_ptr<osg::RefMatrix> projection = _projectionMatrix.get();
osg::ref_ptr<osg::RefMatrix> modelview = _modelviewMatrix.get();
if (_camera.valid())
{
if (_displaySettings.valid() && _displaySettings->getStereo())
{
switch(_displaySettings->getStereoMode())
{
case(osg::DisplaySettings::HORIZONTAL_SPLIT):
_camera->adjustAspectRatio(0.5*_viewport->aspectRatio());
break;
case(osg::DisplaySettings::VERTICAL_SPLIT):
_camera->adjustAspectRatio(2*_viewport->aspectRatio());
break;
default:
_camera->adjustAspectRatio(_viewport->aspectRatio());
break;
}
}
else
{
_camera->adjustAspectRatio(_viewport->aspectRatio());
}
if (_displaySettings.valid())
_camera->setScreenDistance(_displaySettings->getScreenDistance());
if (!projection) projection = new osg::RefMatrix(_camera->getProjectionMatrix());
if (!modelview) modelview = new osg::RefMatrix(_camera->getModelViewMatrix());
//cout <<"fovx="<<_camera->calc_fovx()<<endl;
}
if (!projection) projection = new osg::RefMatrix();
if (!modelview) modelview = new osg::RefMatrix();
@@ -268,12 +233,6 @@ void SceneView::cull()
float fusionDistance = _displaySettings->getScreenDistance();
switch(_fusionDistanceMode)
{
case(USE_CAMERA_FUSION_DISTANCE):
if (_camera.valid())
{
fusionDistance = _camera->getFusionDistance();
}
break;
case(USE_FUSION_DISTANCE_VALUE):
fusionDistance = _fusionDistanceValue;
break;
@@ -305,11 +264,6 @@ void SceneView::cull()
_cullVisitor->setTraversalMask(_cullMaskLeft);
cullStage(projectionLeft.get(),modelviewLeft.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
if (_camera.valid() && _computeNearFar != CullVisitor::DO_NOT_COMPUTE_NEAR_FAR)
{
// clamp the camera to the near/far computed in cull traversal.
_camera->setNearFar(_cullVisitor->getCalculatedNearPlane(),_cullVisitor->getCalculatedFarPlane());
}
}
else if (_displaySettings->getStereoMode()==osg::DisplaySettings::RIGHT_EYE)
{
@@ -330,11 +284,6 @@ void SceneView::cull()
cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
if (_camera.valid() && _computeNearFar != CullVisitor::DO_NOT_COMPUTE_NEAR_FAR)
{
// clamp the camera to the near/far computed in cull traversal.
_camera->setNearFar(_cullVisitor->getCalculatedNearPlane(),_cullVisitor->getCalculatedFarPlane());
}
}
else
{
@@ -381,14 +330,7 @@ void SceneView::cull()
_cullVisitorRight->setTraversalMask(_cullMaskRight);
cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get());
if (_camera.valid() && _computeNearFar != CullVisitor::DO_NOT_COMPUTE_NEAR_FAR)
{
// clamp the camera to the near/far computed in cull traversal.
_camera->setNearFar(_cullVisitorRight->getCalculatedNearPlane(),_cullVisitorRight->getCalculatedFarPlane());
}
}
}
@@ -398,11 +340,6 @@ void SceneView::cull()
_cullVisitor->setTraversalMask(_cullMask);
cullStage(projection.get(),modelview.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get());
if (_camera.valid() && _computeNearFar != CullVisitor::DO_NOT_COMPUTE_NEAR_FAR)
{
// clamp the camera to the near/far computed in cull traversal.
_camera->setNearFar(_cullVisitor->getCalculatedNearPlane(),_cullVisitor->getCalculatedFarPlane());
}
}
@@ -708,7 +645,7 @@ void SceneView::draw()
break;
default:
{
osg::notify(osg::NOTICE)<<"Warning: stereo camera mode not implemented yet."<< std::endl;
osg::notify(osg::NOTICE)<<"Warning: stereo mode not implemented yet."<< std::endl;
}
break;
}
@@ -786,13 +723,9 @@ const osg::Matrix SceneView::computeMVPW() const
if (_modelviewMatrix.valid())
matrix = (*_modelviewMatrix);
else if (_camera.valid())
matrix = _camera->getModelViewMatrix();
if (_projectionMatrix.valid())
matrix.postMult(*_projectionMatrix);
else if (_camera.valid())
matrix.postMult(_camera->getProjectionMatrix());
if (_viewport.valid())
matrix.postMult(_viewport->computeWindowMatrix());