Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

observer.cpp File Reference

#include <celmath/mathlib.h>
#include <celmath/solve.h>
#include "observer.h"
#include "simulation.h"

Include dependency graph for observer.cpp:

Go to the source code of this file.

Defines

#define LY   9466411842000.000
#define VELOCITY_CHANGE_TIME   0.25f

Functions

static double getOrbitDistance (const Selection &selection, double currentDistance)
static double getPreferredDistance (const Selection &selection)
static Quatf lookAt (Point3f from, Point3f to, Vec3f up)
static Vec3d slerp (double t, const Vec3d &v0, const Vec3d &v1)
Vec3d toUniversal (const Vec3d &v, const Observer &observer, const Selection &sel, double t, astro::CoordinateSystem frame)


Define Documentation

#define LY   9466411842000.000
 

Definition at line 18 of file observer.cpp.

Referenced by Observer::getRelativePosition().

#define VELOCITY_CHANGE_TIME   0.25f
 

Definition at line 19 of file observer.cpp.

Referenced by Observer::update().


Function Documentation

static double getOrbitDistance const Selection selection,
double  currentDistance
[static]
 

Definition at line 985 of file observer.cpp.

References getPreferredDistance(), astro::kilometersToMicroLightYears(), and max.

Referenced by Observer::gotoSelection(), and Observer::gotoSelectionGC().

00987 {
00988     // If further than 10 times the preferrred distance, goto the
00989     // preferred distance.  If closer, zoom in 10 times closer or to the
00990     // minimum distance.
00991     double maxDist = astro::kilometersToMicroLightYears(getPreferredDistance(selection));
00992     double minDist = astro::kilometersToMicroLightYears(1.01 * selection.radius());
00993     double dist = (currentDistance > maxDist * 10.0) ? maxDist : currentDistance * 0.1;
00994 
00995     return max(dist, minDist);
00996 }

static double getPreferredDistance const Selection selection  )  [static]
 

Definition at line 958 of file observer.cpp.

References astro::AUtoKilometers(), max, and min.

Referenced by getOrbitDistance(), and Observer::gotoSelectionGC().

00959 {
00960     switch (selection.getType())
00961     {
00962     case Selection::Type_Body:
00963         return 5.0 * selection.radius();
00964     case Selection::Type_DeepSky:
00965         return 5.0 * selection.radius();
00966     case Selection::Type_Star:
00967         if (selection.star()->getVisibility())
00968             return 100.0 * selection.radius();
00969         else
00970             return astro::AUtoKilometers(1.0);
00971     case Selection::Type_Location:
00972         {
00973             double maxDist = getPreferredDistance(selection.location()->getParentBody());
00974             return max(min(selection.location()->getSize() * 50.0, maxDist),
00975                        1.0);
00976         }
00977     default:
00978         return 1.0;
00979     }
00980 }

static Quatf lookAt Point3f  from,
Point3f  to,
Vec3f  up
[static]
 

Definition at line 207 of file observer.cpp.

References Vector3< T >::normalize().

Referenced by Observer::computeCenterParameters(), Observer::computeGotoParameters(), Observer::computeGotoParametersGC(), Observer::gotoSurface(), and Observer::update().

00208 {
00209     Vec3f n = to - from;
00210     n.normalize();
00211     Vec3f v = n ^ up;
00212     v.normalize();
00213     Vec3f u = v ^ n;
00214     return Quatf(Mat3f(v, u, -n));
00215 }

static Vec3d slerp double  t,
const Vec3d v0,
const Vec3d v1
[static]
 

Definition at line 22 of file observer.cpp.

References cos(), Vector3< T >::length(), Math< T >::lerp(), Vector3< T >::normalize(), and sin().

Referenced by Observer::update().

00023 {
00024     double r0 = v0.length();
00025     double r1 = v1.length();
00026     Vec3d u = v0 / r0;
00027     Vec3d n = u ^ (v1 / r1);
00028     n.normalize();
00029     Vec3d v = n ^ u;
00030     if (v * v1 < 0.0)
00031         v = -v;
00032 
00033     double cosTheta = u * (v1 / r1);
00034     double theta = acos(cosTheta);
00035 
00036     return (cos(theta * t) * u + sin(theta * t) * v) * Mathd::lerp(t, r0, r1);
00037 }

Vec3d toUniversal const Vec3d v,
const Observer observer,
const Selection sel,
double  t,
astro::CoordinateSystem  frame
 

Definition at line 164 of file observer.cpp.

References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.

Referenced by Observer::computeGotoParameters(), and Observer::computeGotoParametersGC().

00169 {
00170     switch (frame)
00171     {
00172     case astro::ObserverLocal:
00173         {
00174             Quatf q = observer.getOrientation();
00175             Quatd qd(q.w, q.x, q.y, q.z);
00176             return v * qd.toMatrix3();
00177         }                        
00178 
00179         
00180     case astro::Geographic:
00181         if (sel.getType() != Selection::Type_Body)
00182             return v;
00183         else
00184             return v * sel.body()->getGeographicToHeliocentric(t);
00185         
00186     case astro::Equatorial:
00187         if (sel.getType() != Selection::Type_Body)
00188             return v;
00189         else
00190             return v * sel.body()->getLocalToHeliocentric(t);
00191 
00192     case astro::Ecliptical:
00193         // TODO: Multiply this by the planetary system's ecliptic orientation,
00194         // once this field is added.
00195         return v;
00196 
00197     case astro::Universal:
00198         return v;
00199 
00200     default:
00201         // assert(0);
00202         return v;
00203     }
00204 }


Generated on Sat Jan 14 22:31:01 2006 for Celestia by  doxygen 1.4.1