Eigenized Body and Selection classes; adapted dependent code. Removed some

miscellaneous compile warnings in other modules.
sensor-dev
Chris Laurel 2009-07-16 23:37:48 +00:00
parent b42accebaf
commit 86d1808519
24 changed files with 299 additions and 289 deletions

View File

@ -458,7 +458,7 @@ BodyAxisArrows::BodyAxisArrows(const Body& _body) :
Quaterniond
BodyAxisArrows::getOrientation(double tdb) const
{
return (Quaterniond(AngleAxis<double>(PI, Vector3d::UnitY())) * toEigen(body.getEclipticToBodyFixed(tdb))).conjugate();
return (Quaterniond(AngleAxis<double>(PI, Vector3d::UnitY())) * body.getEclipticToBodyFixed(tdb)).conjugate();
}
@ -475,5 +475,5 @@ FrameAxisArrows::FrameAxisArrows(const Body& _body) :
Quaterniond
FrameAxisArrows::getOrientation(double tdb) const
{
return toEigen(~body.getEclipticToFrame(tdb));
return body.getEclipticToFrame(tdb).conjugate();
}

View File

@ -21,9 +21,12 @@
#include "timelinephase.h"
#include "frametree.h"
#include "referencemark.h"
#include "eigenport.h"
using namespace Eigen;
using namespace std;
Body::Body(PlanetarySystem* _system, const string& _name) :
names(1),
localizedNameIndex(0),
@ -35,7 +38,7 @@ Body::Body(PlanetarySystem* _system, const string& _name) :
semiAxes(1.0f, 1.0f, 1.0f),
mass(0.0f),
albedo(0.5f),
orientation(1.0f),
geometryOrientation(Quaternionf::Identity()),
geometry(InvalidResource),
geometryScale(1.0f),
surface(Color(1.0f, 1.0f, 1.0f)),
@ -87,10 +90,10 @@ Body::~Body()
void Body::setDefaultProperties()
{
radius = 1.0f;
semiAxes = Vec3f(1.0f, 1.0f, 1.0f);
semiAxes = Vector3f::Ones();
mass = 0.0f;
albedo = 0.5f;
orientation = Quatf(1.0f);
geometryOrientation = Quaternionf::Identity();
geometry = InvalidResource;
surface = Surface(Color::White);
delete atmosphere;
@ -304,33 +307,33 @@ void Body::setAlbedo(float _albedo)
}
Quatf Body::getOrientation() const
Quaternionf Body::getGeometryOrientation() const
{
return orientation;
return geometryOrientation;
}
void Body::setOrientation(const Quatf& q)
void Body::setGeometryOrientation(const Quaternionf& orientation)
{
orientation = q;
geometryOrientation = orientation;
}
/*! Set the semiaxes of a body.
*/
void Body::setSemiAxes(const Vec3f& _semiAxes)
void Body::setSemiAxes(const Vector3f& _semiAxes)
{
semiAxes = _semiAxes;
// Radius will always be the largest of the three semi axes
radius = max(semiAxes.x, max(semiAxes.y, semiAxes.z));
radius = semiAxes.maxCoeff();
recomputeCullingRadius();
}
/*! Retrieve the body's semiaxes
*/
Vec3f Body::getSemiAxes() const
Vector3f Body::getSemiAxes() const
{
return semiAxes;
}
@ -356,8 +359,8 @@ float Body::getRadius() const
bool Body::isSphere() const
{
return (geometry == InvalidResource) &&
(semiAxes.x == semiAxes.y) &&
(semiAxes.x == semiAxes.z);
(semiAxes.x() == semiAxes.y()) &&
(semiAxes.x() == semiAxes.z());
}
@ -464,59 +467,69 @@ void Body::setAtmosphere(const Atmosphere& _atmosphere)
*/
UniversalCoord Body::getPosition(double tdb) const
{
Point3d position(0.0, 0.0, 0.0);
Vector3d position = Vector3d::Zero();
const TimelinePhase* phase = timeline->findPhase(tdb);
Point3d p = phase->orbit()->positionAtTime(tdb);
Vector3d p = toEigen(phase->orbit()->positionAtTime(tdb));
ReferenceFrame* frame = phase->orbitFrame();
while (frame->getCenter().getType() == Selection::Type_Body)
{
phase = frame->getCenter().body()->timeline->findPhase(tdb);
position += Vec3d(p.x, p.y, p.z) * frame->getOrientation(tdb).toMatrix3();
p = phase->orbit()->positionAtTime(tdb);
position += toEigen(frame->getOrientation(tdb)).conjugate() * p;
p = toEigen(phase->orbit()->positionAtTime(tdb));
frame = phase->orbitFrame();
}
position += Vec3d(p.x, p.y, p.z) * frame->getOrientation(tdb).toMatrix3();
position += toEigen(frame->getOrientation(tdb)).conjugate() * p;
#if 0
if (frame->getCenter().star())
return astro::universalPosition(position, frame->getCenter().star()->getPosition(tdb));
else
return astro::universalPosition(position, frame->getCenter().getPosition(tdb));
#endif
if (frame->getCenter().star())
return frame->getCenter().star()->getPosition(tdb).offsetKm(position);
else
return frame->getCenter().getPosition(tdb).offsetKm(position);
}
/*! Get the orientation of the body in the universal coordinate system.
*/
Quatd Body::getOrientation(double tdb) const
Quaterniond Body::getOrientation(double tdb) const
{
// TODO: This method overloads getOrientation(), but the two do very
// different things. The other method should be renamed to
// getModelOrientation().
const TimelinePhase* phase = timeline->findPhase(tdb);
return phase->rotationModel()->orientationAtTime(tdb) *
phase->bodyFrame()->getOrientation(tdb);
return toEigen(phase->rotationModel()->orientationAtTime(tdb) *
phase->bodyFrame()->getOrientation(tdb));
}
/*! Get the velocity of the body in the universal frame.
*/
Vec3d Body::getVelocity(double tdb) const
Vector3d Body::getVelocity(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
ReferenceFrame* orbitFrame = phase->orbitFrame();
Vec3d v = phase->orbit()->velocityAtTime(tdb);
v = v * orbitFrame->getOrientation(tdb).toMatrix3() + orbitFrame->getCenter().getVelocity(tdb);
Vector3d v = toEigen(phase->orbit()->velocityAtTime(tdb));
v = toEigen(orbitFrame->getOrientation(tdb)).conjugate() * v + orbitFrame->getCenter().getVelocity(tdb);
if (!orbitFrame->isInertial())
{
Vec3d r = Selection(const_cast<Body*>(this)).getPosition(tdb) - orbitFrame->getCenter().getPosition(tdb);
#if 0
Vec3d r = Selection(const_cast<Body*>(this)).getPosition(tdb) - orbitFrame->getCenter().getPosition(tdb);
r = r * astro::microLightYearsToKilometers(1.0);
v += cross(orbitFrame->getAngularVelocity(tdb), r);
}
#endif
Vector3d r = Selection(const_cast<Body*>(this)).getPosition(tdb).offsetFromKm(orbitFrame->getCenter().getPosition(tdb));
v += toEigen(orbitFrame->getAngularVelocity(tdb)).cross(r);
}
return v;
}
@ -524,17 +537,17 @@ Vec3d Body::getVelocity(double tdb) const
/*! Get the angular velocity of the body in the universal frame.
*/
Vec3d Body::getAngularVelocity(double tdb) const
Vector3d Body::getAngularVelocity(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
Vec3d v = phase->rotationModel()->angularVelocityAtTime(tdb);
Vector3d v = toEigen(phase->rotationModel()->angularVelocityAtTime(tdb));
ReferenceFrame* bodyFrame = phase->bodyFrame();
v = v * bodyFrame->getOrientation(tdb).toMatrix3();
v = toEigen(bodyFrame->getOrientation(tdb)).conjugate() * v;
if (!bodyFrame->isInertial())
{
v += bodyFrame->getAngularVelocity(tdb);
v += toEigen(bodyFrame->getAngularVelocity(tdb));
}
return v;
@ -547,116 +560,115 @@ Vec3d Body::getAngularVelocity(double tdb) const
* is ultimately defined with respect to some star or star
* system barycenter.
*/
Mat4d Body::getLocalToAstrocentric(double tdb) const
Matrix4d Body::getLocalToAstrocentric(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
Point3d p = phase->orbitFrame()->convertToAstrocentric(phase->orbit()->positionAtTime(tdb), tdb);
return Mat4d::translation(p);
Vector3d p = toEigen(phase->orbitFrame()->convertToAstrocentric(phase->orbit()->positionAtTime(tdb), tdb));
return Transform3d(Translation3d(p)).matrix();
}
/*! Get the position of the center of the body in astrocentric ecliptic coordinates.
*/
Point3d Body::getAstrocentricPosition(double tdb) const
Vector3d Body::getAstrocentricPosition(double tdb) const
{
// TODO: Switch the iterative method used in getPosition
const TimelinePhase* phase = timeline->findPhase(tdb);
return phase->orbitFrame()->convertToAstrocentric(phase->orbit()->positionAtTime(tdb), tdb);
return toEigen(phase->orbitFrame()->convertToAstrocentric(phase->orbit()->positionAtTime(tdb), tdb));
}
/*! Get a rotation that converts from the ecliptic frame to the body frame.
*/
Quatd Body::getEclipticToFrame(double tdb) const
Quaterniond Body::getEclipticToFrame(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
return phase->bodyFrame()->getOrientation(tdb);
return toEigen(phase->bodyFrame()->getOrientation(tdb));
}
/*! Get a rotation that converts from the ecliptic frame to the body's
* mean equatorial frame.
*/
Quatd Body::getEclipticToEquatorial(double tdb) const
Quaterniond Body::getEclipticToEquatorial(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
return phase->rotationModel()->equatorOrientationAtTime(tdb) *
phase->bodyFrame()->getOrientation(tdb);
return toEigen(phase->rotationModel()->equatorOrientationAtTime(tdb)) *
toEigen(phase->bodyFrame()->getOrientation(tdb));
}
/*! Get a rotation that converts from the ecliptic frame to this
* objects's body fixed frame.
*/
Quatd Body::getEclipticToBodyFixed(double tdb) const
Quaterniond Body::getEclipticToBodyFixed(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
return phase->rotationModel()->orientationAtTime(tdb) *
phase->bodyFrame()->getOrientation(tdb);
return toEigen(phase->rotationModel()->orientationAtTime(tdb)) *
toEigen(phase->bodyFrame()->getOrientation(tdb));
}
// The body-fixed coordinate system has an origin at the center of the
// body, y-axis parallel to the rotation axis, x-axis through the prime
// meridian, and z-axis at a right angle the xy plane.
Quatd Body::getEquatorialToBodyFixed(double tdb) const
Quaterniond Body::getEquatorialToBodyFixed(double tdb) const
{
const TimelinePhase* phase = timeline->findPhase(tdb);
return phase->rotationModel()->spin(tdb);
return toEigen(phase->rotationModel()->spin(tdb));
}
/*! Get a transformation to convert from the object's body fixed frame
* to the astrocentric ecliptic frame.
*/
Mat4d Body::getBodyFixedToAstrocentric(double tdb) const
Matrix4d Body::getBodyFixedToAstrocentric(double tdb) const
{
return getEquatorialToBodyFixed(tdb).toMatrix4() * getLocalToAstrocentric(tdb);
//return getEquatorialToBodyFixed(tdb).toMatrix4() * getLocalToAstrocentric(tdb);
Matrix4d m = Transform3d(getEquatorialToBodyFixed(tdb)).matrix();
return m * getLocalToAstrocentric(tdb);
}
Vec3d Body::planetocentricToCartesian(double lon, double lat, double alt) const
Vector3d Body::planetocentricToCartesian(double lon, double lat, double alt) const
{
double phi = -degToRad(lat) + PI / 2;
double theta = degToRad(lon) - PI;
Vec3d pos(cos(theta) * sin(phi),
cos(phi),
-sin(theta) * sin(phi));
Vector3d pos(cos(theta) * sin(phi),
cos(phi),
-sin(theta) * sin(phi));
return pos * (getRadius() + alt);
}
Vec3d Body::planetocentricToCartesian(const Vec3d& lonLatAlt) const
Vector3d Body::planetocentricToCartesian(const Vector3d& lonLatAlt) const
{
return planetocentricToCartesian(lonLatAlt.x, lonLatAlt.y, lonLatAlt.z);
return planetocentricToCartesian(lonLatAlt.x(), lonLatAlt.y(), lonLatAlt.z());
}
/*! Convert cartesian body-fixed coordinates to spherical planetocentric
* coordinates.
*/
Vec3d Body::cartesianToPlanetocentric(const Vec3d& v) const
Vector3d Body::cartesianToPlanetocentric(const Vector3d& v) const
{
Vec3d w = v;
w.normalize();
Vector3d w = v.normalized();
double lat = PI / 2.0 - acos(w.y);
double lon = atan2(w.z, -w.x);
double lat = PI / 2.0 - acos(w.y());
double lon = atan2(w.z(), -w.x());
return Vec3d(lon, lat, v.length() - getRadius());
return Vector3d(lon, lat, v.norm() - getRadius());
}
/*! Convert body-centered ecliptic coordinates to spherical planetocentric
* coordinates.
*/
Vec3d Body::eclipticToPlanetocentric(const Vec3d& ecl, double tdb) const
Vector3d Body::eclipticToPlanetocentric(const Vector3d& ecl, double tdb) const
{
Quatd q = getEclipticToBodyFixed(tdb);
Vec3d bf = ecl * (~q).toMatrix3();
Vector3d bf = getEclipticToBodyFixed(tdb) * ecl;
return cartesianToPlanetocentric(bf);
}
@ -729,8 +741,8 @@ float Body::getApparentMagnitude(float sunLuminosity,
/*! Get the apparent magnitude of the body, corrected for its phase.
*/
float Body::getApparentMagnitude(const Star& sun,
const Vec3d& sunPosition,
const Vec3d& viewerPosition) const
const Vector3d& sunPosition,
const Vector3d& viewerPosition) const
{
return getApparentMagnitude(sun.getLuminosity(),
sunPosition,
@ -741,13 +753,12 @@ float Body::getApparentMagnitude(const Star& sun,
/*! Get the apparent magnitude of the body, corrected for its phase.
*/
float Body::getApparentMagnitude(float sunLuminosity,
const Vec3d& sunPosition,
const Vec3d& viewerPosition) const
const Vector3d& sunPosition,
const Vector3d& viewerPosition) const
{
double distanceToViewer = viewerPosition.length();
double distanceToSun = sunPosition.length();
float illuminatedFraction = (float) (1.0 + (viewerPosition / distanceToViewer) *
(sunPosition / distanceToSun)) / 2.0f;
double distanceToViewer = viewerPosition.norm();
double distanceToSun = sunPosition.norm();
float illuminatedFraction = (float) (1.0 + (viewerPosition / distanceToViewer).dot(sunPosition / distanceToSun)) / 2.0f;
return astro::lumToAppMag(getLuminosity(sunLuminosity, (float) distanceToSun) * illuminatedFraction, (float) astro::kilometersToLightYears(distanceToViewer));
}

View File

@ -15,7 +15,6 @@
#include <map>
#include <list>
#include <celutil/utf8.h>
#include <celmath/quaternion.h>
#include <celengine/surface.h>
#include <celengine/atmosphere.h>
#include <celengine/orbit.h>
@ -23,6 +22,8 @@
#include <celengine/location.h>
#include <celengine/rotation.h>
#include <celengine/timeline.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
class ReferenceFrame;
class Body;
@ -200,8 +201,8 @@ class Body
const RotationModel* getRotationModel(double tdb) const;
// Size methods
void setSemiAxes(const Vec3f&);
Vec3f getSemiAxes() const;
void setSemiAxes(const Eigen::Vector3f&);
Eigen::Vector3f getSemiAxes() const;
float getRadius() const;
bool isSphere() const;
@ -211,8 +212,6 @@ class Body
void setMass(float);
float getAlbedo() const;
void setAlbedo(float);
Quatf getOrientation() const;
void setOrientation(const Quatf&);
int getClassification() const;
void setClassification(int);
std::string getInfoURL() const;
@ -232,6 +231,8 @@ class Body
ResourceHandle getGeometry() const { return geometry; }
void setGeometry(ResourceHandle);
Eigen::Quaternionf getGeometryOrientation() const;
void setGeometryOrientation(const Eigen::Quaternionf& orientation);
float getGeometryScale() const { return geometryScale; }
void setGeometryScale(float scale);
@ -251,30 +252,30 @@ class Body
float distanceFromSun,
float distanceFromViewer) const;
float getApparentMagnitude(const Star& sun,
const Vec3d& sunPosition,
const Vec3d& viewerPosition) const;
const Eigen::Vector3d& sunPosition,
const Eigen::Vector3d& viewerPosition) const;
float getApparentMagnitude(float sunLuminosity,
const Vec3d& sunPosition,
const Vec3d& viewerPosition) const;
const Eigen::Vector3d& sunPosition,
const Eigen::Vector3d& viewerPosition) const;
UniversalCoord getPosition(double tdb) const;
Quatd getOrientation(double tdb) const;
Vec3d getVelocity(double tdb) const;
Vec3d getAngularVelocity(double tdb) const;
Eigen::Quaterniond getOrientation(double tdb) const;
Eigen::Vector3d getVelocity(double tdb) const;
Eigen::Vector3d getAngularVelocity(double tdb) const;
Mat4d getLocalToAstrocentric(double) const;
Point3d getAstrocentricPosition(double) const;
Quatd getEquatorialToBodyFixed(double) const;
Quatd getEclipticToFrame(double) const;
Quatd getEclipticToEquatorial(double) const;
Quatd getEclipticToBodyFixed(double) const;
Mat4d getBodyFixedToAstrocentric(double) const;
Eigen::Matrix4d getLocalToAstrocentric(double) const;
Eigen::Vector3d getAstrocentricPosition(double) const;
Eigen::Quaterniond getEquatorialToBodyFixed(double) const;
Eigen::Quaterniond getEclipticToFrame(double) const;
Eigen::Quaterniond getEclipticToEquatorial(double) const;
Eigen::Quaterniond getEclipticToBodyFixed(double) const;
Eigen::Matrix4d getBodyFixedToAstrocentric(double) const;
Vec3d planetocentricToCartesian(double lon, double lat, double alt) const;
Vec3d planetocentricToCartesian(const Vec3d& lonLatAlt) const;
Vec3d cartesianToPlanetocentric(const Vec3d& v) const;
Eigen::Vector3d planetocentricToCartesian(double lon, double lat, double alt) const;
Eigen::Vector3d planetocentricToCartesian(const Eigen::Vector3d& lonLatAlt) const;
Eigen::Vector3d cartesianToPlanetocentric(const Eigen::Vector3d& v) const;
Vec3d eclipticToPlanetocentric(const Vec3d& ecl, double tdb) const;
Eigen::Vector3d eclipticToPlanetocentric(const Eigen::Vector3d& ecl, double tdb) const;
bool extant(double) const;
void setLifespan(double, double);
@ -351,10 +352,10 @@ class Body
FrameTree* frameTree;
float radius;
Vec3f semiAxes;
Eigen::Vector3f semiAxes;
float mass;
float albedo;
Quatf orientation;
Eigen::Quaternionf geometryOrientation;
float cullingRadius;

