Rewrote observer class to use 1.5.0 reference frames. The FrameOfReference

class is replaced by the new ObserverFrame class, which is a wrapper for
ReferenceFrame. Small changes to a lot of file were necessary, in many cases
simply because the CoordinateSystem enum was moved from astro to
ObserverFrame. This change was primarily a refactoring to make future
development easier and improve performance be eliminating redundant
frame -> universal conversions of the observer position. The one change that
will be apparent to users is the redefinition of the chase and phase lock
frames. Previously, these used the spin axis of the reference object to define
the secondary frame axis. Now, the secondary axis is the position vector in
chase mode, and the velocity vector in phase lock mode.
ver1_6_1
Chris Laurel 2008-02-08 21:46:02 +00:00
parent ee20dadc71
commit a6cc486542
23 changed files with 7622 additions and 7546 deletions

View File

@ -8,6 +8,7 @@
#import "Astro.h"
#import "Astro_PrivateAPI.h"
#import "Observer.h"
#import "CelestiaUniversalCoord_PrivateAPI.h"
#import "CelestiaVector_PrivateAPI.h"
@ -68,7 +69,7 @@ NSDictionary* coordinateDict;
+(void)initialize
{
// compiler macro would be prettier I guess
coordinateDict = [[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:astro::Universal],@"Universal",[NSNumber numberWithInt:astro::Ecliptical],@"Ecliptical",[NSNumber numberWithInt:astro::Equatorial],@"Equatorial",[NSNumber numberWithInt:astro::Geographic],@"Geographic",[NSNumber numberWithInt:astro::ObserverLocal],@"ObserverLocal",[NSNumber numberWithInt:astro::PhaseLock],@"PhaseLock",[NSNumber numberWithInt:astro::Chase],@"Chase",nil,nil] retain];
coordinateDict = [[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:ObserverFrame::Universal],@"Universal",[NSNumber numberWithInt:ObserverFrame::Ecliptical],@"Ecliptical",[NSNumber numberWithInt:ObserverFrame::Equatorial],@"Equatorial",[NSNumber numberWithInt:ObserverFrame::BodyFixed],@"Geographic",[NSNumber numberWithInt:ObserverFrame::ObserverLocal],@"ObserverLocal",[NSNumber numberWithInt:ObserverFrame::PhaseLock],@"PhaseLock",[NSNumber numberWithInt:ObserverFrame::Chase],@"Chase",nil,nil] retain];
}
+(NSNumber*)sphereIlluminationFraction:(CelestiaVector*)spherePos viewerPosition:(CelestiaVector*)viewerPos
{

View File

@ -12,6 +12,7 @@
#import "CelestiaUniversalCoord_PrivateAPI.h"
#import "NSString_ObjCPlusPlus.h"
#import "Astro.h"
#import "Observer.h"
#import "CelestiaAppCore.h"
#import "CelestiaSimulation.h"
#import "CelestiaSimulation_PrivateAPI.h"
@ -52,7 +53,7 @@
}
-(void)setCoordinateSystem:(NSString*)coordSys
{
[self favorite]->coordSys = (astro::CoordinateSystem)[[Astro coordinateSystem:coordSys] intValue];
[self favorite]->coordSys = (ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:coordSys] intValue];
}
@end
@ -134,7 +135,7 @@
name = [[[[CelestiaAppCore sharedAppCore] simulation] julianDate] description];
fav->jd = sim->getTime();
fav->position = sim->getObserver().getPosition();
fav->orientation = sim->getObserver().getOrientation();
fav->orientation = sim->getObserver().getOrientationf();
fav->name = [name stdString];
fav->isFolder = false;
fav->parentFolder = [parentFolder stdString];
@ -145,7 +146,7 @@
else
fav->selectionName = sel.getName();
fav->coordSys = sim->getFrame().coordSys;
fav->coordSys = sim->getFrame()->getCoordinateSystem();
self = [self initWithFavorite:fav];
_freeWhenDone = YES;
#ifdef URL_FAVORITES

View File

@ -37,13 +37,9 @@
{
return [[[CelestiaUniversalCoord alloc] initWithUniversalCoord:[self observer].getPosition()] autorelease];
}
-(CelestiaVector*)relativePosition:(CelestiaVector*)p
{
return [CelestiaVector vectorWithPoint3d:[self observer].getRelativePosition([p point3d])];
}
-(CelestiaVector*)orientation
{
return [CelestiaVector vectorWithQuatf:[self observer].getOrientation()];
return [CelestiaVector vectorWithQuatf:[self observer].getOrientationf()];
}
-(void)setOrientation:(CelestiaVector*)q
{

View File

@ -144,7 +144,7 @@ FrameOfReference getFrame() const;
[self simulation]->gotoSelection(
[gotoTime doubleValue],
[up vec3f],
(astro::CoordinateSystem)[[Astro coordinateSystem:csysName] intValue]);
(ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:csysName] intValue]);
}
@ -154,7 +154,7 @@ FrameOfReference getFrame() const;
[gotoTime doubleValue],
[distance doubleValue],
[up vec3f],
(astro::CoordinateSystem)[[Astro coordinateSystem:csysName] intValue]);
(ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:csysName] intValue]);
}
-(void)gotoSelection:(NSNumber*)gotoTime distance:(NSNumber*)distance longitude:(NSNumber*)longitude latitude:(NSNumber*)latitude up:(CelestiaVector*)up
@ -225,7 +225,7 @@ FrameOfReference getFrame() const;
-(void)setFrame:(NSString*)cs selection:(CelestiaSelection*)sel
{
[self simulation]->setFrame((astro::CoordinateSystem)[[Astro coordinateSystem:cs] intValue], [sel selection]);
[self simulation]->setFrame((ObserverFrame::CoordinateSystem)[[Astro coordinateSystem:cs] intValue], [sel selection]);
}
@end

View File

@ -162,15 +162,14 @@ static CelestiaBody *eclipseBody;
sim->setTime(startTime);
Selection target(body);
Selection ref(body->getSystem()->getStar());
sim->setFrame(FrameOfReference(astro::PhaseLock, target, ref));
sim->setFrame(ObserverFrame::PhaseLock, target, ref);
sim->update(0.0);
double distance = astro::kilometersToMicroLightYears(target.radius() * 4.0);
RigidTransform to;
to.rotation = Quatd::yrotation(PI);
to.translation = Point3d(0, 0, -distance);
Quatd toRotation = Quatd::yrotation(PI);
UniversalCoord toPosition = Point3d(0, 0, -distance);
sim->setSelection(target);
sim->gotoLocation(to, 2.5);
sim->gotoLocation(toPosition, toRotation, 2.5);
}
- (IBAction)stopFind: (id)sender

View File

@ -60,18 +60,6 @@ namespace astro
bool parseDate(const std::string&, Date&);
enum CoordinateSystem
{
Universal = 0,
Ecliptical = 1,
Equatorial = 2,
Geographic = 3,
ObserverLocal = 4,
PhaseLock = 5,
Chase = 6,
};
// Time scale conversions
// UTC - Coordinated Universal Time
// TAI - International Atomic Time

View File

