23#ifndef VCL_SPACE_CORE_CAMERA_H
24#define VCL_SPACE_CORE_CAMERA_H
26#include "camera/matrix.h"
35template<
typename Scalar>
39 using ScalarType = Scalar;
43 enum class ProjectionMode { ORTHO, PERSPECTIVE };
94 void reset() { *
this = {}; }
96 PointType& center() {
return mCenter; }
98 const PointType& center()
const {
return mCenter; }
100 PointType& eye() {
return mEye; }
102 const PointType& eye()
const {
return mEye; }
104 PointType& up() {
return mUp; }
106 const PointType& up()
const {
return mUp; }
108 Scalar& fieldOfView() {
return mFovDeg; }
110 const Scalar& fieldOfView()
const {
return mFovDeg; }
112 void setFieldOfViewAdaptingEyeDistance(
const Scalar& fovDeg)
115 PointType targetToEye = (
mEye -
mCenter).normalized();
118 std::tan((fovDeg / 2.0) / 180.0 * M_PI));
129 Scalar& aspectRatio() {
return mAspect; }
131 const Scalar& aspectRatio()
const {
return mAspect; }
133 Scalar& nearPlane() {
return mNear; }
135 const Scalar& nearPlane()
const {
return mNear; }
137 Scalar& farPlane() {
return mFar; }
139 const Scalar& farPlane()
const {
return mFar; }
141 MatrixType viewMatrix()
const
148 MatrixType projectionMatrix()
const
152 case ProjectionMode::ORTHO: {
155 detail::orthoProjectionMatrix(
156 res.data(), -w, w, h, -h,
mNear,
mFar,
false);
159 case ProjectionMode::PERSPECTIVE: {
160 detail::projectionMatrix(
195 mEye.deserialize(is);
209using Cameraf = Camera<float>;
241 std::remove_cvref_t<T>,
242 Camera<typename RemoveRef<T>::ScalarType>>;
A Pinhole camera model.
Definition camera.h:37
Scalar mNear
Z position of the mNear plane.
Definition camera.h:86
Scalar mVerticalHeight
Height of the target in world space (used for ortho projection, and adapting the eye distance for per...
Definition camera.h:80
Scalar mFovDeg
Field of view in degrees.
Definition camera.h:60
void serialize(std::ostream &os) const
Serializes the camera to the given output stream.
Definition camera.h:173
ProjectionMode mProjectionMode
Projection mode.
Definition camera.h:63
PointType mCenter
Position where the camera is looking at (i.e. target point)
Definition camera.h:49
void deserialize(std::istream &is)
Deserializes the camera from the given input stream.
Definition camera.h:192
Scalar mFar
Z position of the mFar plane.
Definition camera.h:89
PointType mUp
Up direction of the camera.
Definition camera.h:55
Scalar mAspect
Aspect ratio.
Definition camera.h:83
PointType mEye
Position of (eye of) the camera.
Definition camera.h:52
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
Segment()
Default constructor. Creates a segment with endpoints at the origin.
Definition segment.h:66
A concept representing a Camera.
Definition camera.h:240
A concept representing a generic Camera.
Definition camera.h:224
Concept for 4x4 matrices.
Definition matrix.h:62