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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _STELPROJECTIONS_HPP_ #ifndef _STELPROJECTIONS_HPP_
#define _STELPROJECTIONS_HPP_ #define _STELPROJECTIONS_HPP_
#include <limits>
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelSphereGeometry.hpp"
#include "renderer/StelGLSLShader.hpp" #include <limits>
class StelProjectorPerspective : public StelProjector class StelProjectorPerspective : public StelProjector
{ {
public: public:
StelProjectorPerspective(ModelViewTranformP func) : StelProjector(fu nc) {;} StelProjectorPerspective(ModelViewTranformP func) : StelProjector(fu nc) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual float getMaxFov() const {return 120.f;} virtual float getMaxFov() const {return 120.f;}
bool forward(Vec3f &v) const bool forward(Vec3f &v) const
{ {
skipping to change at line 93 skipping to change at line 92
float viewScalingFactorToFov(float vsf) const; float viewScalingFactorToFov(float vsf) const;
float deltaZoom(float 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&, co nst Vec3d&) const {return false;} virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do uble) const {return false;} virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do uble) const {return false;}
}; };
class StelProjectorStereographic : public StelProjector class StelProjectorStereographic : public StelProjector
{ {
friend class StereographicGLSLProjectorShader;
private:
//! GLSL projector code for StelProjectorStereographic.
//!
//! Note that when adding GLSL projection to other projectors, a lot
//! of this code might be shared (maybe the main GLSL projection fun
ction)
//! and need to be refactored to the parent class.
class StereographicGLSLProjector : public StelProjector::GLSLProject
or
{
friend class StelProjectorStereographic;
StelProjectorStereographic& projector;
public:
virtual bool init(StelGLSLShader* shader)
{
if(projector.disableShaderProjection)
{
return false;
}
shader->unlock();
// Add (or enable, if already added) shader for the
used modelview transform.
// Not all ModelViewTranforms have GLSL implementati
ons (e.g. Refraction)
if(!projector.modelViewTransform->setupGLSLTransform
(shader))
{
// Failed to add the transform shader, retur
n the shader into locked state.
if(!shader->build())
{
Q_ASSERT_X(false, Q_FUNC_INFO,
"Failed to restore shader
after failing to add a modelview "
"transform shader to it")
;
}
return false;
}
// Add the stereographic projector shader if not yet
added.
if(!shader->hasVertexShader("StereographicProjector"
))
{
static const QString projectorSource(
"vec4 modelViewForward(in vec4 v);\n
"
"\n"
"uniform vec2 viewportCenter;\n"
"uniform float flipHorz;\n"
"uniform float flipVert;\n"
"uniform float pixelPerRad;\n"
"uniform float zNear;\n"
"uniform float oneOverZNearMinusZFar
;\n"
"\n"
"vec4 projectorForward(in vec4 v)\n"
"{\n"
" float r = sqrt(v.x * v.x + v
.y * v.y + v.z * v.z);\n"
" float h = 0.5 * (r - v.z);\n
"
" if (h <= 0.0) \n"
" {\n"
" return vec4(1000000.
0, 1000000.0, -1000000.0, 1.0);\n"
" }\n"
" float f = 1.0 / h;\n"
" return vec4(v.x * f, v.y * f
, r, 1.0);\n"
"}\n"
"\n"
"vec4 project(in vec4 posIn)\n"
"{\n"
" vec4 v = posIn;\n"
" v = modelViewForward(v);\n"
" v = projectorForward(v);\n"
" return vec4(viewportCenter.x
+ flipHorz * pixelPerRad * v.x,\n"
" viewportCenter.y
+ flipVert * pixelPerRad * v.y,\n"
" (v.z - zNear) *
oneOverZNearMinusZFar, 1.0);\n"
"}\n");
if(!shader->addVertexShader("StereographicPr
ojector", projectorSource))
{
// Failed to add the projector shade
r, return the shader into locked state.
if(!shader->build())
{
Q_ASSERT_X(false, Q_FUNC_INF
O,
"Failed to restor
e shader after failing to add a stereographic "
"projector shader
to it");
}
projector.disableShaderProjection =
true;
return false;
}
qDebug() << "Build log after adding a stereo
graphic projection shader: "
<< shader->log();
}
shader->disableVertexShader("DefaultProjector");
shader->enableVertexShader("StereographicProjector")
;
if(!shader->build())
{
qDebug() << "Failed to build with a stereogr
aphic projector shader: "
<< shader->log();
projector.disableShaderProjection = true;
shader->enableVertexShader("DefaultProjector
");
shader->disableVertexShader("StereographicPr
ojector");
if(!shader->build())
{
Q_ASSERT_X(false, Q_FUNC_INFO,
"Failed to restore defaul
t projector shader after failing to link "
"with a (succesfully comp
iled) stereographic projector shader");
}
}
return true;
}
virtual void preDraw(StelGLSLShader* shader)
{
projector.modelViewTransform->setGLSLUniforms(shader
);
shader->setUniformValue("viewportCenter", pro
jector.viewportCenter);
shader->setUniformValue("flipHorz", pro
jector.flipHorz);
shader->setUniformValue("flipVert", pro
jector.flipVert);
shader->setUniformValue("pixelPerRad", pro
jector.pixelPerRad);
shader->setUniformValue("zNear", pro
jector.zNear);
shader->setUniformValue("oneOverZNearMinusZFar", pro
jector.oneOverZNearMinusZFar);
}
virtual void postDraw(StelGLSLShader* shader)
{
shader->unlock();
projector.modelViewTransform->disableGLSLTransform(s
hader);
shader->disableVertexShader("StereographicProjector"
);
shader->enableVertexShader("DefaultProjector");
if(!shader->build())
{
Q_ASSERT_X(false, Q_FUNC_INFO, "Failed to di
sable projector shader");
}
}
private:
//! Constructor. Only a StelProjectorStereographic can call
this.
StereographicGLSLProjector(StelProjectorStereographic& proje
ctor)
: projector(projector)
{
}
};
public: public:
StelProjectorStereographic(ModelViewTranformP func) StelProjectorStereographic(ModelViewTranformP func) : StelProjector(
: StelProjector(func) func) {;}
, glslProjector(*this)
{;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual float getMaxFov() const {return 235.f;} virtual float getMaxFov() const {return 235.f;}
bool forward(Vec3f &v) const bool 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 float h = 0.5f*(r-v[2]); const float h = 0.5f*(r-v[2]);
if (h <= 0.f) { if (h <= 0.f) {
v[0] = std::numeric_limits<float>::max(); v[0] = std::numeric_limits<float>::max();
v[1] = std::numeric_limits<float>::max(); v[1] = std::numeric_limits<float>::max();
skipping to change at line 272 skipping to change at line 129
v = in[i]; v = in[i];
modelViewTransform->forward(v); modelViewTransform->forward(v);
out->set(v[0], v[1], v[2]); out->set(v[0], v[1], v[2]);
StelProjectorStereographic::forward(*out); StelProjectorStereographic::forward(*out);
out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0], out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0],
viewportCenter[1] + flipVert * pixelPerRad * (*out)[1], viewportCenter[1] + flipVert * pixelPerRad * (*out)[1],
((*out)[2] - zNear) * oneOverZNearMinusZFar) ; ((*out)[2] - zNear) * oneOverZNearMinusZFar) ;
} }
} }
virtual GLSLProjector* getGLSLProjector()
{
return &glslProjector;
}
bool backward(Vec3d &v) const; bool backward(Vec3d &v) const;
float fovToViewScalingFactor(float fov) const; float fovToViewScalingFactor(float fov) const;
float viewScalingFactorToFov(float vsf) const; float viewScalingFactorToFov(float vsf) const;
float deltaZoom(float 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&, co nst Vec3d&) const {return false;} virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, co nst Vec3d&) const {return false;}
virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do uble) const {return false;} virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, do uble) const {return false;}
private:
//! If GLSL is supported, this is used for GPU projection.
StereographicGLSLProjector glslProjector;
}; };
class StelProjectorFisheye : public StelProjector class StelProjectorFisheye : public StelProjector
{ {
public: public:
StelProjectorFisheye(ModelViewTranformP func) : StelProjector(func) {;} StelProjectorFisheye(ModelViewTranformP func) : StelProjector(func) {;}
virtual QString getNameI18() const; virtual QString getNameI18() const;
virtual QString getDescriptionI18() const; virtual QString getDescriptionI18() const;
virtual float getMaxFov() const {return 180.00001f;} virtual float getMaxFov() const {return 180.00001f;}
bool forward(Vec3f &v) const bool forward(Vec3f &v) const
 End of changes. 6 change blocks. 
199 lines changed or deleted 4 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/