Allow caller to specify distance in gotoSelection()

This commit is contained in:
Chris Laurel 2001-04-27 07:03:43 +00:00
parent 22deda23c2
commit 7096a14752
2 changed files with 31 additions and 19 deletions

View file

@ -230,7 +230,7 @@ float getSelectionSize(Selection& sel)
else if (sel.star != NULL)
return sel.star->getRadius();
else if (sel.galaxy != NULL)
return sel.galaxy->getRadius();
return astro::lightYearsToKilometers(sel.galaxy->getRadius());
else
return 0.0f;
}
@ -553,21 +553,13 @@ Selection Simulation::pickObject(Vec3f pickRay)
}
void Simulation::computeGotoParameters(Selection& destination, JourneyParams& jparams,
double gotoTime)
void Simulation::computeGotoParameters(Selection& destination,
JourneyParams& jparams,
double gotoTime,
double distance)
{
UniversalCoord targetPosition = getSelectionPosition(selection, simTime);
Vec3d v = targetPosition - observer.getPosition();
double distanceToTarget = v.length();
double maxOrbitDistance;
if (selection.body != NULL)
maxOrbitDistance = astro::kilometersToLightYears(5.0f * selection.body->getRadius());
else if (selection.galaxy != NULL)
maxOrbitDistance = 5.0f * selection.galaxy->getRadius();
else
maxOrbitDistance = 0.5f;
double orbitDistance = (distanceToTarget > maxOrbitDistance * 10.0f) ? maxOrbitDistance : distanceToTarget * 0.1f;
v.normalize();
jparams.duration = gotoTime;
@ -578,7 +570,7 @@ void Simulation::computeGotoParameters(Selection& destination, JourneyParams& jp
// The destination position lies along the line between the current
// position and the star
jparams.to = targetPosition - v * orbitDistance;
jparams.to = targetPosition - v * distance;
jparams.initialFocus = jparams.from +
(Vec3f(0, 0, -1.0f) * observer.getOrientation().toMatrix4());
jparams.finalFocus = targetPosition;
@ -724,7 +716,28 @@ void Simulation::gotoSelection(double gotoTime)
{
if (!selection.empty())
{
computeGotoParameters(selection, journey, gotoTime);
UniversalCoord pos = getSelectionPosition(selection, simTime);
Vec3d v = pos - observer.getPosition();
double distance = v.length();
double maxOrbitDistance;
if (selection.body != NULL)
maxOrbitDistance = astro::kilometersToLightYears(5.0f * selection.body->getRadius());
else if (selection.galaxy != NULL)
maxOrbitDistance = 5.0f * selection.galaxy->getRadius();
else
maxOrbitDistance = 0.5f;
double orbitDistance = (distance > maxOrbitDistance * 10.0f) ? maxOrbitDistance : distance * 0.1f;
computeGotoParameters(selection, journey, gotoTime, orbitDistance);
observerMode = Travelling;
}
}
void Simulation::gotoSelection(double gotoTime, double distance)
{
if (!selection.empty())
{
computeGotoParameters(selection, journey, gotoTime, distance);
observerMode = Travelling;
}
}

View file

@ -45,8 +45,6 @@ class Simulation
Observer& getObserver();
Quatf getOrientation();
void setOrientation(Quatf q);
void orbit(Quatf q);
void rotate(Quatf q);
void changeOrbitDistance(float d);
@ -58,7 +56,8 @@ class Simulation
void selectStar(uint32);
void selectPlanet(int);
Selection findObject(string s);
void gotoSelection(double gotoTime = 5.0);
void gotoSelection(double gotoTime);
void gotoSelection(double gotoTime, double distance);
void centerSelection(double centerTime = 0.5);
void follow();
void cancelMotion();
@ -113,7 +112,7 @@ class Simulation
SolarSystem& solarSystem,
Vec3f pickRay);
Selection pickStar(Vec3f pickRay);
void computeGotoParameters(Selection& sel, JourneyParams& jparams, double gotoTime);
void computeGotoParameters(Selection& sel, JourneyParams& jparams, double gotoTime, double distance);
void computeCenterParameters(Selection& sel, JourneyParams& jparams, double centerTime);
void displaySelectionInfo(Console&);