StelMovementMgr.cpp   StelMovementMgr.cpp 
skipping to change at line 25 skipping to change at line 25
* 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 "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.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>
StelMovementMgr::StelMovementMgr(StelCore* acore) : core(acore), StelMovementMgr::StelMovementMgr(StelCore* acore) : core(acore),
flagLockEquPos(false), flagLockEquPos(false),
skipping to change at line 67 skipping to change at line 66
StelMovementMgr::~StelMovementMgr() StelMovementMgr::~StelMovementMgr()
{ {
} }
void StelMovementMgr::init() void StelMovementMgr::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
objectMgr = GETSTELMODULE(StelObjectMgr); objectMgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(conf); Q_ASSERT(conf);
Q_ASSERT(objectMgr); Q_ASSERT(objectMgr);
connect(objectMgr, SIGNAL(selectedObjectChanged(StelModule::StelModu
leSelectAction)),
this, SLOT(selectedObjectChange(StelModule::StelModu
leSelectAction)));
movementsSpeedFactor=1.; movementsSpeedFactor=1.;
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.0004f).toFloat( ); keyMoveSpeed = conf->value("navigation/move_speed",0.0004f).toFloat( );
keyZoomSpeed = conf->value("navigation/zoom_speed", 0.0004f).toFloat (); keyZoomSpeed = conf->value("navigation/zoom_speed", 0.0004f).toFloat ();
autoMoveDuration = conf->value ("navigation/auto_move_duration",1.5f ).toFloat(); autoMoveDuration = conf->value ("navigation/auto_move_duration",1.5f ).toFloat();
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; minFov = 0.0001;
maxFov = 100.; maxFov = 100.;
initFov = conf->value("navigation/init_fov",60.f).toFloat(); initFov = conf->value("navigation/init_fov",60.f).toFloat();
currentFov = initFov; currentFov = initFov;
Vec3f tmp = StelUtils::strToVec3f(conf->value("navigation/init_view_ pos").toString()); Vec3f tmp = StelUtils::strToVec3f(conf->value("navigation/init_view_ pos").toString());
initViewPos.set(tmp[0], tmp[1], tmp[2]); initViewPos.set(tmp[0], tmp[1], tmp[2]);
viewDirectionJ2000 = core->getNavigator()->altAzToJ2000(initViewPos) ; viewDirectionJ2000 = core->altAzToJ2000(initViewPos, StelCore::Refra ctionOff);
QString tmpstr = conf->value("navigation/viewing_mode", "horizon").t oString(); QString tmpstr = conf->value("navigation/viewing_mode", "horizon").t oString();
if (tmpstr=="equator") if (tmpstr=="equator")
setMountMode(StelMovementMgr::MountEquinoxEquatorial); setMountMode(StelMovementMgr::MountEquinoxEquatorial);
else else
{ {
if (tmpstr=="horizon") if (tmpstr=="horizon")
setMountMode(StelMovementMgr::MountAltAzimuthal); setMountMode(StelMovementMgr::MountAltAzimuthal);
else else
{ {
skipping to change at line 259 skipping to change at line 260
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 StelMovementMgr::addTimeDragPoint(int x, int y) void StelMovementMgr::addTimeDragPoint(int x, int y)
{ {
DragHistoryEntry e; DragHistoryEntry e;
e.runTime=StelApp::getInstance().getTotalRunTime(); e.runTime=StelApp::getInstance().getTotalRunTime();
e.jd=core->getNavigator()->getJDay(); e.jd=core->getJDay();
e.x=x; e.x=x;
e.y=y; e.y=y;
timeDragHistory.append(e); timeDragHistory.append(e);
if (timeDragHistory.size()>3) if (timeDragHistory.size()>3)
timeDragHistory.removeFirst(); timeDragHistory.removeFirst();
} }
void StelMovementMgr::handleMouseClicks(QMouseEvent* event) void StelMovementMgr::handleMouseClicks(QMouseEvent* event)
{ {
switch (event->button()) switch (event->button())
skipping to change at line 289 skipping to change at line 290
} }
break; 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();
previousY = event->y(); previousY = event->y();
beforeTimeDragTimeRate=core->getNavigator()- >getTimeRate(); beforeTimeDragTimeRate=core->getTimeRate();
if (dragTimeMode) if (dragTimeMode)
{ {
timeDragHistory.clear(); timeDragHistory.clear();
addTimeDragPoint(event->pos().x(), e vent->pos().y()); addTimeDragPoint(event->pos().x(), e vent->pos().y());
} }
event->accept(); event->accept();
return; return;
} }
else else
{ {
skipping to change at line 312 skipping to change at line 313
{ {
event->accept(); event->accept();
if (dragTimeMode) if (dragTimeMode)
{ {
if (timeDragHistory.size()>= 3) if (timeDragHistory.size()>= 3)
{ {
const double deltaT = timeDragHistory.last().runTime-timeDragHistory.first().runTime; const double deltaT = timeDragHistory.last().runTime-timeDragHistory.first().runTime;
Vec2f d(timeDragHist ory.last().x-timeDragHistory.first().x, timeDragHistory.last().y-timeDragHi story.first().y); Vec2f d(timeDragHist ory.last().x-timeDragHistory.first().x, timeDragHistory.last().y-timeDragHi story.first().y);
if (d.length()/delta T<dragTriggerDistance) if (d.length()/delta T<dragTriggerDistance)
{ {
core->getNav igator()->setTimeRate(JD_SECOND); core->setTim eRate(StelCore::JD_SECOND);
} }
else else
{ {
const double deltaJd = timeDragHistory.last().jd-timeDragHistory.first().jd; const double deltaJd = timeDragHistory.last().jd-timeDragHistory.first().jd;
const double newTimeRate = deltaJd/deltaT; const double newTimeRate = deltaJd/deltaT;
if (deltaT>0 .00000001) if (deltaT>0 .00000001)
{ {
if ( newTimeRate>=0) if ( newTimeRate>=0)
core->getNavigator()->setTimeRate(qMax(newTimeRate, JD_SECOND)); core->setTimeRate(qMax(newTimeRate, StelCore::JD_SECOND));
else else
core->getNavigator()->setTimeRate(qMin(newTimeRate, -JD_SECOND)); core->setTimeRate(qMin(newTimeRate, -StelCore::JD_SECOND));
} }
else else
core ->getNavigator()->setTimeRate(beforeTimeDragTimeRate); core ->setTimeRate(beforeTimeDragTimeRate);
} }
} }
else else
core->getNavigator() ->setTimeRate(beforeTimeDragTimeRate); core->setTimeRate(be foreTimeDragTimeRate);
} }
return; return;
} }
else else
{ {
// It's a normal click release // It's a normal click release
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
// CTRL + left clic = right clic for 1 button mouse // CTRL + left clic = right clic for 1 button mouse
if (event->modifiers().testFlag(Qt:: ControlModifier)) if (event->modifiers().testFlag(Qt:: ControlModifier))
{ {
skipping to change at line 379 skipping to change at line 380
} }
} }
break; break;
default: break; default: break;
} }
return; return;
} }
void StelMovementMgr::setInitViewDirectionToCurrent() void StelMovementMgr::setInitViewDirectionToCurrent()
{ {
initViewPos = core->getNavigator()->j2000ToAltAz(viewDirectionJ2000) ; initViewPos = core->j2000ToAltAz(viewDirectionJ2000, StelCore::Refra ctionOff);
QString dirStr = QString("%1,%2,%3").arg(initViewPos[0]).arg(initVie wPos[1]).arg(initViewPos[2]); QString dirStr = QString("%1,%2,%3").arg(initViewPos[0]).arg(initVie wPos[1]).arg(initViewPos[2]);
StelApp::getInstance().getSettings()->setValue("navigation/init_view _pos", dirStr); StelApp::getInstance().getSettings()->setValue("navigation/init_view _pos", dirStr);
} }
/************************************************************************* /*************************************************************************
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 StelMovementMgr::selectedObjectChangeCallBack(StelModuleSelectAction) void StelMovementMgr::selectedObjectChange(StelModule::StelModuleSelectActi on)
{ {
// If an object was selected keep the earth following // If an object was selected keep the earth following
if (objectMgr->getWasSelected()) if (objectMgr->getWasSelected())
{ {
if (getFlagTracking()) if (getFlagTracking())
setFlagLockEquPos(true); setFlagLockEquPos(true);
setFlagTracking(false); setFlagTracking(false);
} }
} }
skipping to change at line 536 skipping to change at line 537
updateAutoZoom(deltaTime); updateAutoZoom(deltaTime);
} }
void StelMovementMgr::updateVisionVector(double deltaTime) void StelMovementMgr::updateVisionVector(double deltaTime)
{ {
if (flagAutoMove) if (flagAutoMove)
{ {
if (!move.targetObject.isNull()) if (!move.targetObject.isNull())
{ {
// 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 = move.targetObject->getJ2000EquatorialPos( core->getNavigator()); move.aim = core->altAzToJ2000(move.targetObject->get AltAzPosAuto(core), StelCore::RefractionOff);
move.aim.normalize(); move.aim.normalize();
move.aim*=2.; move.aim*=2.;
} }
move.coef+=move.speed*deltaTime*1000; move.coef+=move.speed*deltaTime*1000;
if (move.coef>=1.) if (move.coef>=1.)
{ {
flagAutoMove=false; flagAutoMove=false;
move.coef=1.; move.coef=1.;
} }
skipping to change at line 602 skipping to change at line 603
const double de_now = de_aim*c + de_start*(1.-c); const double de_now = de_aim*c + de_start*(1.-c);
const double ra_now = ra_aim*c + ra_start*(1.-c); const double 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);
setViewDirectionJ2000(mountFrameToJ2000(tmp)); setViewDirectionJ2000(mountFrameToJ2000(tmp));
} }
else else
{ {
if (flagTracking && objectMgr->getWasSelected()) // Equatori al vision vector locked on selected object if (flagTracking && objectMgr->getWasSelected()) // Equatori al vision vector locked on selected object
{ {
setViewDirectionJ2000(objectMgr->getSelectedObject() Vec3d v = objectMgr->getSelectedObject()[0]->getAltA
[0]->getJ2000EquatorialPos(core->getNavigator())); zPosAuto(core);
setViewDirectionJ2000(core->altAzToJ2000(v, StelCore
::RefractionOff));
} }
else else
{ {
if (flagLockEquPos) // Equatorial vision vector lock ed if (flagLockEquPos) // Equatorial vision vector lock ed
{ {
// Recalc local vision vector // Recalc local vision vector
setViewDirectionJ2000(viewDirectionJ2000); setViewDirectionJ2000(viewDirectionJ2000);
} }
else else
{ {
skipping to change at line 649 skipping to change at line 651
} }
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 = currentFov*0.5f; float newfov = currentFov*0.5f;
zoomTo(newfov, manualMoveDuration); zoomTo(newfov, manualMoveDuration);
} }
else else
{ {
float satfov = objectMgr->getSelectedObject()[0]->getSatelli tesFov(core->getNavigator()); float satfov = objectMgr->getSelectedObject()[0]->getSatelli tesFov(core);
if (satfov>0.0 && currentFov*0.9>satfov) if (satfov>0.0 && currentFov*0.9>satfov)
zoomTo(satfov, moveDuration); zoomTo(satfov, moveDuration);
else else
{ {
float closefov = objectMgr->getSelectedObject()[0]-> getCloseViewFov(core->getNavigator()); float closefov = objectMgr->getSelectedObject()[0]-> getCloseViewFov(core);
if (currentFov>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 StelMovementMgr::autoZoomOut(float moveDuration, bool full) void StelMovementMgr::autoZoomOut(float moveDuration, bool full)
{ {
moveDuration /= movementsSpeedFactor; moveDuration /= movementsSpeedFactor;
if (objectMgr->getWasSelected() && !full) if (objectMgr->getWasSelected() && !full)
{ {
// 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 = objectMgr->getSelectedObject()[0]->getSatelli tesFov(core->getNavigator()); float satfov = objectMgr->getSelectedObject()[0]->getSatelli tesFov(core);
if (satfov>0.0 && currentFov<=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 = objectMgr->getSelectedObject()[0]->getParentSatelli tesFov((core->getNavigator())); satfov = objectMgr->getSelectedObject()[0]->getParentSatelli tesFov((core));
if (satfov>0.0 && currentFov<=satfov*0.9) if (satfov>0.0 && currentFov<=satfov*0.9)
{ {
zoomTo(satfov, moveDuration); zoomTo(satfov, moveDuration);
return; return;
} }
} }
zoomTo(initFov, moveDuration); zoomTo(initFov, moveDuration);
if (flagAutoZoomOutResetsDirection) if (flagAutoZoomOutResetsDirection)
{ {
moveToJ2000(core->getNavigator()->altAzToJ2000(getInitViewin gDirection()), moveDuration, -1); moveToJ2000(core->altAzToJ2000(getInitViewingDirection(), St elCore::RefractionOff), moveDuration, -1);
setFlagTracking(false); setFlagTracking(false);
setFlagLockEquPos(false); setFlagLockEquPos(false);
} }
} }
void StelMovementMgr::setFlagTracking(bool b) void StelMovementMgr::setFlagTracking(bool b)
{ {
if (!b || !objectMgr->getWasSelected()) if (!b || !objectMgr->getWasSelected())
{ {
flagTracking=false; flagTracking=false;
skipping to change at line 748 skipping to change at line 750
move.coef=0.; move.coef=0.;
move.targetObject = target; move.targetObject = target;
flagAutoMove = true; flagAutoMove = true;
} }
Vec3d StelMovementMgr::j2000ToMountFrame(const Vec3d& v) const Vec3d StelMovementMgr::j2000ToMountFrame(const Vec3d& v) const
{ {
switch (mountMode) switch (mountMode)
{ {
case MountAltAzimuthal: case MountAltAzimuthal:
return core->getNavigator()->j2000ToAltAz(v); return core->j2000ToAltAz(v, StelCore::RefractionOff );
case MountEquinoxEquatorial: case MountEquinoxEquatorial:
return core->getNavigator()->j2000ToEquinoxEqu(v); return core->j2000ToEquinoxEqu(v);
case MountGalactic: case MountGalactic:
return core->getNavigator()->j2000ToGalactic(v); return core->j2000ToGalactic(v);
} }
Q_ASSERT(0); Q_ASSERT(0);
return Vec3d(0); return Vec3d(0);
} }
Vec3d StelMovementMgr::mountFrameToJ2000(const Vec3d& v) const Vec3d StelMovementMgr::mountFrameToJ2000(const Vec3d& v) const
{ {
switch (mountMode) switch (mountMode)
{ {
case MountAltAzimuthal: case MountAltAzimuthal:
return core->getNavigator()->altAzToJ2000(v); return core->altAzToJ2000(v, StelCore::RefractionOff );
case MountEquinoxEquatorial: case MountEquinoxEquatorial:
return core->getNavigator()->equinoxEquToJ2000(v); return core->equinoxEquToJ2000(v);
case MountGalactic: case MountGalactic:
return core->getNavigator()->galacticToJ2000(v); return core->galacticToJ2000(v);
} }
Q_ASSERT(0); Q_ASSERT(0);
return Vec3d(0); return Vec3d(0);
} }
void StelMovementMgr::setViewDirectionJ2000(const Vec3d& v) void StelMovementMgr::setViewDirectionJ2000(const Vec3d& v)
{ {
core->getNavigator()->lookAtJ2000(v, getViewUpVectorJ2000()); core->lookAtJ2000(v, getViewUpVectorJ2000());
viewDirectionJ2000 = v; viewDirectionJ2000 = v;
viewDirectionMountFrame = j2000ToMountFrame(v); viewDirectionMountFrame = j2000ToMountFrame(v);
} }
void StelMovementMgr::panView(double deltaAz, double deltaAlt) void StelMovementMgr::panView(double deltaAz, double deltaAlt)
{ {
double azVision, altVision; double azVision, altVision;
StelUtils::rectToSphe(&azVision,&altVision,j2000ToMountFrame(viewDir ectionJ2000)); StelUtils::rectToSphe(&azVision,&altVision,j2000ToMountFrame(viewDir ectionJ2000));
// if we are moving in the Azimuthal angle (left/right) // if we are moving in the Azimuthal angle (left/right)
skipping to change at line 810 skipping to change at line 812
StelUtils::spheToRect(azVision, altVision, tmp); StelUtils::spheToRect(azVision, altVision, tmp);
setViewDirectionJ2000(mountFrameToJ2000(tmp)); setViewDirectionJ2000(mountFrameToJ2000(tmp));
} }
} }
//! 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 StelMovementMgr::dragView(int x1, int y1, int x2, int y2) void StelMovementMgr::dragView(int x1, int y1, int x2, int y2)
{ {
if (dragTimeMode) if (dragTimeMode)
{ {
core->getNavigator()->setTimeRate(0); core->setTimeRate(0);
Vec3d v1, v2; Vec3d v1, v2;
const StelProjectorP prj = core->getProjection(StelCore::Fra meEquinoxEqu); const StelProjectorP prj = core->getProjection(StelCore::Fra meEquinoxEqu);
prj->unProject(x2,y2, v2); prj->unProject(x2,y2, v2);
prj->unProject(x1,y1, v1); prj->unProject(x1,y1, v1);
v1[2]=0; v1.normalize(); v1[2]=0; v1.normalize();
v2[2]=0; v2.normalize(); v2[2]=0; v2.normalize();
double angle = (v2^v1)[2]; double angle = (v2^v1)[2];
double deltaDay = angle/(2.*M_PI)*core->getNavigator()->getL double deltaDay = angle/(2.*M_PI)*core->getLocalSideralDayLe
ocalSideralDayLength(); ngth();
core->getNavigator()->setJDay(core->getNavigator()->getJDay( core->setJDay(core->getJDay()+deltaDay);
)+deltaDay);
addTimeDragPoint(x2, y2); addTimeDragPoint(x2, y2);
} }
else else
{ {
Vec3d tempvec1, tempvec2; Vec3d tempvec1, tempvec2;
const StelProjectorP prj = core->getProjection(StelCore::Fra meJ2000); const StelProjectorP prj = core->getProjection(StelCore::Fra meJ2000);
prj->unProject(x2,y2, tempvec2); prj->unProject(x2,y2, tempvec2);
prj->unProject(x1,y1, tempvec1); prj->unProject(x1,y1, tempvec1);
double az1, alt1, az2, alt2; double az1, alt1, az2, alt2;
StelUtils::rectToSphe(&az1, &alt1, j2000ToMountFrame(tempvec 1)); StelUtils::rectToSphe(&az1, &alt1, j2000ToMountFrame(tempvec 1));
 End of changes. 28 change blocks. 
31 lines changed or deleted 35 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/