Changed the default home position so that it's consistent with other OSG manipulators. Added setter of properties of the SphericalManipualtor, moved across to using doubles internally
This commit is contained in:
parent
22fa18d585
commit
4d9d02e880
@ -26,6 +26,7 @@
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
#include <osgGA/TerrainManipulator>
|
||||
#include <osgGA/SphericalManipulator>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -84,9 +85,10 @@ int main(int argc, char** argv)
|
||||
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
|
||||
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
|
||||
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
|
||||
keyswitchManipulator->addMatrixManipulator( '5', "Spherical", new osgGA::SphericalManipulator() );
|
||||
|
||||
std::string pathfile;
|
||||
char keyForAnimationPath = '5';
|
||||
char keyForAnimationPath = '6';
|
||||
while (arguments.read("-p",pathfile))
|
||||
{
|
||||
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
|
||||
|
@ -64,11 +64,20 @@ class OSGGA_EXPORT SphericalManipulator : public MatrixManipulator
|
||||
|
||||
void computeViewPosition(const osg::BoundingSphere& bound,double& scale,double& distance,osg::Vec3d& center);
|
||||
|
||||
void setCenter(const osg::Vec3d& center) {_center=center;}
|
||||
const osg::Vec3d& getCenter() const {return _center;}
|
||||
|
||||
bool setDistance(double distance);
|
||||
double getDistance() const { return _distance; }
|
||||
|
||||
double getHomeDistance() const { return _homeDistance; }
|
||||
float getAzimuth() const {return _azimuth;}
|
||||
float getZenith() const {return _zenith;}
|
||||
|
||||
void setAzimuth(double azimuth) { _azimuth = azimuth; }
|
||||
double getAzimuth() const {return _azimuth;}
|
||||
|
||||
void setZenith(double zenith) { _zenith = zenith; }
|
||||
double getZenith() const {return _zenith;}
|
||||
|
||||
|
||||
/** get the minimum distance (as ratio) the eye point can be zoomed in */
|
||||
double getMinimumZoomScale() const { return _minimumZoomScale; }
|
||||
@ -77,6 +86,7 @@ class OSGGA_EXPORT SphericalManipulator : public MatrixManipulator
|
||||
center before the center is pushed forward.*/
|
||||
void setMinimumZoomScale(double minimumZoomScale) {_minimumZoomScale=minimumZoomScale;}
|
||||
|
||||
|
||||
/** set the mouse scroll wheel zoom delta.
|
||||
* Range -1.0 to +1.0, -ve value inverts wheel direction and zero switches off scroll wheel. */
|
||||
void setScroolWheelZoomDelta(double zoomDelta) { _zoomDelta = zoomDelta; }
|
||||
@ -84,13 +94,10 @@ class OSGGA_EXPORT SphericalManipulator : public MatrixManipulator
|
||||
/** get the mouse scroll wheel zoom delta. */
|
||||
double getScroolWheelZoomDelta() const { return _zoomDelta; }
|
||||
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
void setCenter(const osg::Vec3d ¢er) {_center=center;}
|
||||
bool setDistance(double distance);
|
||||
void setAngles(float azimuth,float zenith);
|
||||
|
||||
enum RotationMode
|
||||
{
|
||||
MODE_3D=0,
|
||||
@ -102,7 +109,7 @@ class OSGGA_EXPORT SphericalManipulator : public MatrixManipulator
|
||||
RotationMode getRotationMode() const {return _rotationMode;}
|
||||
void setRotationMode(RotationMode mode);
|
||||
|
||||
static double computeAngles(const osg::Vec3d &vec,float& azimuth,float& zenith);
|
||||
static double computeAngles(const osg::Vec3d &vec,double& azimuth,double& zenith);
|
||||
|
||||
protected:
|
||||
|
||||
@ -132,13 +139,13 @@ class OSGGA_EXPORT SphericalManipulator : public MatrixManipulator
|
||||
|
||||
bool _thrown;
|
||||
|
||||
RotationMode _rotationMode;
|
||||
osg::Vec3d _center;
|
||||
double _distance;
|
||||
float _azimuth; // angle from x axis in xy plane
|
||||
float _zenith; // angle from z axis
|
||||
double _homeDistance;
|
||||
float _zoomDelta;
|
||||
RotationMode _rotationMode;
|
||||
osg::Vec3d _center;
|
||||
double _distance;
|
||||
double _azimuth; // angle from x axis in xy plane
|
||||
double _zenith; // angle from z axis
|
||||
double _homeDistance;
|
||||
double _zoomDelta;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
@ -19,7 +19,7 @@ SphericalManipulator::SphericalManipulator()
|
||||
|
||||
_zoomDelta = 0.1f;
|
||||
_azimuth=0;
|
||||
_zenith=0;
|
||||
_zenith=osg::PI_2;
|
||||
|
||||
setRotationMode(MODE_3D);
|
||||
}
|
||||
@ -69,13 +69,7 @@ bool SphericalManipulator::setDistance(double distance)
|
||||
|
||||
return true;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void SphericalManipulator::setAngles(float azimuth,float zenith)
|
||||
{
|
||||
_azimuth=azimuth;
|
||||
if(_rotationMode != MODE_2D)
|
||||
_zenith=zenith;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void SphericalManipulator::home(double /*currentTime*/)
|
||||
{
|
||||
@ -83,7 +77,7 @@ void SphericalManipulator::home(double /*currentTime*/)
|
||||
computeHomePosition();
|
||||
|
||||
_azimuth=3*PI_2;
|
||||
_zenith=0;
|
||||
_zenith=PI_2;
|
||||
_center=_homeCenter;
|
||||
_distance=_homeDistance;
|
||||
|
||||
@ -221,7 +215,7 @@ bool SphericalManipulator::isMouseMoving()
|
||||
{
|
||||
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
|
||||
|
||||
static const float velocity = 0.1f;
|
||||
const float velocity = 0.1f;
|
||||
|
||||
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
|
||||
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
|
||||
@ -269,12 +263,14 @@ osg::Matrixd SphericalManipulator::getInverseMatrix() const
|
||||
osg::Matrixd::translate(osg::Vec3d(0,0,-_distance));
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double SphericalManipulator::computeAngles(const osg::Vec3d &vec,float& azimuth,float& zenith)
|
||||
double SphericalManipulator::computeAngles(const osg::Vec3d &vec,double& azimuth,double& zenith)
|
||||
{
|
||||
osg::Vec3d lv(vec);
|
||||
double distance=lv.length();
|
||||
if(distance > 0)
|
||||
lv/=distance;
|
||||
if(distance > 0.0)
|
||||
{
|
||||
lv /= distance;
|
||||
}
|
||||
|
||||
azimuth=atan2(lv.y(),lv.x());
|
||||
zenith=acos(lv.z());
|
||||
@ -389,8 +385,8 @@ bool SphericalManipulator::calcMovement()
|
||||
|
||||
// zoom model.
|
||||
|
||||
float fd = _distance;
|
||||
float scale = 1.0f+dy;
|
||||
double fd = _distance;
|
||||
double scale = 1.0+dy;
|
||||
if(fd*scale > _modelScale*_minimumZoomScale)
|
||||
{
|
||||
_distance *= scale;
|
||||
@ -404,7 +400,7 @@ bool SphericalManipulator::calcMovement()
|
||||
osg::Matrix rotation_matrix=osg::Matrixd::rotate(_zenith,1,0,0)*
|
||||
osg::Matrixd::rotate(PI_2+_azimuth,0,0,1);
|
||||
|
||||
osg::Vec3 dv = (osg::Vec3(0.0f,0.0f,-1.0f)*rotation_matrix)*(dy*scale);
|
||||
osg::Vec3d dv = (osg::Vec3d(0.0f,0.0f,-1.0f)*rotation_matrix)*(dy*scale);
|
||||
|
||||
_center += dv;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user