From 0dff8a6618cc3f00353dee93de4f62b0a99d661a Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 7 Aug 2020 13:06:06 +0200 Subject: [PATCH] Base: [skip ci] add class ViewOrthoProjMatrix for orthogonal projections in 3d --- src/Base/ViewProj.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/Base/ViewProj.h | 23 +++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/Base/ViewProj.cpp b/src/Base/ViewProj.cpp index bf13085f2072..a5f485713af7 100644 --- a/src/Base/ViewProj.cpp +++ b/src/Base/ViewProj.cpp @@ -191,3 +191,41 @@ Vector3d ViewProjMatrix::inverse (const Vector3d& src) const return dst; } + +// ---------------------------------------------------------------------------- + +ViewOrthoProjMatrix::ViewOrthoProjMatrix (const Matrix4D &rclMtx) + : _clMtx(rclMtx) +{ + _clMtxInv = _clMtx; + _clMtxInv.inverse(); +} + +ViewOrthoProjMatrix::~ViewOrthoProjMatrix() +{ +} + +Matrix4D ViewOrthoProjMatrix::getProjectionMatrix (void) const +{ + return _clMtx; +} + +Vector3f ViewOrthoProjMatrix::operator()(const Vector3f &rclPt) const +{ + return Vector3f(_clMtx * rclPt); +} + +Vector3d ViewOrthoProjMatrix::operator()(const Vector3d &rclPt) const +{ + return Vector3d(_clMtx * rclPt); +} + +Vector3f ViewOrthoProjMatrix::inverse (const Vector3f &rclPt) const +{ + return Vector3f(_clMtxInv * rclPt); +} + +Vector3d ViewOrthoProjMatrix::inverse (const Vector3d &rclPt) const +{ + return Vector3d(_clMtxInv * rclPt); +} diff --git a/src/Base/ViewProj.h b/src/Base/ViewProj.h index c0e5935fbda4..15faaf6374c7 100644 --- a/src/Base/ViewProj.h +++ b/src/Base/ViewProj.h @@ -88,6 +88,29 @@ class BaseExport ViewProjMatrix : public ViewProjMethod Matrix4D _clMtx, _clMtxInv; }; +/** + * The ViewOrthoProjMatrix class returns the result of the multiplication + * of the 3D vector and the transformation matrix. + * Unlike ViewProjMatrix this class is not supposed to project points onto + * a viewport but project points onto a plane in 3D. + */ +class BaseExport ViewOrthoProjMatrix : public ViewProjMethod +{ +public: + ViewOrthoProjMatrix (const Matrix4D &rclMtx); + virtual ~ViewOrthoProjMatrix(); + + Vector3f operator()(const Vector3f &rclPt) const; + Vector3d operator()(const Vector3d &rclPt) const; + Vector3f inverse (const Vector3f &rclPt) const; + Vector3d inverse (const Vector3d &rclPt) const; + + Matrix4D getProjectionMatrix (void) const; + +protected: + Matrix4D _clMtx, _clMtxInv; +}; + } // namespace Base #endif // BASE_VIEWPROJ_H