Stellarium 0.11.4
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelProjector.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2003 Fabien Chereau
00004  * Copyright (C) 2012 Matthew Gates
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00019  */
00020 
00021 #ifndef _STELPROJECTOR_HPP_
00022 #define _STELPROJECTOR_HPP_
00023 
00024 #include "StelProjectorType.hpp"
00025 #include "VecMath.hpp"
00026 #include "StelSphereGeometry.hpp"
00027 
00035 class StelProjector
00036 {
00037 public:
00038     friend class StelPainter;
00039     friend class StelCore;
00040 
00041     class ModelViewTranform;
00044     typedef QSharedPointer<ModelViewTranform> ModelViewTranformP;
00045 
00048     class ModelViewTranform
00049     {
00050     public:
00051         ModelViewTranform() {;}
00052         virtual ~ModelViewTranform() {;}
00053         virtual void forward(Vec3d&) const =0;
00054         virtual void backward(Vec3d&) const =0;
00055         virtual void forward(Vec3f&) const =0;
00056         virtual void backward(Vec3f&) const =0;
00057 
00058         virtual void combine(const Mat4d&)=0;
00059         virtual ModelViewTranformP clone() const=0;
00060 
00061         virtual Mat4d getApproximateLinearTransfo() const=0;
00062     };
00063 
00064     class Mat4dTransform: public ModelViewTranform
00065     {
00066     public:
00067         Mat4dTransform(const Mat4d& m);
00068         void forward(Vec3d& v) const;
00069         void backward(Vec3d& v) const;
00070         void forward(Vec3f& v) const;
00071         void backward(Vec3f& v) const;
00072         void combine(const Mat4d& m);
00073         Mat4d getApproximateLinearTransfo() const;
00074         ModelViewTranformP clone() const;
00075 
00076     private:
00078         Mat4d transfoMat;
00079         Mat4f transfoMatf;
00080     };
00081 
00084     enum StelProjectorMaskType
00085     {
00086         MaskNone,   
00087         MaskDisk    
00088     };
00089 
00092     struct StelProjectorParams
00093     {
00094         StelProjectorParams() : viewportXywh(0, 0, 256, 256), fov(60.f), gravityLabels(false), defautAngleForGravityText(0.f), maskType(MaskNone), viewportCenter(128.f, 128.f), flipHorz(false), flipVert(false) {;}
00095         Vector4<int> viewportXywh;      
00096         float fov;                      
00097         bool gravityLabels;             
00098         float defautAngleForGravityText;
00099         StelProjectorMaskType maskType; 
00100         float zNear, zFar;              
00101         Vec2f viewportCenter;           
00102         float viewportFovDiameter;      
00103         bool flipHorz, flipVert;        
00104     };
00105 
00107     virtual ~StelProjector() {}
00108 
00110     // Methods which must be reimplemented by all instance of StelProjector
00112     virtual QString getNameI18() const = 0;
00114     virtual QString getDescriptionI18() const {return "No description";}
00116     QString getHtmlSummary() const;
00118     virtual float getMaxFov() const = 0;
00125     virtual bool forward(Vec3f& v) const = 0;
00127     virtual bool backward(Vec3d& v) const = 0;
00129     virtual float deltaZoom(float fov) const = 0;
00130 
00134     bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2) const;
00135     bool intersectViewportDiscontinuity(const SphericalCap& cap) const;
00136 
00138     virtual float fovToViewScalingFactor(float fov) const = 0;
00140     virtual float viewScalingFactorToFov(float vsf) const = 0;
00141 
00145     bool getFlagGravityLabels() const;
00146 
00148     const Vec4i& getViewport() const;
00149 
00151     Vec2f getViewportCenter() const;
00152 
00154     int getViewportPosX() const;
00156     int getViewportPosY() const;
00158     int getViewportWidth() const;
00160     int getViewportHeight() const;
00161 
00167     SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const;
00168 
00170     const SphericalCap& getBoundingCap() const;
00171 
00173     float getPixelPerRadAtCenter() const;
00174 
00176     float getFov() const;
00177 
00179     bool needGlFrontFaceCW() const;
00180 
00182     // Full projection methods
00185     bool checkInViewport(const Vec3d& pos) const;
00186 
00189     bool checkInViewport(const Vec3f& pos) const;
00190 
00193     Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const;
00194 
00199     bool project(const Vec3d& v, Vec3d& win) const;
00200 
00205     bool project(const Vec3f& v, Vec3f& win) const;
00206 
00207     virtual void project(int n, const Vec3d* in, Vec3f* out);
00208 
00209     virtual void project(int n, const Vec3f* in, Vec3f* out);
00210 
00214     bool projectInPlace(Vec3d& vd) const;
00215 
00219     bool projectInPlace(Vec3f& v) const;
00220 
00225     bool projectCheck(const Vec3d& v, Vec3d& win) const;
00226 
00231     bool projectCheck(const Vec3f& v, Vec3f& win) const;
00232 
00237     bool unProject(const Vec3d& win, Vec3d& v) const;
00238     bool unProject(double x, double y, Vec3d& v) const;
00239 
00246     bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
00247 
00249     ModelViewTranformP getModelViewTransform() const;
00250 
00252     Mat4f getProjectionMatrix() const;
00253 
00256     static const QString maskTypeToString(StelProjectorMaskType type);
00258     static StelProjectorMaskType stringToMaskType(const QString &s);
00259 
00261     StelProjectorMaskType getMaskType(void) const;
00262 
00263 protected:
00265     StelProjector(ModelViewTranformP amodelViewTransform) : modelViewTransform(amodelViewTransform) {;}
00266 
00268     virtual bool hasDiscontinuity() const =0;
00272     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
00273 
00275     virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const = 0;
00276 
00278     virtual void computeBoundingCap();
00279 
00280     ModelViewTranformP modelViewTransform;  // Operator to apply (if not NULL) before the modelview projection step
00281 
00282     float flipHorz,flipVert;            // Whether to flip in horizontal or vertical directions
00283     float pixelPerRad;                  // pixel per rad at the center of the viewport disk
00284     StelProjectorMaskType maskType;     // The current projector mask
00285     float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
00286     Vec4i viewportXywh;                 // Viewport parameters
00287     Vec2f viewportCenter;               // Viewport center in screen pixel
00288     float viewportFovDiameter;          // diameter of the FOV disk in pixel
00289     bool gravityLabels;                 // should label text align with the horizon?
00290     float defautAngleForGravityText;    // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
00291     SphericalCap boundingCap;           // Bounding cap of the whole viewport
00292 
00293 private:
00295     void init(const StelProjectorParams& param);
00296 };
00297 
00298 #endif // _STELPROJECTOR_HPP_
Generated on Sat Aug 25 22:13:30 2012 for Stellarium by  doxygen 1.6.3