StelProjectorClasses.hpp   StelProjectorClasses.hpp 
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#ifndef _STELPROJECTIONS_HPP_ #ifndef _STELPROJECTIONS_HPP_
#define _STELPROJECTIONS_HPP_ #define _STELPROJECTIONS_HPP_
#include <limits>
#include "StelProjector.hpp" #include "StelProjector.hpp"
class StelProjectorPerspective : public StelProjector class StelProjectorPerspective : public StelProjector
{ {
public: public:
StelProjectorPerspective(const Mat4d& modelViewMat) : StelProjector( modelViewMat) {;} StelProjectorPerspective(const Mat4d& modelViewMat) : StelProjector( modelViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 120.;} virtual float getMaxFov() const {return 120.f;}
bool forward(Vec3d &v) const bool forward(Vec3f &v) const
{ {
const double 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]) ;
if (v[2] < 0) { if (v[2] < 0) {
v[0] /= (-v[2]); v[0] /= (-v[2]);
v[1] /= (-v[2]); v[1] /= (-v[2]);
v[2] = r; v[2] = r;
return true; return true;
} }
if (v[2] > 0) { if (v[2] > 0) {
v[0] /= v[2]; v[0] /= v[2];
v[1] /= v[2]; v[1] /= v[2];
v[2] = r; v[2] = r;
return false; return false;
} }
v[0] *= 1e99; v[0] = std::numeric_limits<float>::max();
v[1] *= 1e99; v[1] = std::numeric_limits<float>::max();
v[2] = r; v[2] = r;
return false; return false;
} }
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return false;} virtual bool hasDiscontinuity() const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co
const Vec3d& p2) const {return false;} nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do
uble) const {return false;}
}; };
class StelProjectorEqualArea : public StelProjector class StelProjectorEqualArea : public StelProjector
{ {
public: public:
StelProjectorEqualArea(const Mat4d& modelViewMat) : StelProjector(mo delViewMat) {;} StelProjectorEqualArea(const Mat4d& modelViewMat) : StelProjector(mo delViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 360.;} virtual float getMaxFov() const {return 360.f;}
bool forward(Vec3d &v) const bool forward(Vec3f &v) const
{ {
const double 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 double f = std::sqrt(2.0/(r*(r-v[2]))); const float f = std::sqrt(2.f/(r*(r-v[2])));
v[0] *= f; v[0] *= f;
v[1] *= f; v[1] *= f;
v[2] = r; v[2] = r;
return true; return true;
} }
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return false;} virtual bool hasDiscontinuity() const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co
const Vec3d& p2) const {return false;} nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do
uble) const {return false;}
}; };
class StelProjectorStereographic : public StelProjector class StelProjectorStereographic : public StelProjector
{ {
public: public:
StelProjectorStereographic(const Mat4d& modelViewMat) : StelProjecto r(modelViewMat) {;} StelProjectorStereographic(const Mat4d& modelViewMat) : StelProjecto r(modelViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 235.;} virtual float getMaxFov() const {return 235.f;}
bool forward(Vec3d &v) const bool forward(Vec3f &v) const
{ {
const double 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 double h = 0.5*(r-v[2]); const float h = 0.5f*(r-v[2]);
if (h <= 0.0) { if (h <= 0.f) {
v[0] = 1e99; v[0] = std::numeric_limits<float>::max();
v[1] = 1e99; v[1] = std::numeric_limits<float>::max();
v[2] = -1e99; v[2] = -std::numeric_limits<float>::min();
return false; return false;
} }
const double f = 1.0 / h; const float f = 1.f / h;
v[0] *= f; v[0] *= f;
v[1] *= f; v[1] *= f;
v[2] = r; v[2] = r;
return true; return true;
} }
virtual void project(int n, const Vec3d* in, Vec3f* out) virtual void project(int n, const Vec3d* in, Vec3f* out)
{ {
Vec3d v; Vec3d v;
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i, ++out)
{ {
v = in[i]; v = in[i];
v.transfo4d(modelViewMatrix); v.transfo4d(modelViewMatrix);
StelProjectorStereographic::forward(v); out->set(v[0], v[1], v[2]);
out[i][0] = viewportCenter[0] + flipHorz * pixelPerR StelProjectorStereographic::forward(*out);
ad * v[0]; out->set(viewportCenter[0] + flipHorz * pixelPerRad
out[i][1] = viewportCenter[1] + flipVert * pixelPerR * (*out)[0],
ad * v[1]; viewportCenter[1] + flipVert * pixelPerRad *
out[i][2] = (v[2] - zNear) * oneOverZNearMinusZFar; (*out)[1],
((*out)[2] - zNear) * oneOverZNearMinusZFar)
;
} }
} }
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return false;} virtual bool hasDiscontinuity() const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co
const Vec3d& p2) const {return false;} nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do
uble) const {return false;}
}; };
class StelProjectorFisheye : public StelProjector class StelProjectorFisheye : public StelProjector
{ {
public: public:
StelProjectorFisheye(const Mat4d& modelViewMat) : StelProjector(mode lViewMat) {;} StelProjectorFisheye(const Mat4d& modelViewMat) : StelProjector(mode lViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 180.00001;} virtual float getMaxFov() const {return 180.00001f;}
bool forward(Vec3d &v) const bool forward(Vec3f &v) const
{ {
const double rq1 = v[0]*v[0] + v[1]*v[1]; const float rq1 = v[0]*v[0] + v[1]*v[1];
if (rq1 > 0.0) { if (rq1 > 0.f) {
const double h = std::sqrt(rq1); const float h = std::sqrt(rq1);
const double f = std::atan2(h,-v[2]) / h; const float f = std::atan2(h,-v[2]) / h;
v[0] *= f; v[0] *= f;
v[1] *= f; v[1] *= f;
v[2] = std::sqrt(rq1 + v[2]*v[2]); v[2] = std::sqrt(rq1 + v[2]*v[2]);
return true; return true;
} }
if (v[2] < 0.0) { if (v[2] < 0.f) {
v[0] = 0.0; v[0] = 0.f;
v[1] = 0.0; v[1] = 0.f;
v[2] = 1.0; v[2] = 1.f;
return true; return true;
} }
v[0] = 1e99; v[0] = std::numeric_limits<float>::max();
v[1] = 1e99; v[1] = std::numeric_limits<float>::max();
v[2] = -1e99; v[2] = std::numeric_limits<float>::min();
return false; return false;
} }
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return false;} virtual bool hasDiscontinuity() const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co
const Vec3d& p2) const {return false;} nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do
uble) const {return false;}
}; };
class StelProjectorHammer : public StelProjector class StelProjectorHammer : public StelProjector
{ {
public: public:
StelProjectorHammer(const Mat4d& modelViewMat) : StelProjector(model ViewMat) {;} StelProjectorHammer(const Mat4d& modelViewMat) : StelProjector(model ViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 360.;} virtual float getMaxFov() const {return 360.f;}
virtual void project(int n, const Vec3d* in, Vec3f* out) virtual void project(int n, const Vec3d* in, Vec3f* out)
{ {
Vec3d v; Vec3d v;
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i)
{ {
v = in[i]; v = in[i];
v.transfo4d(modelViewMatrix); v.transfo4d(modelViewMatrix);
StelProjectorHammer::forward(v); out[i].set(v[0], v[1], v[2]);
out[i][0] = viewportCenter[0] + flipHorz * pixelPerR StelProjectorHammer::forward(out[i]);
ad * v[0]; out[i][0] = viewportCenter[0] + flipHorz * pixelPerR
out[i][1] = viewportCenter[1] + flipVert * pixelPerR ad * out[i][0];
ad * v[1]; out[i][1] = viewportCenter[1] + flipVert * pixelPerR
out[i][2] = (v[2] - zNear) * oneOverZNearMinusZFar; ad * out[i][1];
out[i][2] = (out[i][2] - zNear) * oneOverZNearMinusZ
Far;
} }
} }
bool forward(Vec3d &v) const bool forward(Vec3f &v) const
{ {
// Hammer Aitoff // Hammer Aitoff
const double 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 double alpha = std::atan2(v[0],-v[2]); const float alpha = std::atan2(v[0],-v[2]);
const double cosDelta = std::sqrt(1.-v[1]*v[1]/(r*r)); const float cosDelta = std::sqrt(1.f-v[1]*v[1]/(r*r));
double z = std::sqrt(1.+cosDelta*std::cos(alpha/2.)); float z = std::sqrt(1.+cosDelta*std::cos(alpha/2.f));
v[0] = 2.*M_SQRT2*cosDelta*std::sin(alpha/2.)/z; v[0] = 2.f*M_SQRT2*cosDelta*std::sin(alpha/2.f)/z;
v[1] = M_SQRT2*v[1]/r/z; v[1] = M_SQRT2*v[1]/r/z;
v[2] = r; v[2] = r;
return true; return true;
} }
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return true;} virtual bool hasDiscontinuity() const {return true;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);} virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap
N, double capD) const
{
static const SphericalCap cap1(1,0,0);
static const SphericalCap cap2(-1,0,0);
static const SphericalCap cap3(0,0,-1);
SphericalCap cap(capN, capD);
return cap.intersects(cap1) && cap.intersects(cap2) && cap.i
ntersects(cap2);
}
}; };
class StelProjectorCylinder : public StelProjector class StelProjectorCylinder : public StelProjector
{ {
public: public:
StelProjectorCylinder(const Mat4d& modelViewMat) : StelProjector(mod elViewMat) {;} StelProjectorCylinder(const Mat4d& modelViewMat) : StelProjector(mod elViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 175. * 4./3.;} // assume as virtual float getMaxFov() const {return 175.f * 4.f/3.f;} // assume
pect ration of 4/3 for getting a full 360 degree horizon aspect ration of 4/3 for getting a full 360 degree horizon
bool forward(Vec3d &win) const; bool forward(Vec3f &win) const;
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return true;} virtual bool hasDiscontinuity() const {return true;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
{ {
return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0); return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
} }
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap
N, double capD) const
{
static const SphericalCap cap1(1,0,0);
static const SphericalCap cap2(-1,0,0);
static const SphericalCap cap3(0,0,-1);
SphericalCap cap(capN, capD);
return cap.intersects(cap1) && cap.intersects(cap2) && cap.i
ntersects(cap2);
}
}; };
class StelProjectorMercator : public StelProjector class StelProjectorMercator : public StelProjector
{ {
public: public:
StelProjectorMercator(const Mat4d& modelViewMat) : StelProjector(mod elViewMat) {;} StelProjectorMercator(const Mat4d& modelViewMat) : StelProjector(mod elViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 175. * 4./3.;} // assume as virtual float getMaxFov() const {return 175.f * 4.f/3.f;} // assume
pect ration of 4/3 for getting a full 360 degree horizon aspect ration of 4/3 for getting a full 360 degree horizon
bool forward(Vec3d &win) const; bool forward(Vec3f &win) const;
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return true;} virtual bool hasDiscontinuity() const {return true;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
{ {
return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0); return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
} }
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap
N, double capD) const
{
static const SphericalCap cap1(1,0,0);
static const SphericalCap cap2(-1,0,0);
static const SphericalCap cap3(0,0,-1);
SphericalCap cap(capN, capD);
return cap.intersects(cap1) && cap.intersects(cap2) && cap.i
ntersects(cap2);
}
}; };
class StelProjectorOrthographic : public StelProjector class StelProjectorOrthographic : public StelProjector
{ {
public: public:
StelProjectorOrthographic(const Mat4d& modelViewMat) : StelProjector (modelViewMat) {;} StelProjectorOrthographic(const Mat4d& modelViewMat) : StelProjector (modelViewMat) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 179.9999;} virtual float getMaxFov() const {return 179.9999f;}
bool forward(Vec3d &win) const; bool forward(Vec3f &win) const;
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return false;} virtual bool hasDiscontinuity() const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co
const Vec3d& p2) const {return false;} nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do
uble) const {return false;}
}; };
class StelProjector2d : public StelProjector class StelProjector2d : public StelProjector
{ {
public: public:
StelProjector2d() : StelProjector(Mat4d::identity()) {;} StelProjector2d() : StelProjector(Mat4d::identity()) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual double getMaxFov() const {return 360.;} virtual float getMaxFov() const {return 360.f;}
bool forward(Vec3d &win) const; bool forward(Vec3f &win) const;
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
double fovToViewScalingFactor(double fov) const; float fovToViewScalingFactor(float fov) const;
double viewScalingFactorToFov(double vsf) const; float viewScalingFactorToFov(float vsf) const;
double deltaZoom(double fov) const; float deltaZoom(float fov) const;
protected: protected:
virtual bool hasDiscontinuity() const {return false;} virtual bool hasDiscontinuity() const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co
const Vec3d& p2) const {Q_ASSERT(0); return false;} nst Vec3d&) const {Q_ASSERT(0); return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do
uble) const {Q_ASSERT(0); return false;}
virtual void computeBoundingCap() {;}
}; };
#endif // _STELPROJECTIONS_HPP_ #endif // _STELPROJECTIONS_HPP_
 End of changes. 41 change blocks. 
103 lines changed or deleted 151 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/