StelProjectorClasses.cpp   StelProjectorClasses.cpp 
skipping to change at line 23 skipping to change at line 23
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelProjectorClasses.hpp" #include "StelProjectorClasses.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include <limits>
QString StelProjectorPerspective::getNameI18() const QString StelProjectorPerspective::getNameI18() const
{ {
return q_("Perspective"); return q_("Perspective");
} }
QString StelProjectorPerspective::getDescriptionI18() const QString StelProjectorPerspective::getDescriptionI18() const
{ {
return q_("Perspective projection keeps the horizon a straight line. The mathematical name for this projection method is <i>gnomonic projection </i>."); return q_("Perspective projection keeps the horizon a straight line. The mathematical name for this projection method is <i>gnomonic projection </i>.");
} }
bool StelProjectorPerspective::forward(Vec3f &v) const
{
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
if (v[2] < 0) {
v[0] /= (-v[2]);
v[1] /= (-v[2]);
v[2] = r;
return true;
}
if (v[2] > 0) {
v[0] /= v[2];
v[1] /= v[2];
v[2] = -std::numeric_limits<float>::max();
return false;
}
v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max();
v[2] = -std::numeric_limits<float>::max();
return false;
}
bool StelProjectorPerspective::backward(Vec3d &v) const bool StelProjectorPerspective::backward(Vec3d &v) const
{ {
v[2] = std::sqrt(1.0/(1.0+v[0]*v[0]+v[1]*v[1])); v[2] = std::sqrt(1.0/(1.0+v[0]*v[0]+v[1]*v[1]));
v[0] *= v[2]; v[0] *= v[2];
v[1] *= v[2]; v[1] *= v[2];
v[2] = -v[2]; v[2] = -v[2];
return true; return true;
} }
float StelProjectorPerspective::fovToViewScalingFactor(float fov) const float StelProjectorPerspective::fovToViewScalingFactor(float fov) const
skipping to change at line 70 skipping to change at line 93
QString StelProjectorEqualArea::getNameI18() const QString StelProjectorEqualArea::getNameI18() const
{ {
return q_("Equal Area"); return q_("Equal Area");
} }
QString StelProjectorEqualArea::getDescriptionI18() const QString StelProjectorEqualArea::getDescriptionI18() const
{ {
return q_("The full name of this projection method is, <i>Lambert az imuthal equal-area projection</i>. It preserves the area but not the angle. "); return q_("The full name of this projection method is, <i>Lambert az imuthal equal-area projection</i>. It preserves the area but not the angle. ");
} }
bool StelProjectorEqualArea::forward(Vec3f &v) const
{
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float f = std::sqrt(2.f/(r*(r-v[2])));
v[0] *= f;
v[1] *= f;
v[2] = r;
return true;
}
bool StelProjectorEqualArea::backward(Vec3d &v) const bool StelProjectorEqualArea::backward(Vec3d &v) const
{ {
// FIXME: for high FoV, return false but don't cause crash with Mous e Pointer Coordinates.
const double dq = v[0]*v[0] + v[1]*v[1]; const double dq = v[0]*v[0] + v[1]*v[1];
double l = 1.0 - 0.25*dq; double l = 1.0 - 0.25*dq;
if (l < 0) if (l < 0)
{ {
v[0] = 0.0; v[0] = 0.0;
v[1] = 0.0; v[1] = 0.0;
v[2] = 1.0; v[2] = 1.0;
//return false; // GZ tentative fix for projecting invalid o utlying screen point. CAUSES CRASH SOMETIMES!?
} }
else else
{ {
l = std::sqrt(l); l = std::sqrt(l);
v[0] *= l; v[0] *= l;
v[1] *= l; v[1] *= l;
v[2] = 0.5*dq - 1.0; v[2] = 0.5*dq - 1.0;
} }
return true; return true;
} }
skipping to change at line 115 skipping to change at line 150
QString StelProjectorStereographic::getNameI18() const QString StelProjectorStereographic::getNameI18() const
{ {
return q_("Stereographic"); return q_("Stereographic");
} }
QString StelProjectorStereographic::getDescriptionI18() const QString StelProjectorStereographic::getDescriptionI18() const
{ {
return q_("Stereographic projection is known since the antiquity and was originally known as the planisphere projection. It preserves the angle s at which curves cross each other but it does not preserve area."); return q_("Stereographic projection is known since the antiquity and was originally known as the planisphere projection. It preserves the angle s at which curves cross each other but it does not preserve area.");
} }
bool StelProjectorStereographic::forward(Vec3f &v) const
{
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float h = 0.5f*(r-v[2]);
if (h <= 0.f) {
v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max();
v[2] = -std::numeric_limits<float>::min();
return false;
}
const float f = 1.f / h;
v[0] *= f;
v[1] *= f;
v[2] = r;
return true;
}
bool StelProjectorStereographic::backward(Vec3d &v) const bool StelProjectorStereographic::backward(Vec3d &v) const
{ {
const double lqq = 0.25*(v[0]*v[0] + v[1]*v[1]); const double lqq = 0.25*(v[0]*v[0] + v[1]*v[1]);
v[2] = lqq - 1.0; v[2] = lqq - 1.0;
v *= (1.0 / (lqq + 1.0)); v *= (1.0 / (lqq + 1.0));
return true; return true;
} }
float StelProjectorStereographic::fovToViewScalingFactor(float fov) const float StelProjectorStereographic::fovToViewScalingFactor(float fov) const
{ {
skipping to change at line 149 skipping to change at line 201
QString StelProjectorFisheye::getNameI18() const QString StelProjectorFisheye::getNameI18() const
{ {
return q_("Fish-eye"); return q_("Fish-eye");
} }
QString StelProjectorFisheye::getDescriptionI18() const QString StelProjectorFisheye::getDescriptionI18() const
{ {
return q_("In fish-eye projection, or <i>azimuthal equidistant proje ction</i>, straight lines become curves when they appear a large angular di stance from the centre of the field of view (like the distortions seen with very wide angle camera lenses)."); return q_("In fish-eye projection, or <i>azimuthal equidistant proje ction</i>, straight lines become curves when they appear a large angular di stance from the centre of the field of view (like the distortions seen with very wide angle camera lenses).");
} }
bool StelProjectorFisheye::forward(Vec3f &v) const
{
const float rq1 = v[0]*v[0] + v[1]*v[1];
if (rq1 > 0.f) {
const float h = std::sqrt(rq1);
const float f = std::atan2(h,-v[2]) / h;
v[0] *= f;
v[1] *= f;
v[2] = std::sqrt(rq1 + v[2]*v[2]);
return true;
}
if (v[2] < 0.f) {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 1.f;
return true;
}
v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max();
v[2] = std::numeric_limits<float>::min();
return false;
}
bool StelProjectorFisheye::backward(Vec3d &v) const bool StelProjectorFisheye::backward(Vec3d &v) const
{ {
const double a = std::sqrt(v[0]*v[0]+v[1]*v[1]); const double a = std::sqrt(v[0]*v[0]+v[1]*v[1]);
const double f = (a > 0.0) ? (std::sin(a) / a) : 1.0; const double f = (a > 0.0) ? (std::sin(a) / a) : 1.0;
v[0] *= f; v[0] *= f;
v[1] *= f; v[1] *= f;
v[2] = -std::cos(a); v[2] = -std::cos(a);
return (a < M_PI); return (a < M_PI);
} }
skipping to change at line 184 skipping to change at line 259
QString StelProjectorHammer::getNameI18() const QString StelProjectorHammer::getNameI18() const
{ {
return q_("Hammer-Aitoff"); return q_("Hammer-Aitoff");
} }
QString StelProjectorHammer::getDescriptionI18() const QString StelProjectorHammer::getDescriptionI18() const
{ {
return q_("The Hammer projection is an equal-area map projection, de scribed by Ernst Hammer in 1892 and directly inspired by the Aitoff project ion."); return q_("The Hammer projection is an equal-area map projection, de scribed by Ernst Hammer in 1892 and directly inspired by the Aitoff project ion.");
} }
bool StelProjectorHammer::forward(Vec3f &v) const
{
// Hammer Aitoff
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const float alpha = std::atan2(v[0],-v[2]);
const float cosDelta = std::sqrt(1.f-v[1]*v[1]/(r*r));
float z = std::sqrt(1.+cosDelta*std::cos(alpha/2.f));
v[0] = 2.f*M_SQRT2*cosDelta*std::sin(alpha/2.f)/z;
v[1] = M_SQRT2*v[1]/r/z;
v[2] = r;
return true;
}
bool StelProjectorHammer::backward(Vec3d &v) const bool StelProjectorHammer::backward(Vec3d &v) const
{ {
const double zsq = 1.-0.25*0.25*v[0]*v[0]-0.5*0.5*v[1]*v[1]; const double zsq = 1.-0.25*0.25*v[0]*v[0]-0.5*0.5*v[1]*v[1];
const double z = zsq<0. ? 0. : std::sqrt(zsq); const double z = zsq<0. ? 0. : std::sqrt(zsq);
const bool ret = 0.25*v[0]*v[0]+v[1]*v[1]<2.0; // This is stolen fro m glunatic const bool ret = 0.25*v[0]*v[0]+v[1]*v[1]<2.0; // This is stolen fro m glunatic
const double alpha = 2.*std::atan2(z*v[0],(2.*(2.*zsq-1.))); const double alpha = 2.*std::atan2(z*v[0],(2.*(2.*zsq-1.)));
const double delta = std::asin(v[1]*z); const double delta = std::asin(v[1]*z);
const double cd = std::cos(delta); const double cd = std::cos(delta);
v[2] = - cd * std::cos(alpha); v[2] = - cd * std::cos(alpha);
v[0] = cd * std::sin(alpha); v[0] = cd * std::sin(alpha);
skipping to change at line 267 skipping to change at line 355
return fov; return fov;
} }
QString StelProjectorMercator::getNameI18() const QString StelProjectorMercator::getNameI18() const
{ {
return q_("Mercator"); return q_("Mercator");
} }
QString StelProjectorMercator::getDescriptionI18() const QString StelProjectorMercator::getDescriptionI18() const
{ {
return q_("The mercator projection is one of the most used world map projection. It preserves direction and shapes but distorts size, in an inc reasing degree away from the equator."); return q_("The Mercator projection is one of the most used world map projections. It preserves direction and shapes but distorts size, in an in creasing degree away from the equator.");
} }
bool StelProjectorMercator::forward(Vec3f &v) const bool StelProjectorMercator::forward(Vec3f &v) const
{ {
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const bool rval = (-r < v[1] && v[1] < r); const bool rval = (-r < v[1] && v[1] < r);
const float sin_delta = v[1]/r; const float sin_delta = v[1]/r;
v[0] = std::atan2(v[0],-v[2]); v[0] = std::atan2(v[0],-v[2]);
v[1] = 0.5f*std::log((1.f+sin_delta)/(1.f-sin_delta)); v[1] = 0.5f*std::log((1.f+sin_delta)/(1.f-sin_delta));
v[2] = r; v[2] = r;
skipping to change at line 361 skipping to change at line 449
float StelProjectorOrthographic::viewScalingFactorToFov(float vsf) const float StelProjectorOrthographic::viewScalingFactorToFov(float vsf) const
{ {
return std::asin(vsf); return std::asin(vsf);
} }
float StelProjectorOrthographic::deltaZoom(float fov) const float StelProjectorOrthographic::deltaZoom(float fov) const
{ {
return fov; return fov;
} }
QString StelProjectorSinusoidal::getNameI18() const
{
return q_("Sinusoidal");
}
QString StelProjectorSinusoidal::getDescriptionI18() const
{
return q_("The sinusoidal projection is a <i>pseudocylindrical equal
-area map projection</i>, sometimes called the Sanson–Flamsteed or the Merc
ator equal-area projection.");
}
bool StelProjectorSinusoidal::forward(Vec3f &v) const
{
const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
const bool rval = (-r < v[1] && v[1] < r);
const float alpha = std::atan2(v[0],-v[2]);
const float delta = std::asin(v[1]/r);
v[0] = alpha*std::cos(delta);
v[1] = delta;
v[2] = r;
return rval;
}
bool StelProjectorSinusoidal::backward(Vec3d &v) const
{
const bool rval = v[1]<M_PI_2 && v[1]>-M_PI_2 && v[0]>-M_PI && v[0]<
M_PI;
const double cd = std::cos(v[1]);
const double pcd = v[0]/cd;
if (v[0]<-M_PI*cd || v[0]>M_PI*cd)
{
v[0] = -cd;
v[1] = 1.0;
// FIXME: It is unclear what happens to v[2] here.
v.normalize(); // make sure the length test in Atmosphere.cp
p work.
return false;
}
v[2] = -cd * std::cos(pcd);
v[0] = cd * std::sin(pcd);
v[1] = std::sin(v[1]);
return rval;
}
QString StelProjector2d::getNameI18() const QString StelProjector2d::getNameI18() const
{ {
return "2d"; return "2d";
} }
QString StelProjector2d::getDescriptionI18() const QString StelProjector2d::getDescriptionI18() const
{ {
return "Simple 2d projection for internal use."; return "Simple 2d projection for internal use.";
} }
 End of changes. 10 change blocks. 
1 lines changed or deleted 134 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/