MovementMgr.cpp   StelMovementMgr.cpp 
skipping to change at line 20 skipping to change at line 20
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "MovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "Navigator.hpp" #include "StelNavigator.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include <QString> #include <QString>
#include <QTextStream> #include <QTextStream>
#include <QSettings> #include <QSettings>
#include <QKeyEvent> #include <QKeyEvent>
#include <QDebug> #include <QDebug>
MovementMgr::MovementMgr(StelCore* acore) : core(acore), StelMovementMgr::StelMovementMgr(StelCore* acore) : core(acore),
flagLockEquPos(false), flagLockEquPos(false),
flagTracking(false), flagTracking(false),
isMouseMovingHoriz(false), isMouseMovingHoriz(false),
isMouseMovingVert(false), isMouseMovingVert(false),
flagEnableMouseNavigation(true), flagEnableMouseNavigation(true),
keyMoveSpeed(0.00025), keyMoveSpeed(0.00025),
flagMoveSlow(false),
flagAutoMove(0), flagAutoMove(0),
deltaFov(0.), deltaFov(0.),
deltaAlt(0.), deltaAlt(0.),
deltaAz(0.), deltaAz(0.),
flagAutoZoom(0), flagAutoZoom(0),
flagAutoZoomOutResetsDirection(0) flagAutoZoomOutResetsDirection(0)
{ {
setObjectName("MovementMgr"); setObjectName("StelMovementMgr");
isDragging = false; isDragging = false;
} }
MovementMgr::~MovementMgr() StelMovementMgr::~StelMovementMgr()
{ {
} }
void MovementMgr::init() void StelMovementMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
assert(conf); Q_ASSERT(conf);
flagEnableMoveAtScreenEdge = conf->value("navigation/flag_enable_mov e_at_screen_edge",false).toBool(); flagEnableMoveAtScreenEdge = conf->value("navigation/flag_enable_mov e_at_screen_edge",false).toBool();
mouseZoomSpeed = conf->value("navigation/mouse_zoom",30).toInt(); mouseZoomSpeed = conf->value("navigation/mouse_zoom",30).toInt();
flagEnableZoomKeys = conf->value("navigation/flag_enable_zoom_keys") .toBool(); flagEnableZoomKeys = conf->value("navigation/flag_enable_zoom_keys") .toBool();
flagEnableMoveKeys = conf->value("navigation/flag_enable_move_keys") .toBool(); flagEnableMoveKeys = conf->value("navigation/flag_enable_move_keys") .toBool();
keyMoveSpeed = conf->value("navigation/move_speed",0.0004).toDouble( ); keyMoveSpeed = conf->value("navigation/move_speed",0.0004).toDouble( );
keyZoomSpeed = conf->value("navigation/zoom_speed", 0.0004).toDouble (); keyZoomSpeed = conf->value("navigation/zoom_speed", 0.0004).toDouble ();
autoMoveDuration = conf->value ("navigation/auto_move_duration",1.5) .toDouble(); autoMoveDuration = conf->value ("navigation/auto_move_duration",1.5) .toDouble();
flagManualZoom = conf->value("navigation/flag_manual_zoom").toBool() ; flagManualZoom = conf->value("navigation/flag_manual_zoom").toBool() ;
flagAutoZoomOutResetsDirection = conf->value("navigation/auto_zoom_o ut_resets_direction", true).toBool(); flagAutoZoomOutResetsDirection = conf->value("navigation/auto_zoom_o ut_resets_direction", true).toBool();
flagEnableMouseNavigation = conf->value("navigation/flag_enable_mous e_navigation",true).toBool(); flagEnableMouseNavigation = conf->value("navigation/flag_enable_mous e_navigation",true).toBool();
minFov = 0.0001;
maxFov = 100.;
initFov = conf->value("navigation/init_fov",60.).toDouble();
currentFov = initFov;
} }
bool MovementMgr::handleMouseMoves(int x, int y, Qt::MouseButtons b) bool StelMovementMgr::handleMouseMoves(int x, int y, Qt::MouseButtons b)
{ {
// Turn if the mouse is at the edge of the screen unless config asks otherwise // Turn if the mouse is at the edge of the screen unless config asks otherwise
if (flagEnableMoveAtScreenEdge) if (flagEnableMoveAtScreenEdge)
{ {
if (x <= 1) if (x <= 1)
{ {
turnLeft(1); turnLeft(1);
isMouseMovingHoriz = true; isMouseMovingHoriz = true;
} }
else if (x >= core->getProjection()->getViewportWidth() - 2) else if (x >= core->getProjection2d()->getViewportWidth() - 2)
{ {
turnRight(1); turnRight(1);
isMouseMovingHoriz = true; isMouseMovingHoriz = true;
} }
else if (isMouseMovingHoriz) else if (isMouseMovingHoriz)
{ {
turnLeft(0); turnLeft(0);
isMouseMovingHoriz = false; isMouseMovingHoriz = false;
} }
if (y <= 1) if (y <= 1)
{ {
turnUp(1); turnUp(1);
isMouseMovingVert = true; isMouseMovingVert = true;
} }
else if (y >= core->getProjection()->getViewportHeight() - 2 ) else if (y >= core->getProjection2d()->getViewportHeight() - 2)
{ {
turnDown(1); turnDown(1);
isMouseMovingVert = true; isMouseMovingVert = true;
} }
else if (isMouseMovingVert) else if (isMouseMovingVert)
{ {
turnUp(0); turnUp(0);
isMouseMovingVert = false; isMouseMovingVert = false;
} }
} }
skipping to change at line 125 skipping to change at line 131
setFlagTracking(false); setFlagTracking(false);
dragView(previousX, previousY, x, y); dragView(previousX, previousY, x, y);
previousX = x; previousX = x;
previousY = y; previousY = y;
return true; return true;
} }
} }
return false; return false;
} }
void MovementMgr::handleKeys(QKeyEvent* event) void StelMovementMgr::handleKeys(QKeyEvent* event)
{ {
if (event->type() == QEvent::KeyPress) if (event->type() == QEvent::KeyPress)
{ {
// Direction and zoom deplacements // Direction and zoom deplacements
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
turnLeft(true); break; turnLeft(true); break;
case Qt::Key_Right: case Qt::Key_Right:
turnRight(true); break; turnRight(true); break;
skipping to change at line 148 skipping to change at line 154
else turnUp(true); else turnUp(true);
break; break;
case Qt::Key_Down: case Qt::Key_Down:
if (event->modifiers().testFlag(Qt::ControlM odifier)) zoomOut(true); if (event->modifiers().testFlag(Qt::ControlM odifier)) zoomOut(true);
else turnDown(true); else turnDown(true);
break; break;
case Qt::Key_PageUp: case Qt::Key_PageUp:
zoomIn(true); break; zoomIn(true); break;
case Qt::Key_PageDown: case Qt::Key_PageDown:
zoomOut(true); break; zoomOut(true); break;
case Qt::Key_Shift:
moveSlow(true); break;
default: default:
return; return;
} }
} }
else else
{ {
// When a deplacement key is released stop mooving // When a deplacement key is released stop mooving
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Left: case Qt::Key_Left:
skipping to change at line 173 skipping to change at line 181
turnUp(false); turnUp(false);
break; break;
case Qt::Key_Down: case Qt::Key_Down:
zoomOut(false); zoomOut(false);
turnDown(false); turnDown(false);
break; break;
case Qt::Key_PageUp: case Qt::Key_PageUp:
zoomIn(false); break; zoomIn(false); break;
case Qt::Key_PageDown: case Qt::Key_PageDown:
zoomOut(false); break; zoomOut(false); break;
case Qt::Key_Shift:
moveSlow(false); break;
default: default:
return; return;
} }
} }
event->accept(); event->accept();
} }
//! Handle mouse wheel events. //! Handle mouse wheel events.
void MovementMgr::handleMouseWheel(QWheelEvent* event) void StelMovementMgr::handleMouseWheel(QWheelEvent* event)
{ {
if (flagEnableMouseNavigation==false) if (flagEnableMouseNavigation==false)
return; return;
int numDegrees = event->delta() / 8; int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15; int numSteps = numDegrees / 15;
zoomTo(getAimFov()-mouseZoomSpeed*numSteps*getAimFov()/60., 0.2); zoomTo(getAimFov()-mouseZoomSpeed*numSteps*getAimFov()/60., 0.2);
event->accept(); event->accept();
} }
void MovementMgr::handleMouseClicks(QMouseEvent* event) void StelMovementMgr::handleMouseClicks(QMouseEvent* event)
{ {
switch (event->button()) switch (event->button())
{ {
case Qt::RightButton : break; case Qt::RightButton : break;
case Qt::LeftButton : case Qt::LeftButton :
if (event->type()==QEvent::MouseButtonPress) if (event->type()==QEvent::MouseButtonPress)
{ {
isDragging = true; isDragging = true;
hasDragged = false; hasDragged = false;
previousX = event->x(); previousX = event->x();
skipping to change at line 226 skipping to change at line 236
else else
return; return;
} }
} }
break; break;
case Qt::MidButton : case Qt::MidButton :
if (event->type()==QEvent::MouseButtonRelease) if (event->type()==QEvent::MouseButtonRelease)
{ {
if (StelApp::getInstance().getStelObjectMgr( ).getWasSelected()) if (StelApp::getInstance().getStelObjectMgr( ).getWasSelected())
{ {
moveTo(StelApp::getInstance().getSte lObjectMgr().getSelectedObject()[0]->getObsEquatorialPos(core->getNavigatio n()),autoMoveDuration); moveTo(StelApp::getInstance().getSte lObjectMgr().getSelectedObject()[0]->getEquinoxEquatorialPos(core->getNavig ator()),autoMoveDuration);
setFlagTracking(true); setFlagTracking(true);
} }
} }
break; break;
default: break; default: break;
} }
return; return;
} }
/************************************************************************* /*************************************************************************
The selected objects changed, follow it it we were already following anoth er one The selected objects changed, follow it it we were already following anoth er one
*************************************************************************/ *************************************************************************/
void MovementMgr::selectedObjectChangeCallBack(StelModuleSelectAction actio n) void StelMovementMgr::selectedObjectChangeCallBack(StelModuleSelectAction a ction)
{ {
// If an object was selected keep the earth following // If an object was selected keep the earth following
if (StelApp::getInstance().getStelObjectMgr().getWasSelected()) if (StelApp::getInstance().getStelObjectMgr().getWasSelected())
{ {
if (getFlagTracking()) if (getFlagTracking())
setFlagLockEquPos(true); setFlagLockEquPos(true);
setFlagTracking(false); setFlagTracking(false);
} }
} }
void MovementMgr::turnRight(bool s) void StelMovementMgr::turnRight(bool s)
{ {
if (s && flagEnableMoveKeys) if (s && flagEnableMoveKeys)
{ {
deltaAz = 1; deltaAz = 1;
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
else else
deltaAz = 0; deltaAz = 0;
} }
void MovementMgr::turnLeft(bool s) void StelMovementMgr::turnLeft(bool s)
{ {
if (s && flagEnableMoveKeys) if (s && flagEnableMoveKeys)
{ {
deltaAz = -1; deltaAz = -1;
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
else else
deltaAz = 0; deltaAz = 0;
} }
void MovementMgr::turnUp(bool s) void StelMovementMgr::turnUp(bool s)
{ {
if (s && flagEnableMoveKeys) if (s && flagEnableMoveKeys)
{ {
deltaAlt = 1; deltaAlt = 1;
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
else else
deltaAlt = 0; deltaAlt = 0;
} }
void MovementMgr::turnDown(bool s) void StelMovementMgr::turnDown(bool s)
{ {
if (s && flagEnableMoveKeys) if (s && flagEnableMoveKeys)
{ {
deltaAlt = -1; deltaAlt = -1;
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
else else
deltaAlt = 0; deltaAlt = 0;
} }
void MovementMgr::zoomIn(bool s) void StelMovementMgr::zoomIn(bool s)
{ {
if (flagEnableZoomKeys) if (flagEnableZoomKeys)
deltaFov = -1*(s!=0); deltaFov = -1*(s!=0);
} }
void MovementMgr::zoomOut(bool s) void StelMovementMgr::zoomOut(bool s)
{ {
if (flagEnableZoomKeys) if (flagEnableZoomKeys)
deltaFov = (s!=0); deltaFov = (s!=0);
} }
// Increment/decrement smoothly the vision field and position // Increment/decrement smoothly the vision field and position
void MovementMgr::updateMotion(double deltaTime) void StelMovementMgr::updateMotion(double deltaTime)
{ {
Projector* proj = core->getProjection(); const StelProjectorP proj = core->getProjection(StelCore::FrameJ2000 );
updateVisionVector(deltaTime); updateVisionVector(deltaTime);
// the more it is zoomed, the lower the moving speed is (in angle) // the more it is zoomed, the lower the moving speed is (in angle)
double depl=keyMoveSpeed*deltaTime*1000*proj->getFov(); double depl=keyMoveSpeed*deltaTime*1000*currentFov;
double deplzoom=keyZoomSpeed*deltaTime*1000*proj->getCurrentMapping( double deplzoom=keyZoomSpeed*deltaTime*1000*proj->deltaZoom(currentF
).deltaZoom(proj->getFov()*(M_PI/360.0))*(360.0/M_PI); ov*(M_PI/360.0))*(360.0/M_PI);
if (flagMoveSlow)
{
depl *= 0.2;
deplzoom *= 0.2;
}
if (deltaAz<0) if (deltaAz<0)
{ {
deltaAz = -depl/30; deltaAz = -depl/30;
if (deltaAz<-0.2) if (deltaAz<-0.2)
deltaAz = -0.2; deltaAz = -0.2;
} }
else else
{ {
if (deltaAz>0) if (deltaAz>0)
skipping to change at line 355 skipping to change at line 371
{ {
deltaAlt = depl/30; deltaAlt = depl/30;
if (deltaAlt>0.2) if (deltaAlt>0.2)
deltaAlt = 0.2; deltaAlt = 0.2;
} }
} }
if (deltaFov<0) if (deltaFov<0)
{ {
deltaFov = -deplzoom*5; deltaFov = -deplzoom*5;
if (deltaFov<-0.15*proj->getFov()) if (deltaFov<-0.15*currentFov)
deltaFov = -0.15*proj->getFov(); deltaFov = -0.15*currentFov;
} }
else else
{ {
if (deltaFov>0) if (deltaFov>0)
{ {
deltaFov = deplzoom*5; deltaFov = deplzoom*5;
if (deltaFov>20) if (deltaFov>20)
deltaFov = 20; deltaFov = 20;
} }
} }
if (deltaFov != 0 ) if (deltaFov != 0 )
{ {
changeFov(deltaFov); changeFov(deltaFov);
} }
panView(deltaAz, deltaAlt); panView(deltaAz, deltaAlt);
updateAutoZoom(deltaTime); updateAutoZoom(deltaTime);
} }
// Go and zoom to the selected object. // Go and zoom to the selected object.
void MovementMgr::autoZoomIn(float moveDuration, bool allowManualZoom) void StelMovementMgr::autoZoomIn(float moveDuration, bool allowManualZoom)
{ {
Projector* proj = core->getProjection();
if (!StelApp::getInstance().getStelObjectMgr().getWasSelected()) if (!StelApp::getInstance().getStelObjectMgr().getWasSelected())
return; return;
float manualMoveDuration; float manualMoveDuration;
if (!getFlagTracking()) if (!getFlagTracking())
{ {
setFlagTracking(true); setFlagTracking(true);
moveTo(StelApp::getInstance().getStelObjectMgr().getSelected Object()[0]->getObsEquatorialPos(core->getNavigation()), moveDuration, fals e, 1); moveTo(StelApp::getInstance().getStelObjectMgr().getSelected Object()[0]->getEquinoxEquatorialPos(core->getNavigator()), moveDuration, f alse, 1);
manualMoveDuration = moveDuration; manualMoveDuration = moveDuration;
} }
else else
{ {
// faster zoom in manual zoom mode once object is centered // faster zoom in manual zoom mode once object is centered
manualMoveDuration = moveDuration*.66f; manualMoveDuration = moveDuration*.66f;
} }
if( allowManualZoom && flagManualZoom ) if( allowManualZoom && flagManualZoom )
{ {
// if manual zoom mode, user can zoom in incrementally // if manual zoom mode, user can zoom in incrementally
float newfov = proj->getFov()*0.5f; float newfov = currentFov*0.5f;
zoomTo(newfov, manualMoveDuration); zoomTo(newfov, manualMoveDuration);
} }
else else
{ {
float satfov = StelApp::getInstance().getStelObjectMgr().get SelectedObject()[0]->getSatellitesFov(core->getNavigation()); float satfov = StelApp::getInstance().getStelObjectMgr().get SelectedObject()[0]->getSatellitesFov(core->getNavigator());
if (satfov>0.0 && proj->getFov()*0.9>satfov) if (satfov>0.0 && currentFov*0.9>satfov)
zoomTo(satfov, moveDuration); zoomTo(satfov, moveDuration);
else else
{ {
float closefov = StelApp::getInstance().getStelObjec float closefov = StelApp::getInstance().getStelObjec
tMgr().getSelectedObject()[0]->getCloseViewFov(core->getNavigation()); tMgr().getSelectedObject()[0]->getCloseViewFov(core->getNavigator());
if (proj->getFov()>closefov) if (currentFov>closefov)
zoomTo(closefov, moveDuration); zoomTo(closefov, moveDuration);
} }
} }
} }
// Unzoom and go to the init position // Unzoom and go to the init position
void MovementMgr::autoZoomOut(float moveDuration, bool full) void StelMovementMgr::autoZoomOut(float moveDuration, bool full)
{ {
Navigator* nav = core->getNavigation(); StelNavigator* nav = core->getNavigator();
Projector* proj = core->getProjection();
if (StelApp::getInstance().getStelObjectMgr().getWasSelected() && !f ull) if (StelApp::getInstance().getStelObjectMgr().getWasSelected() && !f ull)
{ {
// If the selected object has satellites, unzoom to satellit es view // If the selected object has satellites, unzoom to satellit es view
// unless specified otherwise // unless specified otherwise
float satfov = StelApp::getInstance().getStelObjectMgr().get SelectedObject()[0]->getSatellitesFov(core->getNavigation()); float satfov = StelApp::getInstance().getStelObjectMgr().get SelectedObject()[0]->getSatellitesFov(core->getNavigator());
if (satfov>0.0 && proj->getFov()<=satfov*0.9) if (satfov>0.0 && currentFov<=satfov*0.9)
{ {
zoomTo(satfov, moveDuration); zoomTo(satfov, moveDuration);
return; return;
} }
// If the selected object is part of a Planet subsystem (oth er than sun), // If the selected object is part of a Planet subsystem (oth er than sun),
// unzoom to subsystem view // unzoom to subsystem view
satfov = StelApp::getInstance().getStelObjectMgr().getSelect satfov = StelApp::getInstance().getStelObjectMgr().getSelect
edObject()[0]->getParentSatellitesFov((core->getNavigation())); edObject()[0]->getParentSatellitesFov((core->getNavigator()));
if (satfov>0.0 && proj->getFov()<=satfov*0.9) if (satfov>0.0 && currentFov<=satfov*0.9)
{ {
zoomTo(satfov, moveDuration); zoomTo(satfov, moveDuration);
return; return;
} }
} }
zoomTo(proj->getInitFov(), moveDuration); zoomTo(initFov, moveDuration);
if (flagAutoZoomOutResetsDirection) if (flagAutoZoomOutResetsDirection)
moveTo(nav->getInitViewingDirection(), moveDuration, true, - 1); moveTo(nav->getInitViewingDirection(), moveDuration, true, - 1);
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
void MovementMgr::setFlagTracking(bool b) void StelMovementMgr::setFlagTracking(bool b)
{ {
if(!b || !StelApp::getInstance().getStelObjectMgr().getWasSelected() ) if(!b || !StelApp::getInstance().getStelObjectMgr().getWasSelected() )
{ {
flagTracking=false; flagTracking=false;
} }
else else
{ {
moveTo(StelApp::getInstance().getStelObjectMgr().getSelected Object()[0]->getObsEquatorialPos(core->getNavigation()), getAutoMoveDuratio n()); moveTo(StelApp::getInstance().getStelObjectMgr().getSelected Object()[0]->getEquinoxEquatorialPos(core->getNavigator()), getAutoMoveDura tion());
flagTracking=true; flagTracking=true;
} }
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Move to the given equatorial position // Move to the given equatorial position
void MovementMgr::moveTo(const Vec3d& _aim, float moveDuration, bool _local Pos, int zooming) void StelMovementMgr::moveTo(const Vec3d& _aim, float moveDuration, bool _l ocalPos, int zooming)
{ {
Navigator* nav = core->getNavigation(); StelNavigator* nav = core->getNavigator();
zoomingMode = zooming; zoomingMode = zooming;
move.aim=_aim; move.aim=_aim;
move.aim.normalize(); move.aim.normalize();
move.aim*=2.; move.aim*=2.;
if (_localPos) if (_localPos)
{ {
move.start=nav->getLocalVision(); move.start=nav->getAltAzVisionDirection();
} }
else else
{ {
move.start=nav->getEquVision(); move.start=nav->getEquinoxEquVisionDirection();
} }
move.start.normalize(); move.start.normalize();
move.speed=1.f/(moveDuration*1000); move.speed=1.f/(moveDuration*1000);
move.coef=0.; move.coef=0.;
move.localPos = _localPos; move.localPos = _localPos;
flagAutoMove = true; flagAutoMove = true;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
void MovementMgr::updateVisionVector(double deltaTime) void StelMovementMgr::updateVisionVector(double deltaTime)
{ {
Navigator* nav = core->getNavigation(); StelNavigator* nav = core->getNavigator();
if (flagAutoMove) if (flagAutoMove)
{ {
double ra_aim, de_aim, ra_start, de_start, ra_now, de_now; double ra_aim, de_aim, ra_start, de_start, ra_now, de_now;
if( zoomingMode == 1 && StelApp::getInstance().getStelObject Mgr().getWasSelected()) if( zoomingMode == 1 && StelApp::getInstance().getStelObject Mgr().getWasSelected())
{ {
// if zooming in, object may be moving so be sure to zoom to latest position // if zooming in, object may be moving so be sure to zoom to latest position
move.aim = StelApp::getInstance().getStelObjectMgr() .getSelectedObject()[0]->getObsEquatorialPos(core->getNavigation()); move.aim = StelApp::getInstance().getStelObjectMgr() .getSelectedObject()[0]->getEquinoxEquatorialPos(core->getNavigator());
move.aim.normalize(); move.aim.normalize();
move.aim*=2.; move.aim*=2.;
} }
// Use a smooth function // Use a smooth function
float smooth = 4.f; float smooth = 4.f;
double c; double c;
if (zoomingMode == 1) if (zoomingMode == 1)
{ {
skipping to change at line 532 skipping to change at line 545
else if(zoomingMode == -1) else if(zoomingMode == -1)
{ {
if( move.coef < 0.1 ) if( move.coef < 0.1 )
{ {
// keep in view at first as zoom out // keep in view at first as zoom out
c = 0; c = 0;
/* could track as moves too, but would need to know if start was actually /* could track as moves too, but would need to know if start was actually
a zoomed in view on the object or an extr aneous zoom out command a zoomed in view on the object or an extr aneous zoom out command
if(move.localPos) { if(move.localPos) {
move.start=earthEquToLocal(selected.getOb sEquatorialPos(this)); move.start=equinoxEquToAltAz(selected.get EquinoxEquatorialPos(this));
} else { } else {
move.start=selected.getObsEquatorialPos(t his); move.start=selected.getEquinoxEquatorialP os(this);
} }
move.start.normalize(); move.start.normalize();
*/ */
} }
else else
{ {
c = pow(1.11*(move.coef-.1),3); c = pow(1.11*(move.coef-.1),3);
} }
} }
else c = std::atan(smooth * 2.*move.coef-smooth)/std::atan(s mooth)/2+0.5; else c = std::atan(smooth * 2.*move.coef-smooth)/std::atan(s mooth)/2+0.5;
if (move.localPos) if (move.localPos)
{ {
StelUtils::rectToSphe(&ra_aim, &de_aim, move.aim); StelUtils::rectToSphe(&ra_aim, &de_aim, move.aim);
StelUtils::rectToSphe(&ra_start, &de_start, move.sta rt); StelUtils::rectToSphe(&ra_start, &de_start, move.sta rt);
} }
else else
{ {
StelUtils::rectToSphe(&ra_aim, &de_aim, nav->earthEq StelUtils::rectToSphe(&ra_aim, &de_aim, nav->equinox
uToLocal(move.aim)); EquToAltAz(move.aim));
StelUtils::rectToSphe(&ra_start, &de_start, nav->ear StelUtils::rectToSphe(&ra_start, &de_start, nav->equ
thEquToLocal(move.start)); inoxEquToAltAz(move.start));
} }
// Trick to choose the good moving direction and never trave l on a distance > PI // Trick to choose the good moving direction and never trave l on a distance > PI
if (ra_aim-ra_start > M_PI) if (ra_aim-ra_start > M_PI)
{ {
ra_aim -= 2.*M_PI; ra_aim -= 2.*M_PI;
} }
else if (ra_aim-ra_start < -M_PI) else if (ra_aim-ra_start < -M_PI)
{ {
ra_aim += 2.*M_PI; ra_aim += 2.*M_PI;
} }
de_now = de_aim*c + de_start*(1. - c); de_now = de_aim*c + de_start*(1. - c);
ra_now = ra_aim*c + ra_start*(1. - c); ra_now = ra_aim*c + ra_start*(1. - c);
Vec3d tmp; Vec3d tmp;
StelUtils::spheToRect(ra_now, de_now, tmp); StelUtils::spheToRect(ra_now, de_now, tmp);
nav->setEquVision(nav->localToEarthEqu(tmp)); nav->setEquinoxEquVisionDirection(nav->altAzToEquinoxEqu(tmp ));
move.coef+=move.speed*deltaTime*1000; move.coef+=move.speed*deltaTime*1000;
if (move.coef>=1.) if (move.coef>=1.)
{ {
flagAutoMove=0; flagAutoMove=0;
if (move.localPos) if (move.localPos)
{ {
nav->setLocalVision(move.aim); nav->setAltAzVisionDirection(move.aim);
} }
else else
{ {
nav->setEquVision(move.aim); nav->setEquinoxEquVisionDirection(move.aim);
} }
} }
} }
else else
{ {
if (flagTracking && StelApp::getInstance().getStelObjectMgr( ).getWasSelected()) // Equatorial vision vector locked on selected object if (flagTracking && StelApp::getInstance().getStelObjectMgr( ).getWasSelected()) // Equatorial vision vector locked on selected object
{ {
nav->setEquVision(StelApp::getInstance().getStelObje ctMgr().getSelectedObject()[0]->getObsEquatorialPos(core->getNavigation())) ; nav->setEquinoxEquVisionDirection(StelApp::getInstan ce().getStelObjectMgr().getSelectedObject()[0]->getEquinoxEquatorialPos(cor e->getNavigator()));
} }
else else
{ {
if (flagLockEquPos) // Equatorial vision vector lock ed if (flagLockEquPos) // Equatorial vision vector lock ed
{ {
// Recalc local vision vector // Recalc local vision vector
nav->setLocalVision(nav->earthEquToLocal(nav ->getEquVision())); nav->setAltAzVisionDirection(nav->equinoxEqu ToAltAz(nav->getEquinoxEquVisionDirection()));
} }
else // Local vision vector locked else // Local vision vector locked
{ {
// Recalc equatorial vision vector // Recalc equatorial vision vector
nav->setEquVision(nav->localToEarthEqu(nav-> getLocalVision())); nav->setEquinoxEquVisionDirection(nav->altAz ToEquinoxEqu(nav->getAltAzVisionDirection()));
} }
} }
} }
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
void MovementMgr::panView(double deltaAz, double deltaAlt) void StelMovementMgr::panView(double deltaAz, double deltaAlt)
{ {
Navigator* nav = core->getNavigation(); StelNavigator* nav = core->getNavigator();
double azVision, altVision; double azVision, altVision;
if( nav->getViewingMode() == Navigator::ViewEquator) StelUtils::rect if( nav->getViewingMode() == StelNavigator::ViewEquator) StelUtils::
ToSphe(&azVision,&altVision,nav->getEquVision()); rectToSphe(&azVision,&altVision,nav->getEquinoxEquVisionDirection());
else StelUtils::rectToSphe(&azVision,&altVision,nav->getLocalVision( else StelUtils::rectToSphe(&azVision,&altVision,nav->getAltAzVisionD
)); irection());
// if we are moving in the Azimuthal angle (left/right) // if we are moving in the Azimuthal angle (left/right)
if (deltaAz) azVision-=deltaAz; if (deltaAz) azVision-=deltaAz;
if (deltaAlt) if (deltaAlt)
{ {
if (altVision+deltaAlt <= M_PI_2 && altVision+deltaAlt >= -M _PI_2) altVision+=deltaAlt; if (altVision+deltaAlt <= M_PI_2 && altVision+deltaAlt >= -M _PI_2) altVision+=deltaAlt;
if (altVision+deltaAlt > M_PI_2) altVision = M_PI_2 - 0.0000 01; // Prevent bug if (altVision+deltaAlt > M_PI_2) altVision = M_PI_2 - 0.0000 01; // Prevent bug
if (altVision+deltaAlt < -M_PI_2) altVision = -M_PI_2 + 0.00 0001; // Prevent bug if (altVision+deltaAlt < -M_PI_2) altVision = -M_PI_2 + 0.00 0001; // Prevent bug
} }
// recalc all the position variables // recalc all the position variables
if (deltaAz || deltaAlt) if (deltaAz || deltaAlt)
{ {
setFlagTracking(false); setFlagTracking(false);
if( nav->getViewingMode() == Navigator::ViewEquator) if( nav->getViewingMode() == StelNavigator::ViewEquator)
{ {
Vec3d tmp; Vec3d tmp;
StelUtils::spheToRect(azVision, altVision, tmp); StelUtils::spheToRect(azVision, altVision, tmp);
nav->setLocalVision(nav->earthEquToLocal(tmp)); nav->setAltAzVisionDirection(nav->equinoxEquToAltAz( tmp));
} }
else else
{ {
Vec3d tmp; Vec3d tmp;
StelUtils::spheToRect(azVision, altVision, tmp); StelUtils::spheToRect(azVision, altVision, tmp);
// Calc the equatorial coordinate of the direction o f vision wich was in Altazimuthal coordinate // Calc the equatorial coordinate of the direction o f vision wich was in Altazimuthal coordinate
nav->setEquVision(nav->localToEarthEqu(tmp)); nav->setEquinoxEquVisionDirection(nav->altAzToEquino xEqu(tmp));
} }
} }
// Update the final modelview matrices
nav->updateModelViewMat();
} }
//! Make the first screen position correspond to the second (useful for mou se dragging) //! Make the first screen position correspond to the second (useful for mou se dragging)
void MovementMgr::dragView(int x1, int y1, int x2, int y2) void StelMovementMgr::dragView(int x1, int y1, int x2, int y2)
{ {
Navigator* nav = core->getNavigation(); StelNavigator* nav = core->getNavigator();
Projector* proj = core->getProjection();
Vec3d tempvec1, tempvec2; Vec3d tempvec1, tempvec2;
double az1, alt1, az2, alt2; double az1, alt1, az2, alt2;
if (nav->getViewingMode()==Navigator::ViewHorizon) const StelProjectorP prj = nav->getViewingMode()==StelNavigator::Vie
proj->setCurrentFrame(Projector::FrameLocal); wHorizon ? core->getProjection(StelCore::FrameAltAz) :
else core->getProjection(StelCore::FrameEquinoxEqu);
proj->setCurrentFrame(Projector::FrameEarthEqu);
//johannes: StelApp already gives appropriate x/y coordinates //johannes: StelApp already gives appropriate x/y coordinates
// proj->unProject(x2,proj->getViewportHeight()-y2, tempvec2); // proj->unProject(x2,proj->getViewportHeight()-y2, tempvec2);
// proj->unProject(x1,proj->getViewportHeight()-y1, tempvec1); // proj->unProject(x1,proj->getViewportHeight()-y1, tempvec1);
proj->unProject(x2,y2, tempvec2); prj->unProject(x2,y2, tempvec2);
proj->unProject(x1,y1, tempvec1); prj->unProject(x1,y1, tempvec1);
StelUtils::rectToSphe(&az1, &alt1, tempvec1); StelUtils::rectToSphe(&az1, &alt1, tempvec1);
StelUtils::rectToSphe(&az2, &alt2, tempvec2); StelUtils::rectToSphe(&az2, &alt2, tempvec2);
panView(az2-az1, alt1-alt2); panView(az2-az1, alt1-alt2);
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
// Update autoZoom if activated // Update autoZoom if activated
void MovementMgr::updateAutoZoom(double deltaTime) void StelMovementMgr::updateAutoZoom(double deltaTime)
{ {
if (flagAutoZoom) if (flagAutoZoom)
{ {
Projector* proj = core->getProjection();
// Use a smooth function // Use a smooth function
double c; double c;
if( zoomMove.start > zoomMove.aim ) if( zoomMove.start > zoomMove.aim )
{ {
// slow down as approach final view // slow down as approach final view
c = 1 - (1-zoomMove.coef)*(1-zoomMove.coef)*(1-zoomM ove.coef); c = 1 - (1-zoomMove.coef)*(1-zoomMove.coef)*(1-zoomM ove.coef);
} }
else else
{ {
// speed up as leave zoom target // speed up as leave zoom target
c = (zoomMove.coef)*(zoomMove.coef)*(zoomMove.coef); c = (zoomMove.coef)*(zoomMove.coef)*(zoomMove.coef);
} }
proj->setFov(zoomMove.start + (zoomMove.aim - zoomMove.start ) * c); setFov(zoomMove.start + (zoomMove.aim - zoomMove.start) * c) ;
zoomMove.coef+=zoomMove.speed*deltaTime*1000; zoomMove.coef+=zoomMove.speed*deltaTime*1000;
if (zoomMove.coef>=1.) if (zoomMove.coef>=1.)
{ {
flagAutoZoom = 0; flagAutoZoom = 0;
proj->setFov(zoomMove.aim); setFov(zoomMove.aim);
} }
} }
} }
// Zoom to the given field of view // Zoom to the given field of view
void MovementMgr::zoomTo(double aim_fov, float moveDuration) void StelMovementMgr::zoomTo(double aim_fov, float moveDuration)
{ {
zoomMove.aim=aim_fov; zoomMove.aim=aim_fov;
zoomMove.start=core->getProjection()->getFov(); zoomMove.start=currentFov;
zoomMove.speed=1.f/(moveDuration*1000); zoomMove.speed=1.f/(moveDuration*1000);
zoomMove.coef=0.; zoomMove.coef=0.;
flagAutoZoom = true; flagAutoZoom = true;
} }
void MovementMgr::changeFov(double deltaFov) void StelMovementMgr::changeFov(double deltaFov)
{ {
// if we are zooming in or out // if we are zooming in or out
if (deltaFov) core->getProjection()->setFov(core->getProjection()->g if (deltaFov)
etFov()+deltaFov); setFov(currentFov + deltaFov);
}
double StelMovementMgr::getAimFov(void) const
{
return (flagAutoZoom ? zoomMove.aim : currentFov);
} }
double MovementMgr::getAimFov(void) const void StelMovementMgr::setMaxFov(double max)
{ {
return (flagAutoZoom ? zoomMove.aim : core->getProjection()->getFov( maxFov = max;
)); if (currentFov > max)
{
setFov(max);
}
} }
 End of changes. 81 change blocks. 
102 lines changed or deleted 116 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/