StelProjector.hpp   StelProjector.hpp 
skipping to change at line 27 skipping to change at line 27
* 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.
*/ */
#ifndef _STELPROJECTOR_HPP_ #ifndef _STELPROJECTOR_HPP_
#define _STELPROJECTOR_HPP_ #define _STELPROJECTOR_HPP_
#include "StelProjectorType.hpp" #include "StelProjectorType.hpp"
#include "VecMath.hpp" #include "VecMath.hpp"
#include "StelSphereGeometry.hpp" #include "StelSphereGeometry.hpp"
#include "renderer/StelGLSLShader.hpp"
//! @class StelProjector //! @class StelProjector
//! Provide the main interface to all operations of projecting coordinates from sky to screen. //! Provide the main interface to all operations of projecting coordinates from sky to screen.
//! The StelProjector also defines the viewport size and position. //! The StelProjector also defines the viewport size and position.
//! All methods from this class are threadsafe. The usual usage is to creat e local instances of StelProjectorP using the //! All methods from this class are threadsafe. The usual usage is to creat e local instances of StelProjectorP using the
//! getProjection() method from StelCore where needed. //! getProjection() method from StelCore where needed.
//! For performing drawing using a particular projection, refer to the Stel //! For performing drawing using a particular projection, see
Painter class. //! StelRenderer and its backends.
//! @sa StelProjectorP //! @sa StelProjectorP
class StelProjector class StelProjector
{ {
public: public:
friend class StelPainter;
friend class StelCore; friend class StelCore;
//! Base class for classes implementing vertex projection in GLSL.
//!
//! Each StelProjector implementation can have its own GLSLProjector
//! implementation implementing the project() member function in GLS
L.
class GLSLProjector
{
public:
//! Initialize GLSL projection. Called by renderer backend b
efore drawing.
//!
//! This attempts to attach (or re-enable, if already attach
ed) the
//! projection GLSL code to specified shader.
//!
//! This function may fail (e.g. due to a build error).
//! In that case, the renderer will fall back to CPU project
ion.
//!
//! @param shader Shader to attach the GLSL projection code
to.
//! @return true on success, false on failure.
virtual bool init(class StelGLSLShader* shader) = 0;
//! Called after init() succeeds, directly before drawing.
//!
//! This is used to set up uniforms.
//!
//! @param shader Shader previously passed to init() in boun
d state,
//! ready to set uniforms.
virtual void preDraw(class StelGLSLShader* shader) = 0;
//! Called after init() succeeds, after drawing.
//!
//! Used to disable the projection GLSL code.
virtual void postDraw(class StelGLSLShader* shader) = 0;
};
class ModelViewTranform; class ModelViewTranform;
//! @typedef ModelViewTranformP //! @typedef ModelViewTranformP
//! Shared pointer on a ModelViewTranform instance (implement refere nce counting) //! Shared pointer on a ModelViewTranform instance (implement refere nce counting)
typedef QSharedPointer<ModelViewTranform> ModelViewTranformP; typedef QSharedPointer<ModelViewTranform> ModelViewTranformP;
//! @class PreModelViewFunc //! @class PreModelViewFunc
//! Allows to define non linear operations in addition to the standa rd linear (Matrix 4d) ModelView transformation. //! Allows to define non linear operations in addition to the standa rd linear (Matrix 4d) ModelView transformation.
class ModelViewTranform class ModelViewTranform
{ {
public: public:
ModelViewTranform() {;} ModelViewTranform() {;}
virtual ~ModelViewTranform() {;} virtual ~ModelViewTranform() {;}
virtual void forward(Vec3d&) const =0; virtual void forward(Vec3d&) const =0;
virtual void backward(Vec3d&) const =0; virtual void backward(Vec3d&) const =0;
virtual void forward(Vec3f&) const =0; virtual void forward(Vec3f&) const =0;
virtual void backward(Vec3f&) const =0; virtual void backward(Vec3f&) const =0;
virtual void combine(const Mat4d&)=0; virtual void combine(const Mat4d&)=0;
virtual ModelViewTranformP clone() const=0; virtual ModelViewTranformP clone() const=0;
//! Attaches (or enables, if attached already) the GLSL tran
sform shader to specified shader.
//!
//! The shader attached must implement one function:
//!
//! vec4(modelViewForward(in vec4 v));
//!
//! This function should implement the same logic as the for
ward() member function,
//! except that it returns the result instead of modifying t
he parameter.
//!
//! @param shader Shader to attach to.
//!
//! @return true if the shader was succesfully attached, fal
se otherwise.
virtual bool setupGLSLTransform(class StelGLSLShader* shader
) = 0;
//! Set GLSL uniforms needed for the transform shader.
//!
//! Called by the renderer backend before drawing, if the tr
ansform
//! shader was attached successfully.
virtual void setGLSLUniforms(class StelGLSLShader* shader) =
0;
//! Disable the attached GLSL transform shader.
virtual void disableGLSLTransform(class StelGLSLShader* shad
er) = 0;
virtual Mat4d getApproximateLinearTransfo() const=0; virtual Mat4d getApproximateLinearTransfo() const=0;
}; };
class Mat4dTransform: public ModelViewTranform class Mat4dTransform: public ModelViewTranform
{ {
public: public:
Mat4dTransform(const Mat4d& m); Mat4dTransform(const Mat4d& m);
void forward(Vec3d& v) const; void forward(Vec3d& v) const;
void backward(Vec3d& v) const; void backward(Vec3d& v) const;
void forward(Vec3f& v) const; void forward(Vec3f& v) const;
void backward(Vec3f& v) const; void backward(Vec3f& v) const;
void combine(const Mat4d& m); void combine(const Mat4d& m);
Mat4d getApproximateLinearTransfo() const; Mat4d getApproximateLinearTransfo() const;
ModelViewTranformP clone() const; ModelViewTranformP clone() const;
virtual bool setupGLSLTransform(StelGLSLShader* shader)
{
if(!shader->hasVertexShader("Mat4dTransform"))
{
static const QString source(
"uniform mat4 modelViewMatrix;\n"
"\n"
"vec4 modelViewForward(in vec4 v)\n"
"{\n"
" return modelViewMatrix * v;\
n"
"}\n");
if(!shader->addVertexShader("Mat4dTransform"
, source))
{
return false;
}
qDebug() << "Build log after adding a Mat4d
transform shader: "
<< shader->log();
}
shader->enableVertexShader("Mat4dTransform");
return true;
}
virtual void setGLSLUniforms(StelGLSLShader* shader)
{
shader->setUniformValue("modelViewMatrix", transfoMa
tf);
}
virtual void disableGLSLTransform(StelGLSLShader* shader)
{
shader->disableVertexShader("Mat4dTransform");
}
private: private:
//! transfo matrix and invert //! transfo matrix and invert
Mat4d transfoMat; Mat4d transfoMat;
Mat4f transfoMatf; Mat4f transfoMatf;
}; };
//! @enum StelProjectorMaskType //! @enum StelProjectorMaskType
//! Define viewport mask types //! Define viewport mask types
enum StelProjectorMaskType enum StelProjectorMaskType
skipping to change at line 179 skipping to change at line 269
//! Return a SphericalCap containing the whole viewport //! Return a SphericalCap containing the whole viewport
const SphericalCap& getBoundingCap() const; const SphericalCap& getBoundingCap() const;
//! Get size of a radian in pixels at the center of the viewport dis k //! Get size of a radian in pixels at the center of the viewport dis k
float getPixelPerRadAtCenter() const; float getPixelPerRadAtCenter() const;
//! Get the current FOV diameter in degrees //! Get the current FOV diameter in degrees
float getFov() const; float getFov() const;
//! Get whether front faces need to be oriented in the clockwise dir ection //! Get whether front faces need to be oriented in the clockwise dir ection
bool needGlFrontFaceCW() const; bool flipFrontBackFace() const
{
// Moved to header for inlining
return (flipHorz*flipVert < 0.f);
}
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
// Full projection methods // Full projection methods
//! Check to see if a 2d position is inside the viewport. //! Check to see if a 2d position is inside the viewport.
//! TODO Optimize by storing viewportXywh[1] + viewportXywh[3] and v iewportXywh[0] + viewportXywh[2] already computed //! TODO Optimize by storing viewportXywh[1] + viewportXywh[3] and v iewportXywh[0] + viewportXywh[2] already computed
bool checkInViewport(const Vec3d& pos) const; bool checkInViewport(const Vec3d& pos) const;
//! Check to see if a 2d position is inside the viewport. //! Check to see if a 2d position is inside the viewport.
//! TODO Optimize by storing viewportXywh[1] + viewportXywh[3] and v iewportXywh[0] + viewportXywh[2] already computed //! TODO Optimize by storing viewportXywh[1] + viewportXywh[3] and v iewportXywh[0] + viewportXywh[2] already computed
bool checkInViewport(const Vec3f& pos) const; bool checkInViewport(const Vec3f& pos) const;
skipping to change at line 211 skipping to change at line 305
//! Project the vector v from the current frame into the viewport. //! Project the vector v from the current frame into the viewport.
//! @param v the vector in the current frame. //! @param v the vector in the current frame.
//! @param win the projected vector in the viewport 2D frame. //! @param win the projected vector in the viewport 2D frame.
//! @return true if the projected coordinate is valid. //! @return true if the projected coordinate is valid.
bool project(const Vec3f& v, Vec3f& win) const; bool project(const Vec3f& v, Vec3f& win) const;
virtual void project(int n, const Vec3d* in, Vec3f* out); virtual void project(int n, const Vec3d* in, Vec3f* out);
virtual void project(int n, const Vec3f* in, Vec3f* out); virtual void project(int n, const Vec3f* in, Vec3f* out);
//! Return the GLSLProjector to provide GLSL projection functionalit
y.
//!
//! This can return NULL if the StelProjector implementation
//! does not support GLSL projection.
virtual GLSLProjector* getGLSLProjector()
{
// No GLSL projection support by default.
return NULL;
}
//! Project the vector v from the current frame into the viewport. //! Project the vector v from the current frame into the viewport.
//! @param vd the vector in the current frame. //! @param vd the vector in the current frame.
//! @return true if the projected coordinate is valid. //! @return true if the projected coordinate is valid.
bool projectInPlace(Vec3d& vd) const; bool projectInPlace(Vec3d& vd) const;
//! Project the vector v from the current frame into the viewport. //! Project the vector v from the current frame into the viewport.
//! @param v the vector in the current frame. //! @param v the vector in the current frame.
//! @return true if the projected coordinate is valid. //! @return true if the projected coordinate is valid.
bool projectInPlace(Vec3f& v) const; bool projectInPlace(Vec3f& v) const;
skipping to change at line 252 skipping to change at line 356
//! @param v2 the second vector in the current frame. //! @param v2 the second vector in the current frame.
//! @param win1 the first projected vector in the viewport 2D frame. //! @param win1 the first projected vector in the viewport 2D frame.
//! @param win2 the second projected vector in the viewport 2D frame . //! @param win2 the second projected vector in the viewport 2D frame .
//! @return true if at least one of the projected vector is within t he viewport. //! @return true if at least one of the projected vector is within t he viewport.
bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const; bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
//! Get the current model view matrix. //! Get the current model view matrix.
ModelViewTranformP getModelViewTransform() const; ModelViewTranformP getModelViewTransform() const;
//! Get the current projection matrix. //! Get the current projection matrix.
Mat4f getProjectionMatrix() const; Mat4f getProjectionMatrix() const
{
// Moved to header for inlining.
return Mat4f(2.f/viewportXywh[2], 0, 0, 0,
0, 2.f/viewportXywh[3], 0, 0,
0, 0, -1., 0.,
-(2.f*viewportXywh[0] + viewportXywh[2])/viewpo
rtXywh[2], -(2.f*viewportXywh[1] + viewportXywh[3])/viewportXywh[3], 0, 1);
}
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
//! Get a string description of a StelProjectorMaskType. //! Get a string description of a StelProjectorMaskType.
static const QString maskTypeToString(StelProjectorMaskType type); static const QString maskTypeToString(StelProjectorMaskType type);
//! Get a StelProjectorMaskType from a string description. //! Get a StelProjectorMaskType from a string description.
static StelProjectorMaskType stringToMaskType(const QString &s); static StelProjectorMaskType stringToMaskType(const QString &s);
//! Get the current type of the mask if any. //! Get the current type of the mask if any.
StelProjectorMaskType getMaskType(void) const; StelProjectorMaskType getMaskType(void) const;
//! Get viewport extents.
Vec4i getViewportXywh() const
{
return viewportXywh;
}
//! Should label text align with the horizon?
bool useGravityLabels() const
{
return gravityLabels;
}
//! Return the rotation angle to apply to gravity text (only if grav
ityLabels is false) .
float getDefaultAngleForGravityText() const
{
return defautAngleForGravityText;
}
//! Get center of the viewport on the screen in pixels.
Vec2f getViewportCenterAbsolute() const
{
return viewportCenter;
}
//! Get diameter of the FOV disk in pixels.
float getViewportFovDiameter()
{
return viewportFovDiameter;
}
protected: protected:
//! Private constructor. Only StelCore can create instances of StelP rojector. //! Private constructor. Only StelCore can create instances of StelP rojector.
StelProjector(ModelViewTranformP amodelViewTransform) : modelViewTra StelProjector(ModelViewTranformP amodelViewTransform)
nsform(amodelViewTransform) {;} : modelViewTransform(amodelViewTransform)
, disableShaderProjection(false)
{;}
//! Return whether the projection presents discontinuities. Used for optimization. //! Return whether the projection presents discontinuities. Used for optimization.
virtual bool hasDiscontinuity() const =0; virtual bool hasDiscontinuity() const =0;
//! Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity. //! Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity.
//! For many projections without discontinuity, this should return a lways false, but for other like //! For many projections without discontinuity, this should return a lways false, but for other like
//! cylindrical projection it will return true if the line cuts the wrap-around line (i.e. at lon=180 if the observer look at lon=0). //! cylindrical projection it will return true if the line cuts the wrap-around line (i.e. at lon=180 if the observer look at lon=0).
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0; virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
//! Determine whether a cap intersects with a projection discontinui ty. //! Determine whether a cap intersects with a projection discontinui ty.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap N, double capD) const = 0; virtual bool intersectViewportDiscontinuityInternal(const Vec3d& cap N, double capD) const = 0;
skipping to change at line 293 skipping to change at line 437
float pixelPerRad; // pixel per rad at the center o f the viewport disk float pixelPerRad; // pixel per rad at the center o f the viewport disk
StelProjectorMaskType maskType; // The current projector mask StelProjectorMaskType maskType; // The current projector mask
float zNear, oneOverZNearMinusZFar; // Near and far clipping planes float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
Vec4i viewportXywh; // Viewport parameters Vec4i viewportXywh; // Viewport parameters
Vec2f viewportCenter; // Viewport center in screen pix el Vec2f viewportCenter; // Viewport center in screen pix el
float viewportFovDiameter; // diameter of the FOV disk in p ixel float viewportFovDiameter; // diameter of the FOV disk in p ixel
bool gravityLabels; // should label text align with the horizon? bool gravityLabels; // should label text align with the horizon?
float defautAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false) float defautAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
SphericalCap boundingCap; // Bounding cap of the whole vie wport SphericalCap boundingCap; // Bounding cap of the whole vie wport
//! If true, shader projection is disabled.
//!
//! Set when an attempt to set up shader projection fails.
bool disableShaderProjection;
private: private:
//! Initialise the StelProjector from a param instance. //! Initialise the StelProjector from a param instance.
void init(const StelProjectorParams& param); void init(const StelProjectorParams& param);
}; };
#endif // _STELPROJECTOR_HPP_ #endif // _STELPROJECTOR_HPP_
 End of changes. 12 change blocks. 
15 lines changed or deleted 183 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/