15 #include <vsg/app/EllipsoidModel.h>
16 #include <vsg/app/ViewMatrix.h>
17 #include <vsg/io/Logger.h>
26 virtual dmat4 transform()
const = 0;
28 virtual dmat4 inverse()
const
30 return vsg::inverse(transform());
33 virtual void changeExtent(
const VkExtent2D& ,
const VkExtent2D& )
51 Perspective(
double fov,
double ar,
double nd,
double fd) :
59 dmat4 transform()
const override {
return perspective(radians(fieldOfViewY), aspectRatio, nearDistance, farDistance); }
61 void changeExtent(
const VkExtent2D&,
const VkExtent2D& newExtent)
override
63 aspectRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
66 void read(
Input& input)
override;
67 void write(
Output& output)
const override;
90 Orthographic(
double l,
double r,
double b,
double t,
double nd,
double fd) :
100 dmat4 transform()
const override {
return orthographic(left, right, bottom, top, nearDistance, farDistance); }
102 void changeExtent(
const VkExtent2D& prevExtent,
const VkExtent2D& newExtent)
override
104 double oldRatio =
static_cast<double>(prevExtent.width) /
static_cast<double>(prevExtent.height);
105 double newRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
106 left *= newRatio / oldRatio;
107 right *= newRatio / oldRatio;
124 projectionMatrix(pm),
132 return matrix * projectionMatrix->transform();
135 void changeExtent(
const VkExtent2D& prevExtent,
const VkExtent2D& newExtent)
override
137 double oldRatio =
static_cast<double>(prevExtent.width) /
static_cast<double>(prevExtent.height);
138 double newRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
139 matrix = scale(oldRatio / newRatio, 1.0, 1.0) * matrix;
141 ref_ptr<ProjectionMatrix> projectionMatrix;
156 nearFarRatio(0.0001),
157 horizonMountainHeight(1000.0)
167 horizonMountainHeight(hmh)
171 dmat4 transform()
const override
175 vsg::dvec3 lv = vsg::normalize(lookAt->center - lookAt->eye);
176 double R = ellipsoidModel->radiusEquator();
177 double H = ellipsoidModel->convertECEFToLatLongAltitude(v).z;
180 double alpha = (D > R) ? std::acos(R / D) : 0.0;
182 double beta_ratio = R / (R + horizonMountainHeight);
183 double beta = beta_ratio < 1.0 ? std::acos(beta_ratio) : 0.0;
185 double theta_ratio = -vsg::dot(lv, v) / (vsg::length(lv) * vsg::length(v));
186 double theta = theta_ratio < 1.0 ? std::acos(theta_ratio) : 0.0;
188 double l = R * (std::tan(alpha) + std::tan(beta));
190 double farDistance = std::cos(theta + alpha - vsg::PI * 0.5) * l;
191 double nearDistance = farDistance * nearFarRatio;
194 return perspective(radians(fieldOfViewY), aspectRatio, nearDistance, farDistance);
197 void changeExtent(
const VkExtent2D& prevExtent,
const VkExtent2D& newExtent)
override
199 double oldRatio =
static_cast<double>(prevExtent.width) /
static_cast<double>(prevExtent.height);
200 double newRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
202 aspectRatio *= (newRatio / oldRatio);
211 double horizonMountainHeight;
Definition: ProjectionMatrix.h:149
Orthographic is a ProjectionMatrix that implements the glOrtho model for setting the projection matri...
Definition: ProjectionMatrix.h:78
Perspective is a ProjectionMatrix that implements the gluPerspective model for setting the projection...
Definition: ProjectionMatrix.h:41
ProjectionMatrix is a base class for specifying the Camera projection matrix and its inverse.
Definition: ProjectionMatrix.h:24
RelativeProjection is a ProjectionMatrix that decorates another ProjectionMatrix and pre-multiplies i...
Definition: ProjectionMatrix.h:121
dmat4 transform() const override
returns matrix * projectionMatrix->transform()
Definition: ProjectionMatrix.h:130