7
#include "ProjectionOrthographic.h"
9
ProjectionOrthographic::ProjectionOrthographic(const int f, const int w, const int h)
10
: ProjectionBase(f, w, h)
12
isWrapAround_ = false;
14
Options *options = Options::getInstance();
16
radius_ = options->Radius() * height_;
17
setRange(options->getRange());
22
ProjectionOrthographic::~ProjectionOrthographic()
28
ProjectionOrthographic::setRange(const double range)
37
radius_ *= sqrt(Pp1/Pm1);
41
ProjectionOrthographic::pixelToSpherical(const double x, const double y,
42
double &lon, double &lat)
44
const double X = (x - centerX_)/radius_;
45
const double Y = (centerY_ - y)/radius_;
47
const double rho2 = X*X + Y*Y;
48
if (rho2 > 1) return(false);
50
const double rho = sqrt(rho2);
59
double arg = Pm1*(Pm1 - rho2 * Pp1);
60
if (arg < 0) return(false);
62
const double N = rho * (PPm1 - sqrt(arg));
63
const double D = (Pm1sq + rho2);
65
const double sinc = N/D;
66
const double cosc = sqrt(1 - sinc*sinc);
69
if (fabs(arg) > 1) return(false);
72
lon = atan2(X * sinc, rho * cosc);
75
// This is the cosine of the observer-planet center-normal angle
76
const double cosa = cos(lat) * cos(lon);
77
const double sina_sq = 1 - cosa*cosa;
79
// This is the distance from the observer to the point on the surface
80
const double dist_sq = Psq - 2 * P * cosa + 1;
82
// This is the angle we want: observer-surface-normal
83
const double sinb_sq = Psq / dist_sq * sina_sq;
84
const double cosb = sqrt(1 - sinb_sq);
86
darkening_ = getPhotoFunction(fabs(cosb));
88
if (rotate_) RotateXYZ(lat, lon);
90
if (lon > M_PI) lon -= 2*M_PI;
91
else if (lon < -M_PI) lon += 2*M_PI;
97
ProjectionOrthographic::sphericalToPixel(double lon, double lat,
98
double &x, double &y) const
100
if (rotate_) RotateZYX(lat, lon);
102
const double cosc = cos(lat) * cos(lon);
103
if (cosc < 0) return(false);
105
const double k = (P - 1) / (P - cosc);
107
const double X = k * cos(lat) * sin(lon);
108
const double Y = k * sin(lat);
110
x = X * radius_ + centerX_;
111
if (x < 0 || x >= width_) return(false);
113
y = centerY_ - Y * radius_;
114
if (y < 0 || y >= height_) return(false);
118
double dist = sqrt(x*x + y*y);
119
if (dist < radius_) return(false);