@ -359,7 +359,7 @@ Mat4d Body::getLocalToHeliocentric(double tjd) const
if (orbitFrame != NULL)
{
Point3d p = orbitFrame->convertFromAstrocentric(pos, tjd);
Point3d p = orbitFrame->convertToAstrocentric(pos, tjd);
// Temporary hack; won't be necessary post-1.5.0 when this function
// is redefined to return position with respect to frame root object
@ -405,7 +405,7 @@ Point3d Body::getHeliocentricPosition(double tjd) const
if (orbitFrame != NULL)
{
Point3d p = orbitFrame->convertFromAstrocentric(pos, tjd);
Point3d p = orbitFrame->convertToAstrocentric(pos, tjd);
// Temporary hack; won't be necessary post-1.5.0 when this function
// is redefined to return position with respect to frame root object

View File

@ -116,24 +116,24 @@ void CommandParser::error(const string errMsg)
}
static astro::CoordinateSystem parseCoordinateSystem(const string& name)
static ObserverFrame::CoordinateSystem parseCoordinateSystem(const string& name)
{
if (compareIgnoringCase(name, "observer") == 0)
return astro::ObserverLocal;
return ObserverFrame::ObserverLocal;
else if (compareIgnoringCase(name, "geographic") == 0)
return astro::Geographic;
return ObserverFrame::BodyFixed;
else if (compareIgnoringCase(name, "equatorial") == 0)
return astro::Equatorial;
return ObserverFrame::Equatorial;
else if (compareIgnoringCase(name, "ecliptical") == 0)
return astro::Ecliptical;
return ObserverFrame::Ecliptical;
else if (compareIgnoringCase(name, "universal") == 0)
return astro::Universal;
return ObserverFrame::Universal;
else if (compareIgnoringCase(name, "lock") == 0)
return astro::PhaseLock;
return ObserverFrame::PhaseLock;
else if (compareIgnoringCase(name, "chase") == 0)
return astro::Chase;
return ObserverFrame::Chase;
else
return astro::ObserverLocal;
return ObserverFrame::ObserverLocal;
}
@ -198,7 +198,7 @@ Command* CommandParser::parseCommand()
string targetName;
paramList->getString("target", targetName);
string coordSysName;
astro::CoordinateSystem coordSys = astro::Universal;
ObserverFrame::CoordinateSystem coordSys = ObserverFrame::Universal;
if (paramList->getString("coordsys", coordSysName))
coordSys = parseCoordinateSystem(coordSysName);
@ -217,7 +217,7 @@ Command* CommandParser::parseCommand()
double distance = 5.0;
paramList->getNumber("distance", distance);
astro::CoordinateSystem upFrame = astro::ObserverLocal;
ObserverFrame::CoordinateSystem upFrame = ObserverFrame::ObserverLocal;
string frameString;
if (paramList->getString("upframe", frameString))
upFrame = parseCoordinateSystem(frameString);

View File

@ -60,7 +60,7 @@ void CommandSelect::process(ExecutionEnvironment& env)
CommandGoto::CommandGoto(double t,
double dist,
Vec3f _up,
astro::CoordinateSystem _upFrame) :
ObserverFrame::CoordinateSystem _upFrame) :
gotoTime(t), distance(dist), up(_up), upFrame(_upFrame)
{
}
@ -124,10 +124,9 @@ CommandGotoLocation::~CommandGotoLocation()
void CommandGotoLocation::process(ExecutionEnvironment& env)
{
RigidTransform to;
to.rotation = Quatd(rotation.w, rotation.x, rotation.y, rotation.z);
to.translation = translation;
env.getSimulation()->gotoLocation(to, gotoTime);
Quatd toOrientation = Quatd(rotation.w, rotation.x, rotation.y, rotation.z);
UniversalCoord toPosition = translation;
env.getSimulation()->gotoLocation(toPosition, toOrientation, gotoTime);
}
/////////////////////////////
@ -231,7 +230,7 @@ void CommandLock::process(ExecutionEnvironment& env)
////////////////
// Setframe command
CommandSetFrame::CommandSetFrame(astro::CoordinateSystem _coordSys,
CommandSetFrame::CommandSetFrame(ObserverFrame::CoordinateSystem _coordSys,
const string& refName,
const string& targetName) :
coordSys(_coordSys), refObjectName(refName), targetObjectName(targetName)
@ -242,9 +241,9 @@ void CommandSetFrame::process(ExecutionEnvironment& env)
{
Selection ref = env.getSimulation()->findObjectFromPath(refObjectName);
Selection target;
if (coordSys == astro::PhaseLock)
if (coordSys == ObserverFrame::PhaseLock)
target = env.getSimulation()->findObjectFromPath(targetObjectName);
env.getSimulation()->setFrame(FrameOfReference(coordSys, ref, target));
env.getSimulation()->setFrame(coordSys, ref, target);
}
@ -273,7 +272,7 @@ CommandCancel::CommandCancel()
void CommandCancel::process(ExecutionEnvironment& env)
{
env.getSimulation()->cancelMotion();
env.getSimulation()->setFrame(FrameOfReference());
env.getSimulation()->setFrame(ObserverFrame::Universal, Selection());
env.getSimulation()->setTrackedObject(Selection());
}

View File

@ -79,7 +79,7 @@ class CommandGoto : public InstantaneousCommand
{
public:
CommandGoto(double t, double dist,
Vec3f _up, astro::CoordinateSystem _upFrame);
Vec3f _up, ObserverFrame::CoordinateSystem _upFrame);
~CommandGoto();
void process(ExecutionEnvironment&);
@ -87,7 +87,7 @@ class CommandGoto : public InstantaneousCommand
double gotoTime;
double distance;
Vec3f up;
astro::CoordinateSystem upFrame;
ObserverFrame::CoordinateSystem upFrame;
};
@ -205,12 +205,12 @@ class CommandTrack : public InstantaneousCommand
class CommandSetFrame : public InstantaneousCommand
{
public:
CommandSetFrame(astro::CoordinateSystem,
CommandSetFrame(ObserverFrame::CoordinateSystem,
const std::string&, const std::string&);
void process(ExecutionEnvironment&);
private:
astro::CoordinateSystem coordSys;
ObserverFrame::CoordinateSystem coordSys;
std::string refObjectName;
std::string targetObjectName;
};

View File

@ -13,214 +13,6 @@
using namespace std;
RigidTransform FrameOfReference::toUniversal(const RigidTransform& xform,
double t) const
{
// Handle the easy case . . .
if (coordSys == astro::Universal)
return xform;
UniversalCoord origin = refObject.getPosition(t);
if (coordSys == astro::Geographic)
{
Quatd rotation(1, 0, 0, 0);
switch (refObject.getType())
{
case Selection::Type_Body:
rotation = refObject.body()->getEclipticalToBodyFixed(t);
break;
case Selection::Type_Star:
rotation = refObject.star()->getRotationModel()->orientationAtTime(t);
break;
case Selection::Type_Location:
if (refObject.location()->getParentBody() != NULL)
rotation = refObject.location()->getParentBody()->getEclipticalToBodyFixed(t);
break;
default:
break;
}
Point3d p = (Point3d) xform.translation * rotation.toMatrix4();
return RigidTransform(origin + Vec3d(p.x, p.y, p.z),
xform.rotation * rotation);
}
else if (coordSys == astro::PhaseLock)
{
Mat3d m;
Vec3d lookDir = refObject.getPosition(t) - targetObject.getPosition(t);
lookDir.normalize();
switch (refObject.getType())
{
case Selection::Type_Body:
{
Body* body = refObject.body();
Vec3d axisDir = Vec3d(0, 1, 0) * body->getEclipticalToEquatorial(t).toMatrix3();
Vec3d v = axisDir ^ lookDir;
v.normalize();
Vec3d u = lookDir ^ v;
m = Mat3d(v, u, lookDir);
}
break;
case Selection::Type_Star:
{
Star* star = refObject.star();
Vec3d axisDir = Vec3d(0, 1, 0) * star->getRotationModel()->equatorOrientationAtTime(t).toMatrix3();
Vec3d v = axisDir ^ lookDir;
v.normalize();
Vec3d u = lookDir ^ v;
m = Mat3d(v, u, lookDir);
}
default:
return xform;
}
Point3d p = (Point3d) xform.translation * m;
return RigidTransform(origin + Vec3d(p.x, p.y, p.z),
xform.rotation * Quatd(m));
}
else if (coordSys == astro::Chase)
{
Mat3d m;
switch (refObject.getType())
{
case Selection::Type_Body:
{
Body* body = refObject.body();
Vec3d lookDir = body->getOrbit()->positionAtTime(t) -
body->getOrbit()->positionAtTime(t - 1.0 / 1440.0);
Vec3d axisDir = Vec3d(0, 1, 0) * body->getEclipticalToEquatorial(t).toMatrix3();
lookDir.normalize();
Vec3d v = lookDir ^ axisDir;
v.normalize();
Vec3d u = v ^ lookDir;
m = Mat3d(v, u, -lookDir);
}
break;
default:
return xform;
}
Point3d p = (Point3d) xform.translation * m;
return RigidTransform(origin + Vec3d(p.x, p.y, p.z),
xform.rotation * Quatd(m));
}
else
{
return RigidTransform(origin + xform.translation, xform.rotation);
}
}
RigidTransform FrameOfReference::fromUniversal(const RigidTransform& xform,
double t) const
{
// Handle the easy case . . .
if (coordSys == astro::Universal)
return xform;
UniversalCoord origin = refObject.getPosition(t);
if (coordSys == astro::Geographic)
{
Quatd rotation(1, 0, 0, 0);
switch (refObject.getType())
{
case Selection::Type_Body:
rotation = refObject.body()->getEclipticalToBodyFixed(t);
break;
case Selection::Type_Star:
rotation = refObject.star()->getRotationModel()->orientationAtTime(t);
break;
case Selection::Type_Location:
if (refObject.location()->getParentBody() != NULL)
rotation = refObject.location()->getParentBody()->getEclipticalToBodyFixed(t);
break;
default:
break;
}
Vec3d v = (xform.translation - origin) * (~rotation).toMatrix4();
return RigidTransform(UniversalCoord(v.x, v.y, v.z),
xform.rotation * ~rotation);
}
else if (coordSys == astro::PhaseLock)
{
Mat3d m;
Vec3d lookDir = refObject.getPosition(t) - targetObject.getPosition(t);
lookDir.normalize();
switch (refObject.getType())
{
case Selection::Type_Body:
{
Body* body = refObject.body();
Vec3d axisDir = Vec3d(0, 1, 0) * body->getEclipticalToEquatorial(t).toMatrix3();
Vec3d v = axisDir ^ lookDir;
v.normalize();
Vec3d u = lookDir ^ v;
m = Mat3d(v, u, lookDir);
}
break;
case Selection::Type_Star:
{
Star* star = refObject.star();
Vec3d axisDir = Vec3d(0, 1, 0) * star->getRotationModel()->equatorOrientationAtTime(t).toMatrix3();
Vec3d v = axisDir ^ lookDir;
v.normalize();
Vec3d u = lookDir ^ v;
m = Mat3d(v, u, lookDir);
}
default:
return xform;
}
Vec3d v = (xform.translation - origin) * m.transpose();
return RigidTransform(UniversalCoord(v.x, v.y, v.z),
xform.rotation * ~Quatd(m));
}
else if (coordSys == astro::Chase)
{
Mat3d m;
switch (refObject.getType())
{
case Selection::Type_Body:
{
Body* body = refObject.body();
Vec3d lookDir = body->getOrbit()->positionAtTime(t) -
body->getOrbit()->positionAtTime(t - 1.0 / 1440.0);
Vec3d axisDir = Vec3d(0, 1, 0) * body->getEclipticalToEquatorial(t).toMatrix3();
lookDir.normalize();
Vec3d v = lookDir ^ axisDir;
v.normalize();
Vec3d u = v ^ lookDir;
m = Mat3d(v, u, -lookDir);
}
break;
default:
return xform;
}
Vec3d v = (xform.translation - origin) * m.transpose();
return RigidTransform(UniversalCoord(v.x, v.y, v.z),
xform.rotation * ~Quatd(m));
}
else
{
return RigidTransform(xform.translation.difference(origin),
xform.rotation);
}
}
/*** ReferenceFrame ***/
ReferenceFrame::ReferenceFrame(Selection center) :
@ -249,30 +41,92 @@ ReferenceFrame::release() const
}
// TODO: Not correct; requires BigFix * double multiplication
UniversalCoord
ReferenceFrame::convertFrom(const UniversalCoord& uc, double tjd) const
// High-precision rotation using 64.64 fixed point path. Rotate uc by
// the rotation specified by unit quaternion q.
static UniversalCoord rotate(const UniversalCoord& uc, const Quatd& q)
{
UniversalCoord center = centerObject.getPosition(tjd);
Vec3d relative = uc - center;
return center + relative * getOrientation(tjd).toMatrix3();
Mat3d r = q.toMatrix3();
UniversalCoord uc1;
uc1.x = uc.x * BigFix(r[0].x) + uc.y * BigFix(r[1].x) + uc.z * BigFix(r[2].x);
uc1.y = uc.x * BigFix(r[0].y) + uc.y * BigFix(r[1].y) + uc.z * BigFix(r[2].y);
uc1.z = uc.x * BigFix(r[0].z) + uc.y * BigFix(r[1].z) + uc.z * BigFix(r[2].z);
return uc1;
}
// TODO: Not correct; requires BigFix * double multiplication
/*! Convert from universal coordinates to frame coordinates. This method
* uses 64.64 fixed point arithmetic in conversion, and is thus /much/ slower
* than convertFromAstrocentric(), which works with double precision
* floating points values. For cases when the bodies are all in the same
* solar system, convertFromAstrocentric() should be used.
*/
UniversalCoord
ReferenceFrame::convertTo(const UniversalCoord& uc, double tjd) const
ReferenceFrame::convertFromUniversal(const UniversalCoord& uc, double tjd) const
{
UniversalCoord center = centerObject.getPosition(tjd);
Vec3d relative = uc - center;
UniversalCoord uc1 = uc.difference(centerObject.getPosition(tjd));
return rotate(uc1, conjugate(getOrientation(tjd)));
}
return center + relative * conjugate(getOrientation(tjd)).toMatrix3();
Quatd
ReferenceFrame::convertFromUniversal(const Quatd& q, double tjd) const
{
return q * conjugate(getOrientation(tjd));
}
/*! Convert from local coordinates to universal coordinates. This method
* uses 64.64 fixed point arithmetic in conversion, and is thus /much/ slower
* than convertFromAstrocentric(), which works with double precision
* floating points values. For cases when the bodies are all in the same
* solar system, convertFromAstrocentric() should be used.
*
* To get the position of a solar system object in universal coordinates,
* it usually suffices to get the astrocentric position and then add that
* to the position of the star in universal coordinates. This avoids any
* expensive high-precision multiplication.
*/
UniversalCoord
ReferenceFrame::convertToUniversal(const UniversalCoord& uc, double tjd) const
{
return centerObject.getPosition(tjd) + rotate(uc, getOrientation(tjd));
}
Quatd
ReferenceFrame::convertToUniversal(const Quatd& q, double tjd) const
{
return q * getOrientation(tjd);
}
Point3d
ReferenceFrame::convertFromAstrocentric(const Point3d& p, double tjd) const
{
Point3d center;
if (centerObject.getType() == Selection::Type_Body)
{
Point3d center = centerObject.body()->getHeliocentricPosition(tjd);
return Point3d(0.0, 0.0, 0.0) + (p - center) * conjugate(getOrientation(tjd)).toMatrix3();
}
else if (centerObject.getType() == Selection::Type_Star)
{
return p * conjugate(getOrientation(tjd)).toMatrix3();
}
else
{
// TODO:
// bad if the center object is a galaxy
// what about locations?
return Point3d(0.0, 0.0, 0.0);
}
}
Point3d
ReferenceFrame::convertToAstrocentric(const Point3d& p, double tjd) const
{
Point3d center;
if (centerObject.getType() == Selection::Type_Body)
@ -290,7 +144,7 @@ ReferenceFrame::convertFromAstrocentric(const Point3d& p, double tjd) const
// bad if the center object is a galaxy
// what about locations?
return Point3d(0.0, 0.0, 0.0);
}
}
}

