49 class VSG_DECLSPEC Perspective :
public Inherit<ProjectionMatrix, Perspective>
60 explicit Perspective(
const Perspective& p,
const CopyOp& copyop = {}) :
62 fieldOfViewY(p.fieldOfViewY),
63 aspectRatio(p.aspectRatio),
64 nearDistance(p.nearDistance),
65 farDistance(p.farDistance)
69 Perspective(
double fov,
double ar,
double nd,
double fd) :
79 dmat4 transform()
const override {
return perspective(radians(fieldOfViewY), aspectRatio, nearDistance, farDistance); }
81 void changeExtent(
const VkExtent2D& prevExtent,
const VkExtent2D& newExtent)
override
83 double oldRatio =
static_cast<double>(prevExtent.width) /
static_cast<double>(prevExtent.height);
84 double newRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
86 aspectRatio *= (newRatio / oldRatio);
95 void read(Input& input)
override;
96 void write(Output& output)
const override;
101 class VSG_DECLSPEC Orthographic :
public Inherit<ProjectionMatrix, Orthographic>
114 explicit Orthographic(
const Orthographic& o,
const CopyOp& copyop = {}) :
120 nearDistance(o.nearDistance),
121 farDistance(o.farDistance)
125 Orthographic(
double l,
double r,
double b,
double t,
double nd,
double fd) :
137 dmat4 transform()
const override {
return orthographic(left, right, bottom, top, nearDistance, farDistance); }
139 void changeExtent(
const VkExtent2D& prevExtent,
const VkExtent2D& newExtent)
override
141 double oldRatio =
static_cast<double>(prevExtent.width) /
static_cast<double>(prevExtent.height);
142 double newRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
143 left *= newRatio / oldRatio;
144 right *= newRatio / oldRatio;
155 void read(Input& input)
override;
156 void write(Output& output)
const override;
189 class VSG_DECLSPEC EllipsoidPerspective :
public Inherit<ProjectionMatrix, EllipsoidPerspective>
192 EllipsoidPerspective() {}
206 horizonMountainHeight(hmh)
210 dmat4 transform()
const override
213 vsg::dvec3 v = lookAt->eye;
214 vsg::dvec3 lv = vsg::normalize(lookAt->center - lookAt->eye);
215 double R = ellipsoidModel->radiusEquator();
216 double H = ellipsoidModel->convertECEFToLatLongAltitude(v).z;
219 double alpha = (D > R) ? std::acos(R / D) : 0.0;
221 double beta_ratio = R / (R + horizonMountainHeight);
222 double beta = beta_ratio < 1.0 ? std::acos(beta_ratio) : 0.0;
224 double theta_ratio = -vsg::dot(lv, v) / (vsg::length(lv) * vsg::length(v));
225 double theta = theta_ratio < 1.0 ? std::acos(theta_ratio) : 0.0;
227 double l = R * (std::tan(alpha) + std::tan(beta));
229 double farDistance = std::cos(theta + alpha - vsg::PI * 0.5) * l;
230 double nearDistance = farDistance * nearFarRatio;
233 return perspective(radians(fieldOfViewY), aspectRatio, nearDistance, farDistance);
236 void changeExtent(
const VkExtent2D& prevExtent,
const VkExtent2D& newExtent)
override
238 double oldRatio =
static_cast<double>(prevExtent.width) /
static_cast<double>(prevExtent.height);
239 double newRatio =
static_cast<double>(newExtent.width) /
static_cast<double>(newExtent.height);
241 aspectRatio *= (newRatio / oldRatio);
246 double fieldOfViewY = 60.0;
247 double aspectRatio = 1.0;
248 double nearFarRatio = 0.0001;
249 double horizonMountainHeight = 1000.0;
252 void read(
Input& input)
override;
253 void write(
Output& output)
const override;