3
* Copyright (C) 2003 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "StelTranslator.hpp"
22
#include "StelProjector.hpp"
23
#include "StelProjectorClasses.hpp"
29
const QString StelProjector::maskTypeToString(StelProjectorMaskType type)
31
if (type == MaskDisk )
37
StelProjector::StelProjectorMaskType StelProjector::stringToMaskType(const QString &s)
44
void StelProjector::init(const StelProjectorParams& params)
46
maskType = (StelProjectorMaskType)params.maskType;
48
oneOverZNearMinusZFar = 1./(zNear-params.zFar);
49
viewportXywh = params.viewportXywh;
50
viewportCenter = params.viewportCenter;
51
gravityLabels = params.gravityLabels;
52
flipHorz = params.flipHorz ? -1. : 1.;
53
flipVert = params.flipVert ? -1. : 1.;
54
viewportFovDiameter = params.viewportFovDiameter;
55
pixelPerRad = 0.5 * viewportFovDiameter / fovToViewScalingFactor(params.fov*(M_PI/360.0));
56
//Q_ASSERT(params.fov<=getMaxFov());
59
QString StelProjector::getHtmlSummary() const
61
return QString("<h3>%1</h3><p>%2</p><b>%3</b>%4").arg(getNameI18()).arg(getDescriptionI18()).arg(q_("Maximum FOV: ")).arg(getMaxFov())+QChar(0x00B0);
64
/*************************************************************************
65
Return a convex polygon on the sphere which includes the viewport in the
67
*************************************************************************/
68
StelGeom::ConvexPolygon StelProjector::getViewportConvexPolygon(double marginX, double marginY) const
71
bool ok = unProject(0-marginX,0-marginY,e0);
72
ok &= unProject(getViewportWidth()+marginX,0-marginY,e1);
73
ok &= unProject(getViewportWidth()+marginX,getViewportHeight()+marginY,e2);
74
ok &= unProject(0-marginX,getViewportHeight()+marginY,e3);
77
// Special case for handling degenerated cases, use full sky.
79
return StelGeom::ConvexPolygon::fullSky();
85
StelGeom::ConvexPolygon res = needGlFrontFaceCW() ? StelGeom::ConvexPolygon(e1, e0, e3, e2) : StelGeom::ConvexPolygon(e0, e1, e2, e3);
88
//qDebug() << "!valid";
89
return StelGeom::ConvexPolygon::fullSky();
93
// Return a Halfspace containing the whole viewport
94
StelGeom::HalfSpace StelProjector::getBoundingHalfSpace() const
96
StelGeom::HalfSpace result;
98
bool ok = unProject(viewportXywh[0]+0.5*viewportXywh[2], viewportXywh[1]+0.5*viewportXywh[3], result.n);
99
Q_ASSERT(ok); // The central point should be at a valid position by definition
101
// Now need to determine the aperture
102
Vec3d e0,e1,e2,e3,e4,e5;
103
const Vec4i& vp = viewportXywh;
104
ok &= unProject(vp[0],vp[1],e0);
105
ok &= unProject(vp[0]+vp[2],vp[1],e1);
106
ok &= unProject(vp[0]+vp[2],vp[1]+vp[3],e2);
107
ok &= unProject(vp[0],vp[1]+vp[3],e3);
108
ok &= unProject(vp[0],vp[1]+vp[3]/2,e4);
109
ok &= unProject(vp[0]+vp[2],vp[1]+vp[3]/2,e5);
112
// Some points were in invalid positions
116
result.d = result.n*e0;
117
double h = result.n*e1;
135
/*************************************************************************
136
Project the vector v from the viewport frame into the current frame
137
*************************************************************************/
138
bool StelProjector::unProject(double x, double y, Vec3d &v) const
140
v[0] = flipHorz * (x - viewportCenter[0]) / pixelPerRad;
141
v[1] = flipVert * (y - viewportCenter[1]) / pixelPerRad;
143
const bool rval = backward(v);
144
// Even when the reprojected point comes from a region of the screen,
145
// where nothing is projected to (rval=false), we finish reprojecting.
146
// This looks good for atmosphere rendering, and it helps avoiding
147
// discontinuities when dragging around with the mouse.
149
// We need no matrix inversion because we always work with orthogonal matrices (where the transposed is the inverse).
150
//v.transfo4d(inverseModelViewMatrix);
151
x = v[0] - modelViewMatrix.r[12];
152
y = v[1] - modelViewMatrix.r[13];
153
const double z = v[2] - modelViewMatrix.r[14];
154
v[0] = modelViewMatrix.r[0]*x + modelViewMatrix.r[1]*y + modelViewMatrix.r[2]*z;
155
v[1] = modelViewMatrix.r[4]*x + modelViewMatrix.r[5]*y + modelViewMatrix.r[6]*z;
156
v[2] = modelViewMatrix.r[8]*x + modelViewMatrix.r[9]*y + modelViewMatrix.r[10]*z;