View File

@ -12,6 +12,11 @@
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
#include <Eigen/Geometry>
#ifndef _EIGENPORT_
#define _EIGENPORT_
template<typename T>
Eigen::Matrix<T, 3, 1> toEigen(const Vector3<T>& v)
{
@ -52,4 +57,5 @@ Point3<SCALAR> ptFromEigen(const Eigen::Matrix<SCALAR, 3, 1>& v)
return Point3<SCALAR>(v.x(), v.y(), v.z());
}
#endif // _EIGENPORT_

View File

@ -2,7 +2,8 @@
//
// Reference frame base class.
//
// Copyright (C) 2003-2008, Chris Laurel <claurel@shatters.net>
// Copyright (C) 2003-2009, the Celestia Development Team
// Original version by Chris Laurel <claurel@gmail.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@ -11,7 +12,9 @@
#include <cassert>
#include <celengine/frame.h>
#include "eigenport.h"
using namespace Eigen;
using namespace std;
@ -114,7 +117,7 @@ ReferenceFrame::convertFromAstrocentric(const Point3d& p, double tjd) const
{
if (centerObject.getType() == Selection::Type_Body)
{
Point3d center = centerObject.body()->getAstrocentricPosition(tjd);
Point3d center = ptFromEigen(centerObject.body()->getAstrocentricPosition(tjd));
return Point3d(0.0, 0.0, 0.0) + (p - center) * conjugate(getOrientation(tjd)).toMatrix3();
}
else if (centerObject.getType() == Selection::Type_Star)
@ -136,7 +139,7 @@ ReferenceFrame::convertToAstrocentric(const Point3d& p, double tjd) const
{
if (centerObject.getType() == Selection::Type_Body)
{
Point3d center = centerObject.body()->getAstrocentricPosition(tjd);
Point3d center = ptFromEigen(centerObject.body()->getAstrocentricPosition(tjd));
return center + p * getOrientation(tjd).toMatrix3();
}
else if (centerObject.getType() == Selection::Type_Star)
@ -290,16 +293,16 @@ BodyFixedFrame::getOrientation(double tjd) const
{
// Rotation of 180 degrees about the y axis is required
// TODO: this rotation could go in getEclipticalToBodyFixed()
Quatd yrot180 = Quatd(0.0, 0.0, 1.0, 0.0);
Quaterniond yrot180(0.0, 0.0, 1.0, 0.0);
switch (fixObject.getType())
{
case Selection::Type_Body:
return yrot180 * fixObject.body()->getEclipticToBodyFixed(tjd);
return fromEigen(yrot180 * fixObject.body()->getEclipticToBodyFixed(tjd));
case Selection::Type_Star:
return yrot180 * fixObject.star()->getRotationModel()->orientationAtTime(tjd);
return fromEigen(yrot180 * toEigen(fixObject.star()->getRotationModel()->orientationAtTime(tjd)));
default:
return yrot180;
return fromEigen(yrot180);
}
}
@ -310,7 +313,7 @@ BodyFixedFrame::getAngularVelocity(double tjd) const
switch (fixObject.getType())
{
case Selection::Type_Body:
return fixObject.body()->getAngularVelocity(tjd);
return fromEigen(fixObject.body()->getAngularVelocity(tjd));
case Selection::Type_Star:
return fixObject.star()->getRotationModel()->angularVelocityAtTime(tjd);
default:
@ -375,7 +378,7 @@ BodyMeanEquatorFrame::getOrientation(double tjd) const
switch (equatorObject.getType())
{
case Selection::Type_Body:
return equatorObject.body()->getEclipticToEquatorial(t);
return fromEigen(equatorObject.body()->getEclipticToEquatorial(t));
case Selection::Type_Star:
return equatorObject.star()->getRotationModel()->equatorOrientationAtTime(t);
default:
@ -757,36 +760,36 @@ FrameVector::createConstantVector(const Vec3d& _vec,
Vec3d
FrameVector::direction(double tjd) const
{
Vec3d v;
Vector3d v;
switch (vecType)
{
case RelativePosition:
v = target.getPosition(tjd) - observer.getPosition(tjd);
v = target.getPosition(tjd).offsetFromKm(observer.getPosition(tjd));
break;
case RelativeVelocity:
{
Vec3d v0 = observer.getVelocity(tjd);
Vec3d v1 = target.getVelocity(tjd);
Vector3d v0 = observer.getVelocity(tjd);
Vector3d v1 = target.getVelocity(tjd);
v = v1 - v0;
}
break;
case ConstantVector:
if (frame == NULL)
v = vec;
v = toEigen(vec);
else
v = vec * frame->getOrientation(tjd).toMatrix3();
v = toEigen(vec * frame->getOrientation(tjd).toMatrix3());
break;
default:
// unhandled vector type
v = Vec3d(0.0, 0.0, 0.0);
v = Vector3d::Zero();
break;
}
return v;
return fromEigen(v);
}

View File

@ -11,7 +11,9 @@
#include <celengine/location.h>
#include <celengine/body.h>
#include <celutil/util.h>
#include "eigenport.h"
using namespace Eigen;
using namespace std;
static map<string, uint32> FeatureNameToFlag;
@ -194,18 +196,27 @@ void Location::setParentBody(Body* _parent)
Point3d Location::getPlanetocentricPosition(double t) const
{
if (parent == NULL)
{
return Point3d(position.x, position.y, position.z);
Quatd q = parent->getEclipticToBodyFixed(t);
return Point3d(position.x, position.y, position.z) * q.toMatrix3();
}
else
{
Quatd q = fromEigen(parent->getEclipticToBodyFixed(t));
return Point3d(position.x, position.y, position.z) * q.toMatrix3();
}
}
Point3d Location::getHeliocentricPosition(double t) const
{
if (parent == NULL)
{
return Point3d(position.x, position.y, position.z);
}
else
{
Vector3d v = parent->getAstrocentricPosition(t) + toEigen(getPlanetocentricPosition(t));
return ptFromEigen(v);
}
return parent->getAstrocentricPosition(t) +
(getPlanetocentricPosition(t) - Point3d(0.0, 0.0, 0.0));
}

View File

@ -268,5 +268,8 @@ void MarkerRepresentation::render(float size) const
DrawCircle(s);
glEnd();
break;
default:
break;
}
}

View File

@ -16,6 +16,7 @@
#include "astro.h"
#include "orbit.h"
#include "body.h"
#include "eigenport.h"
using namespace std;
@ -617,7 +618,7 @@ SynchronousOrbit::~SynchronousOrbit()
Point3d SynchronousOrbit::positionAtTime(double jd) const
{
Quatd q = body.getEquatorialToBodyFixed(jd);
Quatd q = fromEigen(body.getEquatorialToBodyFixed(jd));
return position * q.toMatrix3();
}

View File

@ -23,7 +23,9 @@
#include "trajmanager.h"
#include "rotationmanager.h"
#include "universe.h"
#include "eigenport.h"
using namespace Eigen;
using namespace std;
@ -246,7 +248,7 @@ CreateFixedPosition(Hash* trajData, const Selection& centralObject, bool usePlan
// TODO: Need function to calculate planetographic coordinates
// TODO: Change planetocentricToCartesian so that 180 degree offset isn't required
position = centralObject.body()->planetocentricToCartesian(180.0 + v.x, v.y, v.z);
position = fromEigen(centralObject.body()->planetocentricToCartesian(180.0 + v.x, v.y, v.z));
}
else if (trajData->getVector("Planetocentric", v))
{
@ -257,7 +259,7 @@ CreateFixedPosition(Hash* trajData, const Selection& centralObject, bool usePlan
}
// TODO: Change planetocentricToCartesian so that 180 degree offset isn't required
position = centralObject.body()->planetocentricToCartesian(180.0 + v.x, v.y, v.z);
position = fromEigen(centralObject.body()->planetocentricToCartesian(180.0 + v.x, v.y, v.z));
}
else
{
@ -775,8 +777,8 @@ CreateOrbit(const Selection& centralObject,
Body* centralBody = centralObject.body();
if (centralBody != NULL)
{
Vec3d pos = centralBody->planetocentricToCartesian(longlat.x, longlat.y, longlat.z);
return new SynchronousOrbit(*centralBody, Point3d(pos.x, pos.y, pos.z));
Vector3d pos = centralBody->planetocentricToCartesian(longlat.x, longlat.y, longlat.z);
return new SynchronousOrbit(*centralBody, Point3d(pos.x(), pos.y(), pos.z()));
}
else
{

View File

@ -101,9 +101,7 @@ PlanetographicGrid::render(Renderer* renderer,
double tdb) const
{
// Compatibility
Quatd q_old = Quatd::yrotation(PI) * body.getEclipticToBodyFixed(tdb);
Quaterniond q(q_old.w, q_old.x, q_old.y, q_old.z);
Quaterniond q = Quaterniond(AngleAxis<double>(PI, Vector3d::UnitY())) * body.getEclipticToBodyFixed(tdb);
Quaternionf qf = q.cast<float>();
// The grid can't be rendered exactly on the planet sphere, or
@ -113,8 +111,7 @@ PlanetographicGrid::render(Renderer* renderer,
scale = max(scale, 1.001f);
float offset = scale - 1.0f;
Vec3f semiAxes_old = body.getSemiAxes();
Vector3f semiAxes(semiAxes_old.x, semiAxes_old.y, semiAxes_old.z);
Vector3f semiAxes = body.getSemiAxes();
Vector3d posd(pos.x, pos.y, pos.z);
Vector3d viewRayOrigin = q * Vector3d(-pos.x, -pos.y, -pos.z);
@ -286,7 +283,7 @@ PlanetographicGrid::setIAULongLatConvention()
}
else
{
if (body.getAngularVelocity(astro::J2000).y >= 0.0)
if (body.getAngularVelocity(astro::J2000).y() >= 0.0)
{
northDirection = NorthNormal;
longitudeConvention = Westward;

View File

@ -1,6 +1,6 @@
// render.cpp
//
// Copyright (C) 2001-2008, the Celestia Development Team
// Copyright (C) 2001-2009, the Celestia Development Team
// Original version by Chris Laurel <claurel@gmail.com>
//
// This program is free software; you can redistribute it and/or
@ -1971,90 +1971,6 @@ static Point3d renderOrbitSplineSegment(const Renderer::OrbitSample& p0,
}
#if 0
// Not yet used
static Point3d renderOrbitSplineAdaptive(const Renderer::OrbitSample& p0,
const Renderer::OrbitSample& p1,
const Renderer::OrbitSample& p2,
const Renderer::OrbitSample& p3,
double nearZ,
double farZ,
unsigned int minSubdivisions,
unsigned int maxSubdivisions,
int lastOutcode,
bool drawLastSegment)
{
Vec3d v0 = (p2.pos - p0.pos) * ((p2.t - p1.t) / (p2.t - p0.t));
Vec3d v1 = (p3.pos - p1.pos) * ((p2.t - p1.t) / (p3.t - p1.t));
double minDt = 1.0 / (double) maxSubdivisions;
double maxDt = 1.0 / (double) minSubdivisions;
double g = (p2.pos - p1.pos).length() * maxSubdivisions;
double t = 0.0;
splinesRendered += 10000;
Point3d lastP = p1.pos;
while (t < 1.0)
{
t += max(minDt, max(lastP.distanceFromOrigin() / g, maxDt));
if (drawLastSegment && t > 1.0)
t = 1.0;
else
break;
Point3d p = cubicInterpolate(p1.pos, v0, p2.pos, v1, t);
int outcode = (p.z > nearZ ? 1 : 0) | (p.z < farZ ? 2 : 0);
if ((outcode | lastOutcode) == 0)
{
glVertex3d(p.x, p.y, p.z);
}
else if ((outcode & lastOutcode) == 0)
{
// Need to clip
Point3d q0 = lastP;
Point3d q1 = p;
if (lastOutcode != 0)
{
glBegin(GL_LINE_STRIP);
double t;
if (lastOutcode == 1)
t = (nearZ - lastP.z) / (p.z - lastP.z);
else
t = (farZ - lastP.z) / (p.z - lastP.z);
q0 = lastP + t * (p - lastP);
}
if (outcode != 0)
{
double t;
if (outcode == 1)
t = (nearZ - lastP.z) / (p.z - lastP.z);
else
t = (farZ - lastP.z) / (p.z - lastP.z);
q1 = lastP + t * (p - lastP);
}
glVertex3d(q0.x, q0.y, q0.z);
glVertex3d(q1.x, q1.y, q1.z);
if (outcode != 0)
{
glEnd();
}
}
lastOutcode = outcode;
lastP = p;
}
return lastP;
}
#endif
static Point3d renderOrbitSection(const Orbit& orbit,
Renderer::CachedOrbit& cachedOrbit,
unsigned int sectionNumber,
@ -3525,7 +3441,7 @@ void Renderer::draw(const Observer& observer,
// to sphere calculation will not suffice.
const Atmosphere* atmosphere = iter->body->getAtmosphere();
float radius = iter->body->getRadius();
Vec3f semiAxes = iter->body->getSemiAxes() * (1.0f / radius);
Vec3f semiAxes = fromEigen(iter->body->getSemiAxes()) * (1.0f / radius);
Vec3f recipSemiAxes(1.0f / semiAxes.x,
1.0f / semiAxes.y,
1.0f / semiAxes.z);
@ -3534,7 +3450,7 @@ void Renderer::draw(const Observer& observer,
eyeVec *= (1.0f / radius);
// Compute the orientation of the planet before axial rotation
Quatd qd = iter->body->getEclipticToEquatorial(now);
Quatd qd = fromEigen(iter->body->getEclipticToEquatorial(now));
Quatf q((float) qd.w, (float) qd.x, (float) qd.y, (float) qd.z);
eyeVec = eyeVec * conjugate(q).toMatrix3();
@ -3937,8 +3853,9 @@ void Renderer::draw(const Observer& observer,
float eradius = radius;
if (iter->renderableType == RenderListEntry::RenderableBody)
{
Vec3f semiAxes = iter->body->getSemiAxes();
float minSemiAxis = min(semiAxes.x, min(semiAxes.y, semiAxes.z));
float minSemiAxis = iter->body->getSemiAxes().minCoeff();
//Vec3f semiAxes = iter->body->getSemiAxes();
//float minSemiAxis = min(semiAxes.x, min(semiAxes.y, semiAxes.z));
eradius *= minSemiAxis / radius;
}
@ -7116,7 +7033,7 @@ void Renderer::renderLocations(const Body& body,
if (locations == NULL)
return;
Vec3f semiAxes = body.getSemiAxes();
Vec3f semiAxes = fromEigen(body.getSemiAxes());
float nearDist = getNearPlaneDistance();
double boundingRadius = max(semiAxes.x, max(semiAxes.y, semiAxes.z));
@ -8091,8 +8008,8 @@ bool Renderer::testEclipse(const Body& receiver,
// less than the distance between the sun and the receiver. This
// approximation works everywhere in the solar system, and is likely
// valid for any orbitally stable pair of objects orbiting a star.
Point3d posReceiver = receiver.getAstrocentricPosition(now);
Point3d posCaster = caster.getAstrocentricPosition(now);
Point3d posReceiver = ptFromEigen(receiver.getAstrocentricPosition(now));
Point3d posCaster = ptFromEigen(caster.getAstrocentricPosition(now));
//const Star* sun = receiver.getSystem()->getStar();
//assert(sun != NULL);
@ -8199,13 +8116,13 @@ void Renderer::renderPlanet(Body& body,
rp.rings = body.getRings();
rp.radius = body.getRadius();
rp.geometry = body.getGeometry();
rp.semiAxes = body.getSemiAxes() * (1.0f / rp.radius);
rp.semiAxes = fromEigen(body.getSemiAxes()) * (1.0f / rp.radius);
rp.geometryScale = body.getGeometryScale();
Quatd q = body.getRotationModel(now)->spin(now) *
body.getEclipticToEquatorial(now);
fromEigen(body.getEclipticToEquatorial(now));
rp.orientation = body.getOrientation() *
rp.orientation = fromEigen(body.getGeometryOrientation()) *
Quatf((float) q.w, (float) q.x, (float) q.y, (float) q.z);
if (body.getLocations() != NULL && (labelMode & LocationLabels) != 0)
@ -8652,7 +8569,7 @@ void Renderer::renderCometTail(const Body& body,
// comet. The first axis is the velocity. We choose the second one
// based on the orientation of the comet. And the third is just the cross
// product of the first and second axes.
Quatd qd = body.getEclipticToEquatorial(t);
Quatd qd = fromEigen(body.getEclipticToEquatorial(t));
Quatf q((float) qd.w, (float) qd.x, (float) qd.y, (float) qd.z);
Vec3f v = cometPoints[1] - cometPoints[0];
v.normalize();
@ -9013,8 +8930,8 @@ void Renderer::buildRenderLists(const Point3d& astrocentricObserverPos,
float appMag = 100.0f;
for (unsigned int li = 0; li < lightSourceList.size(); li++)
{
Vec3d sunPos = pos_v - lightSourceList[li].position;
appMag = min(appMag, body->getApparentMagnitude(lightSourceList[li].luminosity, sunPos, pos_v));
Vector3d sunPos = toEigen(pos_v - lightSourceList[li].position);
appMag = min(appMag, body->getApparentMagnitude(lightSourceList[li].luminosity, sunPos, toEigen(pos_v)));
}
bool visibleAsPoint = appMag < faintestPlanetMag && body->isVisibleAsPoint();
@ -9153,7 +9070,7 @@ void Renderer::buildOrbitLists(const Point3d& astrocentricObserverPos,
// pos_v: viewer-relative position of object
// Get the position of the body relative to the sun.
Point3d pos_s = body->getAstrocentricPosition(now);
Point3d pos_s = ptFromEigen(body->getAstrocentricPosition(now));
// We now have the positions of the observer and the planet relative
// to the sun. From these, compute the position of the body
@ -9172,7 +9089,7 @@ void Renderer::buildOrbitLists(const Point3d& astrocentricObserverPos,
Selection centerObject = phase->orbitFrame()->getCenter();
if (centerObject.body() != NULL)
{
orbitOrigin = centerObject.body()->getAstrocentricPosition(now);
orbitOrigin = ptFromEigen(centerObject.body()->getAstrocentricPosition(now));
}
// Calculate the origin of the orbit relative to the observer
@ -9543,7 +9460,7 @@ void StarRenderer::process(const Star& star, float distance, float appMag)
Vector3f starPos = star.getPosition();
Vector3f relPos = (starPos.cast<double>() - obsPos).cast<float>();
#if 0
#if CELVEC
Vec3f relPos((float) ((double) starPos.x - obsPos.x),
(float) ((double) starPos.y - obsPos.y),
(float) ((double) starPos.z - obsPos.z));
@ -10448,9 +10365,9 @@ void Renderer::renderDeepSkyObjects(const Universe& universe,
}
static Vec3d toStandardCoords(const Vec3d& v)
static Vector3d toStandardCoords(const Vector3d& v)
{
return Vec3d(v.x, -v.z, v.y);
return Vector3d(v.x(), -v.z(), v.y());
}
@ -10499,27 +10416,26 @@ void Renderer::renderSkyGrids(const Observer& observer)
grid.setLongitudeUnits(SkyGrid::LongitudeDegrees);
grid.setLongitudeDirection(SkyGrid::IncreasingClockwise);
Vec3d zenithDirection = observer.getPosition() - body->getPosition(tdb);
zenithDirection.normalize();
Vector3d zenithDirection = observer.getPosition().offsetFromKm(body->getPosition(tdb)).normalized();
Vec3d northPole = Vec3d(0.0, 1.0, 0.0) * (body->getEclipticToEquatorial(tdb)).toMatrix3();
Vector3d northPole = body->getEclipticToEquatorial(tdb).conjugate() * Vector3d::UnitY();
zenithDirection = toStandardCoords(zenithDirection);
northPole = toStandardCoords(northPole);
Vec3d v = zenithDirection ^ northPole;
Vector3d v = zenithDirection.cross(northPole);
// Horizontal coordinate system not well defined when observer
// is at a pole.
double tolerance = 1.0e-10;
if (v.length() > tolerance && v.length() < 1.0 - tolerance)
if (v.norm() > tolerance && v.norm() < 1.0 - tolerance)
{
v.normalize();
Vec3d u = v ^ zenithDirection;
Vector3d u = v.cross(zenithDirection);
Matrix3d m;
m.row(0) = toEigen(u);
m.row(1) = toEigen(v);
m.row(2) = toEigen(zenithDirection);
m.row(0) = u;
m.row(1) = v;
m.row(2) = zenithDirection;
grid.setOrientation(Quaterniond(m));
grid.render(*this, observer, windowWidth, windowHeight);

View File

@ -12,7 +12,9 @@
#include "astro.h"
#include "selection.h"
#include "frametree.h"
#include "eigenport.h"
using namespace Eigen;
using namespace std;
@ -52,9 +54,14 @@ UniversalCoord Selection::getPosition(double t) const
case Type_DeepSky:
{
Point3d p = deepsky()->getPosition();
Vector3d p = toEigen(deepsky()->getPosition());
// NOTE: cast to single precision is only present to maintain compatibility with
// Celestia 1.6.0.
return UniversalCoord::CreateLy(p.cast<float>());
#if CELVEC
return astro::universalPosition(Point3d(0.0, 0.0, 0.0),
Point3f((float) p.x, (float) p.y, (float) p.z));
#endif
}
case Type_Location:
@ -62,46 +69,52 @@ UniversalCoord Selection::getPosition(double t) const
Body* body = location()->getParentBody();
if (body != NULL)
{
#if CELVEC
Point3d planetocentricPos = location()->getPlanetocentricPosition(t) *
astro::kilometersToMicroLightYears(1.0);
return body->getPosition(t) + planetocentricPos;
#endif
return body->getPosition(t).offsetKm(toEigen(location()->getPlanetocentricPosition(t)));
}
else
{
// Bad location; all locations should have a parent.
assert(0);
return UniversalCoord(0.0, 0.0, 0.0);
return UniversalCoord::Zero();
}
}
default:
return UniversalCoord(Point3d(0.0, 0.0, 0.0));
return UniversalCoord::Zero();
}
}
Vec3d Selection::getVelocity(double t) const
Vector3d Selection::getVelocity(double t) const
{
switch (type)
{
case Type_Body:
return body()->getVelocity(t);
return body()->getVelocity(t);
case Type_Star:
return star()->getVelocity(t);
case Type_DeepSky:
return Vec3d(0.0, 0.0, 0.0);
return Vector3d::Zero();
case Type_Location:
{
// For now, just use differentiation for location velocities.
#if CELVEC
Vec3d ulyPerJD = (getPosition(t) - getPosition(t - VELOCITY_DIFF_DELTA)) * (1.0 / VELOCITY_DIFF_DELTA);
return ulyPerJD * astro::microLightYearsToKilometers(1.0);
#endif
return getPosition(t).offsetFromKm(getPosition(t - VELOCITY_DIFF_DELTA)) / VELOCITY_DIFF_DELTA;
}
default:
return Vec3d(0.0, 0.0, 0.0);
return Vector3d::Zero();
}
}

View File

@ -16,6 +16,7 @@
#include <celengine/deepskyobj.h>
#include <celengine/location.h>
#include <celengine/univcoord.h>
#include <Eigen/Core>
class Selection
{
@ -40,7 +41,7 @@ class Selection
bool empty() const { return type == Type_Nil; }
double radius() const;
UniversalCoord getPosition(double t) const;
Vec3d getVelocity(double t) const;
Eigen::Vector3d getVelocity(double t) const;
std::string getName(bool i18n = false) const;
Selection parent() const;

View File

@ -166,10 +166,8 @@ static Location* CreateLocation(Hash* locationData,
Vec3d longlat(0.0, 0.0, 0.0);
locationData->getVector("LongLat", longlat);
Vec3d position = body->planetocentricToCartesian(longlat.x,
longlat.y,
longlat.z);
location->setPosition(Vec3f((float) position.x, (float) position.y, (float) position.z));
Vector3f position = body->planetocentricToCartesian(toEigen(longlat)).cast<float>();
location->setPosition(fromEigen(position));
double size = 1.0;
locationData->getNumber("Size", size);
@ -748,7 +746,7 @@ static Body* CreateBody(const string& name,
bool radiusSpecified = false;
if (planetData->getNumber("Radius", radius))
{
body->setSemiAxes(Vec3f((float) radius, (float) radius, (float) radius));
body->setSemiAxes(Vector3f::Constant((float) radius));
radiusSpecified = true;
}
@ -758,14 +756,14 @@ static Body* CreateBody(const string& name,
if (radiusSpecified)
semiAxes *= radius;
// Swap y and z to match internal coordinate system
body->setSemiAxes(Vec3f((float) semiAxes.x, (float) semiAxes.z, (float) semiAxes.y));
body->setSemiAxes(toEigen(semiAxes).cast<float>());
}
else
{
double oblateness = 0.0;
if (planetData->getNumber("Oblateness", oblateness))
{
body->setSemiAxes((float) body->getRadius() * Vec3f(1.0f, 1.0f - (float) oblateness, 1.0f));
body->setSemiAxes((float) body->getRadius() * Vector3f(1.0f, 1.0f - (float) oblateness, 1.0f));
}
}
@ -832,7 +830,7 @@ static Body* CreateBody(const string& name,
Quatf orientation;
if (planetData->getRotation("Orientation", orientation))
body->setOrientation(orientation);
body->setGeometryOrientation(toEigen(orientation));
Surface surface;
if (disposition == ModifyObject)
@ -1030,7 +1028,7 @@ static Body* CreateReferencePoint(const string& name,
disposition = AddObject;
}
body->setSemiAxes(Vec3f(1.0f, 1.0f, 1.0f));
body->setSemiAxes(Vector3f::Ones());
body->setClassification(Body::Invisible);
body->setVisible(false);
body->setVisibleAsPoint(false);

View File

@ -15,6 +15,7 @@
#include "orbit.h"
#include "star.h"
#include "texmanager.h"
#include "eigenport.h"
using namespace Eigen;
using namespace std;
@ -1069,7 +1070,7 @@ Star::getOrbitBarycenterPosition(double t) const
/*! Get the velocity of the star in the universal coordinate system.
*/
Vec3d
Vector3d
Star::getVelocity(double t) const
{
const Orbit* orbit = getOrbit();
@ -1077,7 +1078,7 @@ Star::getVelocity(double t) const
{
// The star doesn't have a defined orbit, so the velocity is just
// zero. (This will change when stellar proper motion is implemented.)
return Vec3d(0.0, 0.0, 0.0);
return Vector3d::Zero();
}
else
{
@ -1087,12 +1088,12 @@ Star::getVelocity(double t) const
{
// Star orbit is defined around a fixed point, so the total velocity
// is just the star's orbit velocity.
return orbit->velocityAtTime(t);
return toEigen(orbit->velocityAtTime(t));
}
else
{
// Sum the star's orbital velocity and the velocity of the barycenter.
return barycenter->getVelocity(t) + orbit->velocityAtTime(t);
return barycenter->getVelocity(t) + toEigen(orbit->velocityAtTime(t));
}
}
}

View File

@ -14,7 +14,6 @@
#include <celutil/basictypes.h>
#include <celutil/reshandle.h>
#include <celutil/color.h>
#include <celmath/vecmath.h>
#include <celengine/univcoord.h>
#include <celengine/celestia.h>
#include <celengine/stellarclass.h>
@ -260,7 +259,7 @@ public:
UniversalCoord getPosition(double t) const;
UniversalCoord getOrbitBarycenterPosition(double t) const;
Vec3d getVelocity(double t) const;
Eigen::Vector3d getVelocity(double t) const;
void setCatalogNumber(uint32);
void setPosition(float, float, float);

View File

@ -28,6 +28,11 @@ class UniversalCoord
UniversalCoord(const Point3d&);
UniversalCoord(const Point3f&);
explicit UniversalCoord(const Eigen::Vector3d& v) :
x(v.x()), y(v.y()), z(v.z())
{
}
operator Point3d() const;
operator Point3f() const;
@ -43,6 +48,20 @@ class UniversalCoord
friend UniversalCoord operator+(const UniversalCoord&, const UniversalCoord&);
/** Compute a universal coordinate that is the sum of this coordinate and
* an offset in kilometers.
*/
UniversalCoord offsetKm(const Eigen::Vector3d& v)
{
Eigen::Vector3d vUly = v * astro::kilometersToMicroLightYears(1.0);
#if 0
return UniversalCoord(x + (BigFix) vUly.x(),
y + (BigFix) vUly.y(),
z + (BigFix) vUly.z());
#endif
return *this + UniversalCoord(vUly);
}
/** Get the offset in kilometers of this coordinate from another coordinate.
* The result is double precision, calculated as (this - uc) * scale, where
* scale is a factor that converts from Celestia's internal units to kilometers.
@ -76,6 +95,31 @@ class UniversalCoord
double distanceTo(const UniversalCoord&);
UniversalCoord difference(const UniversalCoord&) const;
static UniversalCoord Zero()
{
// Default constructor returns zero, but this static method is clearer
return UniversalCoord();
}
/** Convert double precision coordinates in kilometers to high precision
* universal coordinates.
*/
static UniversalCoord CreateKm(const Eigen::Vector3d& v)
{
Eigen::Vector3d vUly = v * astro::microLightYearsToKilometers(1.0);
return UniversalCoord(vUly.x(), vUly.y(), vUly.z());
}
/** Convert single precision coordinates in light years to high precision
* universal coordinates.
*/
static UniversalCoord CreateLy(const Eigen::Vector3f& v)
{
Eigen::Vector3f vUly = v * 1.0e6f;
return UniversalCoord(vUly.x(), vUly.y(), vUly.z());
}
public:
BigFix x, y, z;
};

View File

@ -325,7 +325,7 @@ static bool ApproxPlanetPickTraversal(Body* body, void* info)
if (!body->isVisible() || !body->extant(pickInfo->jd) || !body->isClickable())
return true;
Vector3d bpos = toEigen(body->getAstrocentricPosition(pickInfo->jd));
Vector3d bpos = body->getAstrocentricPosition(pickInfo->jd);
Vector3d bodyDir = bpos - pickInfo->pickRay.origin;
double distance = bodyDir.norm();
@ -358,7 +358,7 @@ static bool ApproxPlanetPickTraversal(Body* body, void* info)
static bool ExactPlanetPickTraversal(Body* body, void* info)
{
PlanetPickInfo* pickInfo = reinterpret_cast<PlanetPickInfo*>(info);
Vector3d bpos = toEigen(body->getAstrocentricPosition(pickInfo->jd));
Vector3d bpos = body->getAstrocentricPosition(pickInfo->jd);
float radius = body->getRadius();
double distance = -1.0;
@ -375,10 +375,10 @@ static bool ExactPlanetPickTraversal(Body* body, void* info)
// we need to perform a ray-ellipsoid intersection test.
if (!body->isSphere())
{
Vector3d ellipsoidAxes = toEigen(body->getSemiAxes()).cast<double>();
Vector3d ellipsoidAxes = body->getSemiAxes().cast<double>();
// Transform rotate the pick ray into object coordinates
Matrix3d m = toEigen(body->getEclipticToEquatorial(pickInfo->jd)).toRotationMatrix();
Matrix3d m = body->getEclipticToEquatorial(pickInfo->jd).toRotationMatrix();
Ray3d r(pickInfo->pickRay.origin - bpos, pickInfo->pickRay.direction);
r = r.transform(m);
if (!testIntersection(r, Ellipsoidd(ellipsoidAxes), distance))
@ -388,8 +388,8 @@ static bool ExactPlanetPickTraversal(Body* body, void* info)
else
{
// Transform rotate the pick ray into object coordinates
Quaterniond qd = toEigen(body->getOrientation()).cast<double>();
Matrix3d m = (qd * toEigen(body->getEclipticToBodyFixed(pickInfo->jd))).toRotationMatrix();
Quaterniond qd = body->getGeometryOrientation().cast<double>();
Matrix3d m = (qd * body->getEclipticToBodyFixed(pickInfo->jd)).toRotationMatrix();
Ray3d r(pickInfo->pickRay.origin - bpos, pickInfo->pickRay.direction);
r = r.transform(m);

View File

@ -183,7 +183,7 @@ VisibleRegion::render(Renderer* /* renderer */,
unsigned int nSections = (unsigned int) (30.0f + discSizeInPixels * 0.5f);
nSections = min(nSections, 360u);
Quaterniond q = toEigen(m_body.getEclipticToBodyFixed(tdb));
Quaterniond q = m_body.getEclipticToBodyFixed(tdb);
Quaternionf qf = q.cast<float>();
// The outline can't be rendered exactly on the planet sphere, or
@ -192,7 +192,7 @@ VisibleRegion::render(Renderer* /* renderer */,
float scale = (discSizeInPixels + 1) / discSizeInPixels;
scale = max(scale, 1.0001f);
Vector3f semiAxes = toEigen(m_body.getSemiAxes());
Vector3f semiAxes = m_body.getSemiAxes();
// Enable depth buffering
glEnable(GL_DEPTH_TEST);

View File

@ -59,6 +59,7 @@
#define TIMERATE_PRINTF_FORMAT "%'.12g"
#endif
using namespace Eigen;
using namespace std;
static const int DragThreshold = 3;
@ -505,7 +506,7 @@ void showSelectionInfo(const Selection& sel)
if (sel.deepsky() != NULL)
sel.deepsky()->getOrientation().getAxisAngle(axis, angle);
else if (sel.body() != NULL)
sel.body()->getOrientation().getAxisAngle(axis, angle);
fromEigen(sel.body()->getGeometryOrientation()).getAxisAngle(axis, angle);
cout << sel.getName() << '\n';
cout << _("Orientation: ") << '[' << axis.x << ',' << axis.y << ',' << axis.z << "], " << radToDeg(angle) << '\n';
@ -908,7 +909,7 @@ void CelestiaCore::mouseMove(float dx, float dy, int modifiers)
if (sel.getType() == Selection::Type_DeepSky)
q = sel.deepsky()->getOrientation();
else if (sel.getType() == Selection::Type_Body)
q = sel.body()->getOrientation();
q = fromEigen(sel.body()->getGeometryOrientation());
q.yrotate(dx / width);
q.xrotate(dy / height);
@ -916,7 +917,7 @@ void CelestiaCore::mouseMove(float dx, float dy, int modifiers)
if (sel.getType() == Selection::Type_DeepSky)
sel.deepsky()->setOrientation(q);
else if (sel.getType() == Selection::Type_Body)
sel.body()->setOrientation(q);
sel.body()->setGeometryOrientation(toEigen(q));
}
else if (editMode && checkMask(modifiers, RightButton | ShiftKey | ControlKey))
{
@ -3067,7 +3068,7 @@ static void displayPlanetocentricCoords(Overlay& overlay,
else
{
// Swap hemispheres if the object is a retrograde rotator
Quatd q = ~body.getEclipticToEquatorial(astro::J2000);
Quatd q = fromEigen(body.getEclipticToEquatorial(astro::J2000).conjugate());
bool retrograde = (Vec3d(0.0, 1.0, 0.0) * q.toMatrix3()).y < 0.0;
if ((latitude < 0.0) ^ retrograde)
@ -3298,7 +3299,7 @@ static void displayPlanetInfo(Overlay& overlay,
const Star* sun = system->getStar();
if (sun != NULL)
{
double distFromSun = body.getAstrocentricPosition(t).distanceFromOrigin();
double distFromSun = body.getAstrocentricPosition(t).norm();
float planetTemp = sun->getTemperature() *
(float) (::pow(1.0 - body.getAlbedo(), 0.25) *
sqrt(sun->getRadius() / (2.0 * distFromSun)));
@ -3333,10 +3334,10 @@ static void displayLocationInfo(Overlay& overlay,
Body* body = location.getParentBody();
if (body != NULL)
{
Vec3f locPos = location.getPosition();
Vec3d lonLatAlt = body->cartesianToPlanetocentric(Vec3d(locPos.x, locPos.y, locPos.z));
Vector3f locPos = toEigen(location.getPosition());
Vector3d lonLatAlt = body->cartesianToPlanetocentric(locPos.cast<double>());
displayPlanetocentricCoords(overlay, *body,
lonLatAlt.x, lonLatAlt.y, lonLatAlt.z, false);
lonLatAlt.x(), lonLatAlt.y(), lonLatAlt.z(), false);
}
}

View File

@ -624,7 +624,7 @@ static int object_getinfo(lua_State* l)
celx.setTable("radius", (lua_Number)body->getRadius());
// TODO: add method to return semiaxes
Vec3f semiAxes = body->getSemiAxes();
Vec3f semiAxes = fromEigen(body->getSemiAxes());
// Note: oblateness is an obsolete field, replaced by semiaxes;
// it's only here for backward compatibility.
float polarRadius = semiAxes.y;

View File

@ -59,8 +59,8 @@ bool EclipseFinder::testEclipse(const Body& receiver, const Body& caster,
// less than the distance between the sun and the receiver. This
// approximation works everywhere in the solar system, and likely
// works for any orbitally stable pair of objects orbiting a star.
Point3d posReceiver = receiver.getAstrocentricPosition(now);
Point3d posCaster = caster.getAstrocentricPosition(now);
Point3d posReceiver = ptFromEigen(receiver.getAstrocentricPosition(now));
Point3d posCaster = ptFromEigen(caster.getAstrocentricPosition(now));
const Star* sun = receiver.getSystem()->getStar();
assert(sun != NULL);

View File

@ -151,6 +151,8 @@ void WriteFavoritesList(FavoritesList& favorites, ostream& out)
out << "phaselock"; break;
case ObserverFrame::Chase:
out << "chase"; break;
default:
out << "universal"; break;
}
out << "\"\n";
}

View File

@ -130,8 +130,8 @@ bool QtEclipseFinder::testEclipse(const Body& receiver, const Body& occulter,
// less than the distance between the sun and the receiver. This
// approximation works everywhere in the solar system, and likely
// works for any orbitally stable pair of objects orbiting a star.
Point3d posReceiver = receiver.getAstrocentricPosition(now);
Point3d posOcculter = occulter.getAstrocentricPosition(now);
Point3d posReceiver = ptFromEigen(receiver.getAstrocentricPosition(now));
Point3d posOcculter = ptFromEigen(occulter.getAstrocentricPosition(now));
const Star* sun = receiver.getSystem()->getStar();
assert(sun != NULL);
@ -809,7 +809,7 @@ void EventFinder::slotViewNearEclipsed()
Vec3d maxEclipsePoint = findMaxEclipsePoint(toCasterDir, toReceiver,
astro::kilometersToMicroLightYears(receiver.radius()));
Vec3d up = Vec3d(0.0, 1.0, 0.0) * (activeEclipse->receiver->getEclipticToBodyFixed(now)).toMatrix3();
Vec3d up = Vec3d(0.0, 1.0, 0.0) * (fromEigen(activeEclipse->receiver->getEclipticToBodyFixed(now))).toMatrix3();
Point3d viewerPos = Point3d(0.0, 0.0, 0.0) + maxEclipsePoint * 4.0; // 4 radii from center
Quatd viewOrientation = Quatd::lookAt(viewerPos,
Point3d(0.0, 0.0, 0.0) + maxEclipsePoint,
@ -870,7 +870,7 @@ void EventFinder::slotViewOccluderSurface()
Selection sun(activeEclipse->receiver->getSystem()->getStar());
Vec3d toCasterDir = caster.getPosition(now) - sun.getPosition(now);
Vec3d up = Vec3d(0.0, 1.0, 0.0) * activeEclipse->receiver->getEclipticToBodyFixed(now).toMatrix3();
Vec3d up = Vec3d(0.0, 1.0, 0.0) * fromEigen(activeEclipse->receiver->getEclipticToBodyFixed(now)).toMatrix3();
Vec3d toReceiverDir = receiver.getPosition(now) - caster.getPosition(now);
@ -902,7 +902,7 @@ void EventFinder::slotViewBehindOccluder()
Selection sun(activeEclipse->receiver->getSystem()->getStar());
Vec3d toCasterDir = caster.getPosition(now) - sun.getPosition(now);
Vec3d up = Vec3d(0.0, 1.0, 0.0) * activeEclipse->receiver->getEclipticToBodyFixed(now).toMatrix3();
Vec3d up = Vec3d(0.0, 1.0, 0.0) * fromEigen(activeEclipse->receiver->getEclipticToBodyFixed(now)).toMatrix3();
Vec3d toReceiverDir = receiver.getPosition(now) - caster.getPosition(now);