View File

@ -16,72 +16,12 @@
#include <celengine/selection.h>
struct RigidTransform
{
RigidTransform() :
translation(0.0, 0.0, 0.0), rotation(1.0, 0.0, 0.0, 0.0) {};
RigidTransform(const UniversalCoord& uc) :
translation(uc), rotation(1.0f) {};
RigidTransform(const UniversalCoord& uc, const Quatd& q) :
translation(uc), rotation(q) {};
RigidTransform(const UniversalCoord& uc, const Quatf& q) :
translation(uc), rotation(q.w, q.x, q.y, q.z) {};
UniversalCoord translation;
Quatd rotation;
};
struct FrameOfReference
{
FrameOfReference() :
coordSys(astro::Universal) {};
FrameOfReference(astro::CoordinateSystem _coordSys, Body* _body) :
coordSys(_coordSys), refObject(_body) {};
FrameOfReference(astro::CoordinateSystem _coordSys, Star* _star) :
coordSys(_coordSys), refObject(_star) {};
FrameOfReference(astro::CoordinateSystem _coordSys, DeepSkyObject* _deepsky) :
coordSys(_coordSys), refObject(_deepsky) {};
FrameOfReference(astro::CoordinateSystem _coordSys, const Selection& sel) :
coordSys(_coordSys), refObject(sel) {};
FrameOfReference(astro::CoordinateSystem _coordSys, const Selection& ref,
const Selection& target) :
coordSys(_coordSys), refObject(ref), targetObject(target) {};
RigidTransform toUniversal(const RigidTransform& xform, double t) const;
RigidTransform fromUniversal(const RigidTransform& xform, double t) const;
astro::CoordinateSystem coordSys;
Selection refObject;
Selection targetObject;
};
// class RefCountedObject
/*!
Frame
{
Center "Sol"
# Orientation "J2000"
# Orientation "J2000Ecliptic"
TwoAxis
{
Primary
{
Axis "+X"
Observer "Earth"
Target "Sun"
}
Secondary
{
Axis "+Y"
}
}
}
*/
/*! A ReferenceFrame object has a center and set of orthogonal axes.
*
* Subclasses of ReferenceFrame must override the getOrientation method
* (which specifies the coordinate axes at a given time) and the
* nestingDepth() method (which is used to check for recursive frames.)
*/
class ReferenceFrame
{
public:
@ -91,10 +31,13 @@ class ReferenceFrame
int addRef() const;
int release() const;
UniversalCoord convertFrom(const UniversalCoord& uc, double tjd) const;
UniversalCoord convertTo(const UniversalCoord& uc, double tjd) const;
UniversalCoord convertFromUniversal(const UniversalCoord& uc, double tjd) const;
UniversalCoord convertToUniversal(const UniversalCoord& uc, double tjd) const;
Quatd convertFromUniversal(const Quatd& q, double tjd) const;
Quatd convertToUniversal(const Quatd& q, double tjd) const;
Point3d convertFromAstrocentric(const Point3d& p, double tjd) const;
Point3d convertToAstrocentric(const Point3d& p, double tjd) const;
Selection getCenter() const;

File diff suppressed because it is too large Load Diff

View File

@ -20,35 +20,102 @@
#include <celengine/frame.h>
class ObserverFrame
{
public:
enum CoordinateSystem
{
Universal = 0,
Ecliptical = 1,
Equatorial = 2,
BodyFixed = 3,
PhaseLock = 5,
Chase = 6,
// Previous versions of PhaseLock and Chase used the
// spin axis of the reference object as a secondary
// vector for the coordinate system.
PhaseLock_Old = 100,
Chase_Old = 101,
// ObserverLocal is not a real frame; it's an optional
// way to specify view vectors. Eventually, there will
// be some other way to accomplish this and ObserverLocal
// will go away.
ObserverLocal = 200,
Unknown = 1000,
};
ObserverFrame();
ObserverFrame(CoordinateSystem cs,
const Selection& _refObject,
const Selection& _targetObj = Selection());
ObserverFrame(const ObserverFrame&);
~ObserverFrame();
ObserverFrame& operator=(const ObserverFrame& f);
CoordinateSystem getCoordinateSystem() const;
Selection getRefObject() const;
Selection getTargetObject() const;
const ReferenceFrame* getFrame() const;
UniversalCoord convertFromUniversal(const UniversalCoord& uc, double tjd) const;
UniversalCoord convertToUniversal(const UniversalCoord& uc, double tjd) const;
Quatd convertFromUniversal(const Quatd& q, double tjd) const;
Quatd convertToUniversal(const Quatd& q, double tjd) const;
static UniversalCoord convert(const ObserverFrame* fromFrame,
const ObserverFrame* toFrame,
const UniversalCoord& uc,
double t);
static Quatd convert(const ObserverFrame* fromFrame,
const ObserverFrame* toFrame,
const Quatd& q,
double t);
private:
ReferenceFrame* createFrame(CoordinateSystem _coordSys,
const Selection& _refObject,
const Selection& _targetObject);
private:
CoordinateSystem coordSys;
ReferenceFrame* frame;
Selection targetObject;
};
/*! ObserverFrame is a wrapper class for ReferenceFrame which adds some
* annotation data. The goal is to place some restrictions on what reference
* frame can be set for an observer. General reference frames can be
* arbitrarily complex, with multiple levels of nesting. This makes it
* difficult to store them in a cel:// URL or display information about
* them for the user. The restricted set of reference frames wrapped by
* the ObserverFrame class does not suffer from such problems.
*/
class Observer
{
public:
Observer();
// The getPosition method returns the observer's position in micro light
// years.
UniversalCoord getPosition() const;
// getRelativePosition returns in units of kilometers the difference
// between the position of the observer and a location specified in
// light years.
Point3d getRelativePosition(const Point3d&) const;
Quatf getOrientation() const;
void setPosition(const UniversalCoord&);
void setPosition(const Point3d&);
Quatd getOrientation() const;
Quatf getOrientationf() const;
void setOrientation(const Quatf&);
void setOrientation(const Quatd&);
Vec3d getVelocity() const;
void setVelocity(const Vec3d&);
Vec3f getAngularVelocity() const;
void setAngularVelocity(const Vec3f&);
void setPosition(BigFix x, BigFix y, BigFix z);
void setPosition(const UniversalCoord&);
void setPosition(const Point3d&);
RigidTransform getSituation() const;
void setSituation(const RigidTransform&);
float getFOV() const;
void setFOV(float);
@ -75,30 +142,31 @@ public:
void gotoSelection(const Selection&,
double gotoTime,
Vec3f up,
astro::CoordinateSystem upFrame);
ObserverFrame::CoordinateSystem upFrame);
void gotoSelection(const Selection&,
double gotoTime,
double startInter,
double endInter,
Vec3f up,
astro::CoordinateSystem upFrame);
ObserverFrame::CoordinateSystem upFrame);
void gotoSelectionGC(const Selection&,
double gotoTime,
double startInter,
double endInter,
Vec3f up,
astro::CoordinateSystem upFrame);
ObserverFrame::CoordinateSystem upFrame);
void gotoSelection(const Selection&,
double gotoTime,
double distance,
Vec3f up,
astro::CoordinateSystem upFrame);
ObserverFrame::CoordinateSystem upFrame);
void gotoSelectionLongLat(const Selection&,
double gotoTime,
double distance,
float longitude, float latitude,
Vec3f up);
void gotoLocation(const RigidTransform& transform,
void gotoLocation(const UniversalCoord& toPosition,
const Quatd& toOrientation,
double duration);
void getSelectionLongLat(const Selection&,
double& distance,
@ -108,7 +176,7 @@ public:
double gotoTime,
double distance,
Vec3f up,
astro::CoordinateSystem upFrame);
ObserverFrame::CoordinateSystem upFrame);
void gotoSurface(const Selection&, double duration);
void centerSelection(const Selection&, double centerTime = 0.5);
void centerSelectionCO(const Selection&, double centerTime = 0.5);
@ -120,23 +188,28 @@ public:
void reverseOrientation();
void setFrame(const FrameOfReference&);
FrameOfReference getFrame() const;
void setFrame(ObserverFrame::CoordinateSystem cs, const Selection& refObj, const Selection& targetObj);
void setFrame(ObserverFrame::CoordinateSystem cs, const Selection& refObj);
void setFrame(const ObserverFrame& f);
const ObserverFrame* getFrame() const;
double getArrivalTime() const;
double getTime() const;
void setTime(double);
enum ObserverMode {
enum ObserverMode
{
Free = 0,
Travelling = 1,
};
ObserverMode getMode() const;
void setMode(ObserverMode);
enum TrajectoryType {
enum TrajectoryType
{
Linear = 0,
GreatCircle = 1,
CircularOrbit = 2,
@ -148,13 +221,13 @@ public:
double startTime;
UniversalCoord from;
UniversalCoord to;
Quatf initialOrientation;
Quatf finalOrientation;
Quatd initialOrientation;
Quatd finalOrientation;
double startInterpolation; // start of orientation interpolation phase [0-1]
double endInterpolation; // end of orientation interpolation phase [0-1]
double expFactor;
double accelTime;
Quatf rotation1; // rotation on the CircularOrbit around centerObject
Quatd rotation1; // rotation on the CircularOrbit around centerObject
Selection centerObject;
@ -171,18 +244,18 @@ public:
double startInter,
double endInter,
Vec3d offset,
astro::CoordinateSystem offsetFrame,
ObserverFrame::CoordinateSystem offsetFrame,
Vec3f up,
astro::CoordinateSystem upFrame);
ObserverFrame::CoordinateSystem upFrame);
void computeGotoParametersGC(const Selection& sel,
JourneyParams& jparams,
double gotoTime,
double startInter,
double endInter,
Vec3d offset,
astro::CoordinateSystem offsetFrame,
ObserverFrame::CoordinateSystem offsetFrame,
Vec3f up,
astro::CoordinateSystem upFrame,
ObserverFrame::CoordinateSystem upFrame,
const Selection& centerObj);
void computeCenterParameters(const Selection& sel,
JourneyParams& jparams,
@ -191,13 +264,25 @@ public:
JourneyParams& jparams,
double centerTime);
void updateUniversal();
void convertFrameCoordinates(const ObserverFrame* newFrame);
private:
double simTime;
RigidTransform situation;
// Position, orientation, and velocity in the observer's reference frame
UniversalCoord position;
Quatd orientation;
Vec3d velocity;
Vec3f angularVelocity;
// Position and orientation in universal coordinates, derived from the
// equivalent quantities in the observer reference frame.
UniversalCoord positionUniv;
Quatd orientationUniv;
ObserverFrame* frame;
double realTime;
double targetSpeed;
@ -206,11 +291,10 @@ public:
double beginAccelTime;
ObserverMode observerMode;
JourneyParams journey;
FrameOfReference frame;
JourneyParams journey;
Selection trackObject;
Quatf trackingOrientation; // orientation prior to selecting tracking
Quatd trackingOrientation; // orientation prior to selecting tracking
float fov;
bool reverseFlag;

View File

@ -2163,7 +2163,7 @@ void Renderer::render(const Observer& observer,
// Highlight the selected object
highlightObject = sel;
Quatf cameraOrientation = observer.getOrientation();
Quatf cameraOrientation = observer.getOrientationf();
// Set up the camera for star rendering; the units of this phase
// are light years.
@ -2445,7 +2445,7 @@ void Renderer::render(const Observer& observer,
Frustum frustum(degToRad(fov),
(float) windowWidth / (float) windowHeight,
MinNearPlaneDistance);
Mat3f viewMat = conjugate(observer.getOrientation()).toMatrix3();
Mat3f viewMat = conjugate(observer.getOrientationf()).toMatrix3();
// Remove objects from the render list that lie completely outside the
// view frustum.
@ -2898,7 +2898,7 @@ void Renderer::render(const Observer& observer,
renderMarkers(*universe.getMarkers(),
observer.getPosition(),
observer.getOrientation(),
observer.getOrientationf(),
now);
if ((renderFlags & ShowSmoothLines) != 0)
@ -7159,7 +7159,7 @@ void Renderer::buildRenderLists(const Star& sun,
Point3f starPos = sun.getPosition();
Point3d observerPos = astrocentricPosition(observer.getPosition(),
sun, now);
Mat3f viewMat = observer.getOrientation().toMatrix3();
Mat3f viewMat = observer.getOrientationf().toMatrix3();
Vec3f viewMatZ(viewMat[2][0], viewMat[2][1], viewMat[2][2]);
Body* lastPrimary = NULL;
@ -7334,7 +7334,7 @@ void Renderer::buildRenderLists(const Star& sun,
}
#endif
if (showLabels && (pos * conjugate(observer.getOrientation()).toMatrix3()).z < 0)
if (showLabels && (pos * conjugate(observer.getOrientationf()).toMatrix3()).z < 0)
{
float boundingRadiusSize = (float) (body->getOrbit()->getBoundingRadius() / distanceFromObserver) / pixelSize;
if (boundingRadiusSize > minOrbitSize)
@ -7552,7 +7552,7 @@ void Renderer::addStarOrbitToRenderList(const Star& star,
if ((renderFlags & ShowOrbits) != 0 &&
((orbitMask & Body::Stellar) != 0 || highlightObject.star() == &star))
{
Mat3f viewMat = observer.getOrientation().toMatrix3();
Mat3f viewMat = observer.getOrientationf().toMatrix3();
Vec3f viewMatZ(viewMat[2][0], viewMat[2][1], viewMat[2][2]);
if (star.getOrbit() != NULL)
@ -7830,7 +7830,7 @@ void StarRenderer::process(const Star& star, float distance, float appMag)
}
else
{
Mat3f viewMat = observer->getOrientation().toMatrix3();
Mat3f viewMat = observer->getOrientationf().toMatrix3();
Vec3f viewMatZ(viewMat[2][0], viewMat[2][1], viewMat[2][2]);
RenderListEntry rle;
@ -8022,7 +8022,7 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
}
else
{
Mat3f viewMat = observer->getOrientation().toMatrix3();
Mat3f viewMat = observer->getOrientationf().toMatrix3();
Vec3f viewMatZ(viewMat[2][0], viewMat[2][1], viewMat[2][2]);
RenderListEntry rle;
@ -8075,7 +8075,7 @@ void Renderer::renderStars(const StarDatabase& starDB,
starRenderer.starDB = &starDB;
starRenderer.observer = &observer;
starRenderer.obsPos = obsPos;
starRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientation().toMatrix3();
starRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientationf().toMatrix3();
starRenderer.glareParticles = &glareParticles;
starRenderer.renderList = &renderList;
starRenderer.starVertexBuffer = starVertexBuffer;
@ -8119,7 +8119,7 @@ void Renderer::renderStars(const StarDatabase& starDB,
glareParticles.clear();
starVertexBuffer->setBillboardOrientation(observer.getOrientation());
starVertexBuffer->setBillboardOrientation(observer.getOrientationf());
glEnable(GL_TEXTURE_2D);
@ -8142,7 +8142,7 @@ void Renderer::renderStars(const StarDatabase& starDB,
}
starDB.findVisibleStars(starRenderer,
obsPos,
observer.getOrientation(),
observer.getOrientationf(),
degToRad(fov),
(float) windowWidth / (float) windowHeight,
faintestMagNight);
@ -8153,7 +8153,7 @@ void Renderer::renderStars(const StarDatabase& starDB,
starRenderer.starVertexBuffer->finish();
gaussianGlareTex->bind();
renderParticles(glareParticles, observer.getOrientation());
renderParticles(glareParticles, observer.getOrientationf());
}
@ -8169,7 +8169,7 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
starRenderer.starDB = &starDB;
starRenderer.observer = &observer;
starRenderer.obsPos = obsPos;
starRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientation().toMatrix3();
starRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientationf().toMatrix3();
starRenderer.renderList = &renderList;
starRenderer.starVertexBuffer = pointStarVertexBuffer;
starRenderer.glareVertexBuffer = glareVertexBuffer;
@ -8216,7 +8216,7 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
starDB.findVisibleStars(starRenderer,
obsPos,
observer.getOrientation(),
observer.getOrientationf(),
degToRad(fov),
(float) windowWidth / (float) windowHeight,
faintestMagNight);
@ -8334,7 +8334,7 @@ void DSORenderer::process(DeepSkyObject* const & dso,
dso->render(*context,
relPos,
observer->getOrientation(),
observer->getOrientationf(),
(float) brightness,
pixelSize);
glPopMatrix();
@ -8419,10 +8419,10 @@ void Renderer::renderDeepSkyObjects(const Universe& universe,
dsoRenderer.context = context;
dsoRenderer.renderer = this;
dsoRenderer.dsoDB = dsoDB;
dsoRenderer.orientationMatrix = conjugate(observer.getOrientation()).toMatrix3();
dsoRenderer.orientationMatrix = conjugate(observer.getOrientationf()).toMatrix3();
dsoRenderer.observer = &observer;
dsoRenderer.obsPos = obsPos;
dsoRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientation().toMatrix3();
dsoRenderer.viewNormal = Vec3f(0, 0, -1) * observer.getOrientationf().toMatrix3();
dsoRenderer.fov = fov;
// size/pixelSize =0.86 at 120deg, 1.43 at 45deg and 1.6 at 0deg.
dsoRenderer.size = pixelSize * 1.6f / corrFac;
@ -8456,7 +8456,7 @@ void Renderer::renderDeepSkyObjects(const Universe& universe,
dsoDB->findVisibleDSOs(dsoRenderer,
obsPos,
observer.getOrientation(),
observer.getOrientationf(),
degToRad(fov),
(float) windowWidth / (float) windowHeight,
2 * faintestMagNight);
@ -8514,7 +8514,7 @@ void Renderer::renderCelestialSphere(const Observer& observer)
glLineWidth(1.0f);
Mat3f m = conjugate(observer.getOrientation()).toMatrix3();
Mat3f m = conjugate(observer.getOrientationf()).toMatrix3();
// Show the declination labels
for (i = 0; i < DecLabelCount; i++)
@ -8573,7 +8573,7 @@ void Renderer::labelConstellations(const AsterismList& asterisms,
Vec3f rpos = Point3f(avg.x, avg.y, avg.z) - observerPos;
if ((observer.getOrientation().toMatrix3() * rpos).z < 0)
if ((observer.getOrientationf().toMatrix3() * rpos).z < 0)
{
// We'll linearly fade the labels as a function of the
// observer's distance to the origin of coordinates:

View File

@ -166,7 +166,7 @@ void Simulation::setTrackedObject(const Selection& sel)
Selection Simulation::pickObject(Vec3f pickRay, int renderFlags, float tolerance)
{
return universe->pick(activeObserver->getPosition(),
pickRay * activeObserver->getOrientation().toMatrix4(),
pickRay * activeObserver->getOrientationf().toMatrix4(),
activeObserver->getTime(),
renderFlags,
faintestVisible,
@ -236,18 +236,20 @@ void Simulation::setObserverMode(Observer::ObserverMode mode)
activeObserver->setMode(mode);
}
void Simulation::setFrame(astro::CoordinateSystem coordSys,
const Selection& sel)
void Simulation::setFrame(ObserverFrame::CoordinateSystem coordSys,
const Selection& refObject,
const Selection& targetObject)
{
activeObserver->setFrame(FrameOfReference(coordSys, sel));
activeObserver->setFrame(coordSys, refObject, targetObject);
}
void Simulation::setFrame(const FrameOfReference& _frame)
void Simulation::setFrame(ObserverFrame::CoordinateSystem coordSys,
const Selection& refObject)
{
activeObserver->setFrame(_frame);
activeObserver->setFrame(coordSys, refObject);
}
FrameOfReference Simulation::getFrame() const
const ObserverFrame* Simulation::getFrame() const
{
return activeObserver->getFrame();
}
@ -286,7 +288,7 @@ float Simulation::getTargetSpeed()
void Simulation::gotoSelection(double gotoTime,
Vec3f up,
astro::CoordinateSystem upFrame)
ObserverFrame::CoordinateSystem upFrame)
{
if (selection.getType() == Selection::Type_Location)
{
@ -303,9 +305,9 @@ void Simulation::gotoSelection(double gotoTime,
void Simulation::gotoSelection(double gotoTime,
double distance,
Vec3f up,
astro::CoordinateSystem upFrame)
ObserverFrame::CoordinateSystem upCoordSys)
{
activeObserver->gotoSelection(selection, gotoTime, distance, up, upFrame);
activeObserver->gotoSelection(selection, gotoTime, distance, up, upCoordSys);
}
void Simulation::gotoSelectionLongLat(double gotoTime,
@ -319,10 +321,11 @@ void Simulation::gotoSelectionLongLat(double gotoTime,
}
void Simulation::gotoLocation(const RigidTransform& transform,
void Simulation::gotoLocation(const UniversalCoord& position,
const Quatd& orientation,
double duration)
{
activeObserver->gotoLocation(transform, duration);
activeObserver->gotoLocation(position, orientation, duration);
}

View File

@ -61,14 +61,14 @@ class Simulation
Selection findObjectFromPath(std::string s, bool i18n = false);
std::vector<std::string> getObjectCompletion(std::string s, bool withLocations = false);
void gotoSelection(double gotoTime,
Vec3f up, astro::CoordinateSystem upFrame);
Vec3f up, ObserverFrame::CoordinateSystem upFrame);
void gotoSelection(double gotoTime, double distance,
Vec3f up, astro::CoordinateSystem upFrame);
Vec3f up, ObserverFrame::CoordinateSystem upFrame);
void gotoSelectionLongLat(double gotoTime,
double distance,
float longitude, float latitude,
Vec3f up);
void gotoLocation(const RigidTransform& transform, double duration);
void gotoLocation(const UniversalCoord& toPosition, const Quatd& toOrientation, double duration);
void getSelectionLongLat(double& distance,
double& longitude,
double& latitude);
@ -107,9 +107,9 @@ class Simulation
void setObserverMode(Observer::ObserverMode);
Observer::ObserverMode getObserverMode() const;
void setFrame(astro::CoordinateSystem, const Selection&);
void setFrame(const FrameOfReference&);
FrameOfReference getFrame() const;
void setFrame(ObserverFrame::CoordinateSystem, const Selection& refObject, const Selection& targetObject);
void setFrame(ObserverFrame::CoordinateSystem, const Selection& refObject);
const ObserverFrame* getFrame() const;
private:
SolarSystem* getSolarSystem(const Star* star);

View File

@ -140,7 +140,7 @@ float ComputeRotationCoarseness(Simulation& sim)
{
float coarseness = 1.5f;
Selection selection = sim.getActiveObserver()->getFrame().refObject;
Selection selection = sim.getActiveObserver()->getFrame()->getRefObject();
if (selection.getType() == Selection::Type_Star ||
selection.getType() == Selection::Type_Body)
{
@ -449,7 +449,7 @@ void CelestiaCore::addFavorite(string name, string parentFolder, FavoritesList::
FavoritesEntry* fav = new FavoritesEntry();
fav->jd = sim->getTime();
fav->position = sim->getObserver().getPosition();
fav->orientation = sim->getObserver().getOrientation();
fav->orientation = sim->getObserver().getOrientationf();
fav->name = name;
fav->isFolder = false;
fav->parentFolder = parentFolder;
@ -460,7 +460,7 @@ void CelestiaCore::addFavorite(string name, string parentFolder, FavoritesList::
else
fav->selectionName = sel.getName();
fav->coordSys = sim->getFrame().coordSys;
fav->coordSys = sim->getFrame()->getCoordinateSystem();
favorites->insert(pos, fav);
}
@ -937,11 +937,12 @@ void CelestiaCore::mouseMove(float dx, float dy, int modifiers)
{
Observer& observer = sim->getObserver();
Vec3d v = Vec3d(0, 0, dx * -MouseRotationSensitivity);
RigidTransform rt = observer.getSituation();
Quatd dr = 0.5 * (v * rt.rotation);
rt.rotation += dr;
rt.rotation.normalize();
observer.setSituation(rt);
Quatd obsOrientation = observer.getOrientation();
Quatd dr = 0.5 * (v * obsOrientation);
obsOrientation += dr;
obsOrientation.normalize();
observer.setOrientation(obsOrientation);
}
}
else if (checkMask(modifiers, LeftButton | ShiftKey))
@ -1571,7 +1572,7 @@ void CelestiaCore::charEntered(const char *c_p, int /*modifiers*/)
if (sim->getObserverMode() == Observer::Travelling)
sim->setObserverMode(Observer::Free);
else
sim->setFrame(astro::Universal, Selection());
sim->setFrame(ObserverFrame::Universal, Selection());
if (!sim->getTrackedObject().empty())
sim->setTrackedObject(Selection());
}
@ -1853,9 +1854,9 @@ void CelestiaCore::charEntered(const char *c_p, int /*modifiers*/)
case 'G':
addToHistory();
if (sim->getFrame().coordSys == astro::Universal)
if (sim->getFrame()->getCoordinateSystem() == ObserverFrame::Universal)
sim->follow();
sim->gotoSelection(5.0, Vec3f(0, 1, 0), astro::ObserverLocal);
sim->gotoSelection(5.0, Vec3f(0, 1, 0), ObserverFrame::ObserverLocal);
break;
case 'H':
@ -2266,7 +2267,7 @@ void CelestiaCore::tick()
av = av * (float) exp(-dt * RotationDecay);
float fov = sim->getActiveObserver()->getFOV() / stdFOV;
FrameOfReference frame = sim->getFrame();
Selection refObject = sim->getFrame()->getRefObject();
// Handle arrow keys; disable them when the log console is displayed,
// because then they're used to scroll up and down.
@ -2285,11 +2286,11 @@ void CelestiaCore::tick()
}
else
{
if (!frame.refObject.empty())
if (!refObject.empty())
{
Quatf orientation = sim->getObserver().getOrientation();
Quatf orientation = sim->getObserver().getOrientationf();
Vec3d upd = sim->getObserver().getPosition() -
frame.refObject.getPosition(sim->getTime());
refObject.getPosition(sim->getTime());
upd.normalize();
Vec3f up((float) upd.x, (float) upd.y, (float) upd.z);
@ -2359,7 +2360,7 @@ void CelestiaCore::tick()
sim->setTargetSpeed(sim->getTargetSpeed());
}
if (!frame.refObject.empty())
if (!refObject.empty())
{
Quatf q(1.0f);
float coarseness = ComputeRotationCoarseness(*sim);
@ -3452,32 +3453,34 @@ void CelestiaCore::renderOverlay()
*overlay << '\n';
{
FrameOfReference frame = sim->getFrame();
//FrameOfReference frame = sim->getFrame();
Selection refObject = sim->getFrame()->getRefObject();
ObserverFrame::CoordinateSystem coordSys = sim->getFrame()->getCoordinateSystem();
switch (frame.coordSys)
switch (coordSys)
{
case astro::Ecliptical:
case ObserverFrame::Ecliptical:
*overlay << _("Follow ");
displaySelectionName(*overlay, frame.refObject,
displaySelectionName(*overlay, refObject,
*sim->getUniverse());
break;
case astro::Geographic:
case ObserverFrame::BodyFixed:
*overlay << _("Sync Orbit ");
displaySelectionName(*overlay, frame.refObject,
displaySelectionName(*overlay, refObject,
*sim->getUniverse());
break;
case astro::PhaseLock:
case ObserverFrame::PhaseLock:
*overlay << _("Lock ");
displaySelectionName(*overlay, frame.refObject,
displaySelectionName(*overlay, refObject,
*sim->getUniverse());
*overlay << " -> ";
displaySelectionName(*overlay, frame.targetObject,
displaySelectionName(*overlay, sim->getFrame()->getTargetObject(),
*sim->getUniverse());
break;
case astro::Chase:
case ObserverFrame::Chase:
*overlay << _("Chase ");
displaySelectionName(*overlay, frame.refObject,
displaySelectionName(*overlay, refObject,
*sim->getUniverse());
break;
@ -3582,7 +3585,7 @@ void CelestiaCore::renderOverlay()
// Display RA/Dec for the selection, but only when the observer is near
// the Earth.
Selection refObject = sim->getFrame().refObject;
Selection refObject = sim->getFrame()->getRefObject();
if (refObject.body() && refObject.body()->getName() == "Earth")
{
Body* earth = refObject.body();

File diff suppressed because it is too large Load Diff

View File

@ -88,13 +88,13 @@ FavoritesList* ReadFavoritesList(istream& in)
string coordSysName;
favParams->getString("coordsys", coordSysName);
if (coordSysName == "ecliptical")
fav->coordSys = astro::Ecliptical;
fav->coordSys = ObserverFrame::Ecliptical;
else if (coordSysName == "equatorial")
fav->coordSys = astro::Equatorial;
fav->coordSys = ObserverFrame::Equatorial;
else if (coordSysName == "geographic")
fav->coordSys = astro::Geographic;
fav->coordSys = ObserverFrame::BodyFixed;
else
fav->coordSys = astro::Universal;
fav->coordSys = ObserverFrame::Universal;
favorites->insert(favorites->end(), fav);
}
@ -137,19 +137,19 @@ void WriteFavoritesList(FavoritesList& favorites, ostream& out)
out << "\tcoordsys \"";
switch (fav->coordSys)
{
case astro::Universal:
case ObserverFrame::Universal:
out << "universal"; break;
case astro::Ecliptical:
case ObserverFrame::Ecliptical:
out << "ecliptical"; break;
case astro::Equatorial:
case ObserverFrame::Equatorial:
out << "equatorial"; break;
case astro::Geographic:
case ObserverFrame::BodyFixed:
out << "geographic"; break;
case astro::ObserverLocal:
case ObserverFrame::ObserverLocal:
out << "local"; break;
case astro::PhaseLock:
case ObserverFrame::PhaseLock:
out << "phaselock"; break;
case astro::Chase:
case ObserverFrame::Chase:
out << "chase"; break;
}
out << "\"\n";

View File

@ -15,7 +15,7 @@
#include <iostream>
#include <celmath/vecmath.h>
#include <celmath/quaternion.h>
#include <celengine/astro.h>
#include <celengine/observer.h>
struct FavoritesEntry
@ -29,7 +29,7 @@ struct FavoritesEntry
bool isFolder;
std::string parentFolder;
astro::CoordinateSystem coordSys;
ObserverFrame::CoordinateSystem coordSys;
};
typedef std::vector<FavoritesEntry*> FavoritesList;

View File

@ -52,27 +52,27 @@ Url::Url(const std::string& str, CelestiaCore *core):
if (!compareIgnoringCase(modeStr, std::string("Freeflight")))
{
mode = astro::Universal;
mode = ObserverFrame::Universal;
nbBodies = 0;
}
else if (!compareIgnoringCase(modeStr, std::string("Follow")))
{
mode = astro::Ecliptical;
mode = ObserverFrame::Ecliptical;
nbBodies = 1;
}
else if (!compareIgnoringCase(modeStr, std::string("SyncOrbit")))
{
mode = astro::Geographic;
mode = ObserverFrame::BodyFixed;
nbBodies = 1;
}
else if (!compareIgnoringCase(modeStr, std::string("Chase")))
{
mode = astro::Chase;
mode = ObserverFrame::Chase;
nbBodies = 1;
}
else if (!compareIgnoringCase(modeStr, std::string("PhaseLock")))
{
mode = astro::PhaseLock;
mode = ObserverFrame::PhaseLock;
nbBodies = 2;
}
else if (!compareIgnoringCase(modeStr, std::string("Settings")))
@ -125,9 +125,9 @@ Url::Url(const std::string& str, CelestiaCore *core):
return; // Number of bodies in Url doesn't match Mode
}
if (nbBodies == 0) ref = FrameOfReference();
if (nbBodies == 1) ref = FrameOfReference(mode, bodies[0]);
if (nbBodies == 2) ref = FrameOfReference(mode, bodies[0], bodies[1]);
if (nbBodies == 0) ref = ObserverFrame();
if (nbBodies == 1) ref = ObserverFrame(mode, bodies[0]);
if (nbBodies == 2) ref = ObserverFrame(mode, bodies[0], bodies[1]);
fromString = true;
std::string time="";
@ -218,15 +218,15 @@ Url::Url(CelestiaCore* core, UrlType type)
this->type = type;
modeStr = getCoordSysName(sim->getFrame().coordSys);
modeStr = getCoordSysName(sim->getFrame()->getCoordinateSystem());
if (type == Settings) modeStr = "Settings";
ref = sim->getFrame();
ref = *sim->getFrame();
urlStr += "cel://" + modeStr;
if (type != Settings && sim->getFrame().coordSys != astro::Universal) {
body1 = getSelectionName(sim->getFrame().refObject);
if (type != Settings && sim->getFrame()->getCoordinateSystem() != ObserverFrame::Universal) {
body1 = getSelectionName(sim->getFrame()->getRefObject());
urlStr += "/" + body1;
if (sim->getFrame().coordSys == astro::PhaseLock) {
body2 = getSelectionName(sim->getFrame().targetObject);
if (sim->getFrame()->getCoordinateSystem() == ObserverFrame::PhaseLock) {
body2 = getSelectionName(sim->getFrame()->getTargetObject());
urlStr += "/" + body2;
}
}
@ -245,7 +245,7 @@ Url::Url(CelestiaCore* core, UrlType type)
urlStr += "&y=" + coord.y.toString();
urlStr += "&z=" + coord.z.toString();
orientation = sim->getObserver().getOrientation();
orientation = sim->getObserver().getOrientationf();
sprintf(buff, "&ow=%f&ox=%f&oy=%f&oz=%f", orientation.w, orientation.x, orientation.y, orientation.z);
urlStr += buff;
break;
@ -371,23 +371,23 @@ std::map<std::string, std::string> Url::parseUrlParams(const std::string& url) c
}
std::string Url::getCoordSysName(astro::CoordinateSystem mode) const
std::string Url::getCoordSysName(ObserverFrame::CoordinateSystem mode) const
{
switch (mode)
{
case astro::Universal:
case ObserverFrame::Universal:
return "Freeflight";
case astro::Ecliptical:
case ObserverFrame::Ecliptical:
return "Follow";
case astro::Geographic:
case ObserverFrame::BodyFixed:
return "SyncOrbit";
case astro::Chase:
case ObserverFrame::Chase:
return "Chase";
case astro::PhaseLock:
case ObserverFrame::PhaseLock:
return "PhaseLock";
case astro::Equatorial:
case ObserverFrame::Equatorial:
return "Unknown";
case astro::ObserverLocal:
case ObserverFrame::ObserverLocal:
return "Unknown";
}
return "Unknown";
@ -469,7 +469,7 @@ void Url::goTo()
switch(type) {
case Absolute:// Intentional Fall-Through
case Relative:
sim->setFrame(ref);
sim->setFrame(ref.getCoordinateSystem(), ref.getRefObject(), ref.getTargetObject());
sim->getActiveObserver()->setFOV(degToRad(fieldOfView));
appCore->setZoomFromFOV();
sim->setTimeScale(timeScale);

View File

@ -52,11 +52,11 @@ private:
CelestiaCore *appCore;
FrameOfReference ref;
ObserverFrame ref;
Selection selected;
Selection tracked;
astro::CoordinateSystem mode;
ObserverFrame::CoordinateSystem mode;
int nbBodies;
float fieldOfView;
float timeScale;
@ -66,7 +66,7 @@ private:
bool pauseState;
std::map<std::string, std::string> parseUrlParams(const std::string& url) const;
std::string getCoordSysName(astro::CoordinateSystem mode) const;
std::string getCoordSysName(ObserverFrame::CoordinateSystem mode) const;
std::string getSelectionName(const Selection& selection) const;
std::string getBodyShortName(const std::string& body) const;
static std::string decode_string(const std::string& str);