00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STELPROJECTOR_HPP_
00021 #define _STELPROJECTOR_HPP_
00022
00023 #include "StelProjectorType.hpp"
00024 #include "VecMath.hpp"
00025 #include "StelSphereGeometry.hpp"
00026
00034 class StelProjector
00035 {
00036 public:
00037 friend class StelPainter;
00038 friend class StelCore;
00039
00042 enum StelProjectorMaskType
00043 {
00044 MaskNone,
00045 MaskDisk
00046 };
00047
00050 struct StelProjectorParams
00051 {
00052 StelProjectorParams() : viewportXywh(0), fov(60.), gravityLabels(false), maskType(MaskNone), viewportCenter(0., 0.), flipHorz(false), flipVert(false) {;}
00053 Vector4<int> viewportXywh;
00054 double fov;
00055 bool gravityLabels;
00056 StelProjectorMaskType maskType;
00057 double zNear, zFar;
00058 Vec2d viewportCenter;
00059 double viewportFovDiameter;
00060 bool flipHorz, flipVert;
00061 };
00062
00064 virtual ~StelProjector() {;}
00065
00067
00069 virtual QString getNameI18() const = 0;
00071 virtual QString getDescriptionI18() const {return "No description";}
00073 QString getHtmlSummary() const;
00075 virtual double getMaxFov() const = 0;
00082 virtual bool forward(Vec3d &v) const = 0;
00084 virtual bool backward(Vec3d &v) const = 0;
00086 virtual double deltaZoom(double fov) const = 0;
00087
00089 virtual double fovToViewScalingFactor(double fov) const = 0;
00091 virtual double viewScalingFactorToFov(double vsf) const = 0;
00092
00096 bool getFlagGravityLabels() const { return gravityLabels; }
00097
00099 const Vec4i& getViewport(void) const {return viewportXywh;}
00100
00102 Vec2d getViewportCenter(void) const
00103 {
00104 return Vec2d(viewportCenter[0]-viewportXywh[0],viewportCenter[1]-viewportXywh[1]);
00105 }
00106
00108 int getViewportPosX(void) const {return viewportXywh[0];}
00110 int getViewportPosY(void) const {return viewportXywh[1];}
00112 int getViewportWidth(void) const {return viewportXywh[2];}
00114 int getViewportHeight(void) const {return viewportXywh[3];}
00115
00120 StelGeom::ConvexPolygon getViewportConvexPolygon(double marginX=0., double marginY=0.) const;
00121
00125 StelGeom::ConvexS unprojectViewport() const;
00126
00128 StelGeom::HalfSpace getBoundingHalfSpace() const;
00129
00131 double getPixelPerRadAtCenter(void) const {return pixelPerRad;}
00132
00134 double getFov() const {return 360./M_PI*viewScalingFactorToFov(0.5*viewportFovDiameter/pixelPerRad);}
00135
00137 bool needGlFrontFaceCW(void) const {return (flipHorz*flipVert < 0.0);}
00138
00140
00143 bool checkInViewport(const Vec3d& pos) const
00144 {
00145 return (pos[1]>=viewportXywh[1] && pos[0]>=viewportXywh[0] &&
00146 pos[1]<=(viewportXywh[1] + viewportXywh[3]) && pos[0]<=(viewportXywh[0] + viewportXywh[2]));
00147 }
00148
00151 Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const
00152 {
00153 Vec3d v1=p1;
00154 Vec3d v2=p2;
00155 Vec3d v;
00156 for (int i=0;i<8;++i)
00157 {
00158 v=(v1+v2)*0.5;
00159 if (!checkInViewport(v))
00160 v2=v;
00161 else
00162 v1=v;
00163 }
00164 return v;
00165 }
00166
00171 bool project(const Vec3d& v, Vec3d& win) const
00172 {
00173
00174 win[0] = modelViewMatrix.r[0]*v[0] + modelViewMatrix.r[4]*v[1]
00175 + modelViewMatrix.r[8]*v[2] + modelViewMatrix.r[12];
00176 win[1] = modelViewMatrix.r[1]*v[0] + modelViewMatrix.r[5]*v[1]
00177 + modelViewMatrix.r[9]*v[2] + modelViewMatrix.r[13];
00178 win[2] = modelViewMatrix.r[2]*v[0] + modelViewMatrix.r[6]*v[1]
00179 + modelViewMatrix.r[10]*v[2] + modelViewMatrix.r[14];
00180 const bool rval = forward(win);
00181
00182
00183
00184
00185 win[0] = viewportCenter[0] + flipHorz * pixelPerRad * win[0];
00186 win[1] = viewportCenter[1] + flipVert * pixelPerRad * win[1];
00187 win[2] = (win[2] - zNear) * oneOverZNearMinusZFar;
00188 return rval;
00189 }
00190
00195 bool projectCheck(const Vec3d& v, Vec3d& win) const {return (project(v, win) && checkInViewport(win));}
00196
00201 bool unProject(const Vec3d& win, Vec3d& v) const {return unProject(win[0], win[1], v);}
00202 bool unProject(double x, double y, Vec3d& v) const;
00203
00210 bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const
00211 {return project(v1, win1) && project(v2, win2) && (checkInViewport(win1) || checkInViewport(win2));}
00212
00214 const Mat4d& getModelViewMatrix() const {return modelViewMatrix;}
00215
00218 static const QString maskTypeToString(StelProjectorMaskType type);
00220 static StelProjectorMaskType stringToMaskType(const QString &s);
00221
00223 StelProjectorMaskType getMaskType(void) const {return maskType;}
00224
00225 protected:
00227 StelProjector(const Mat4d& modelViewMat) : modelViewMatrix(modelViewMat) {;}
00228
00229 private:
00231 void init(const StelProjectorParams& param);
00232
00233 StelProjectorMaskType maskType;
00234 double zNear, oneOverZNearMinusZFar;
00235 Vec4i viewportXywh;
00236 Vec2d viewportCenter;
00237 double viewportFovDiameter;
00238 double pixelPerRad;
00239 double flipHorz,flipVert;
00240 bool gravityLabels;
00241 Mat4d modelViewMatrix;
00242 };
00243
00244 #endif // _STELPROJECTOR_HPP_