From d15ad700445d9491d324e69480498ef0ae2ce43d Mon Sep 17 00:00:00 2001 From: Michael Saunders Date: Fri, 11 Oct 2024 10:06:40 -0700 Subject: [PATCH] Added copy constructors and clone method implementations for LookAt view matrix and Perspective, and Orthographic projections --- include/vsg/app/ProjectionMatrix.h | 33 ++++++++++++++++++++++++++++++ include/vsg/app/ViewMatrix.h | 15 ++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/vsg/app/ProjectionMatrix.h b/include/vsg/app/ProjectionMatrix.h index f08581d22..5833a71da 100644 --- a/include/vsg/app/ProjectionMatrix.h +++ b/include/vsg/app/ProjectionMatrix.h @@ -23,6 +23,15 @@ namespace vsg class VSG_DECLSPEC ProjectionMatrix : public Inherit { public: + ProjectionMatrix() + { + } + + explicit ProjectionMatrix(const ProjectionMatrix& pm, const CopyOp& copyop = {}) : + Inherit(pm, copyop) + { + } + virtual dmat4 transform() const = 0; virtual dmat4 inverse() const @@ -48,6 +57,15 @@ namespace vsg { } + explicit Perspective(const Perspective& p, const CopyOp& copyop = {}) : + Inherit(p, copyop), + fieldOfViewY(p.fieldOfViewY), + aspectRatio(p.aspectRatio), + nearDistance(p.nearDistance), + farDistance(p.farDistance) + { + } + Perspective(double fov, double ar, double nd, double fd) : fieldOfViewY(fov), aspectRatio(ar), @@ -56,6 +74,8 @@ namespace vsg { } + ref_ptr clone(const CopyOp& copyop = {}) const override { return Perspective::create(*this, copyop); } + dmat4 transform() const override { return perspective(radians(fieldOfViewY), aspectRatio, nearDistance, farDistance); } void changeExtent(const VkExtent2D& prevExtent, const VkExtent2D& newExtent) override @@ -91,6 +111,17 @@ namespace vsg { } + explicit Orthographic(const Orthographic& o, const CopyOp& copyop = {}) : + Inherit(o, copyop), + left(o.left), + right(o.right), + bottom(o.bottom), + top(o.top), + nearDistance(o.nearDistance), + farDistance(o.farDistance) + { + } + Orthographic(double l, double r, double b, double t, double nd, double fd) : left(l), right(r), @@ -101,6 +132,8 @@ namespace vsg { } + ref_ptr clone(const CopyOp& copyop = {}) const override { return Orthographic::create(*this, copyop); } + dmat4 transform() const override { return orthographic(left, right, bottom, top, nearDistance, farDistance); } void changeExtent(const VkExtent2D& prevExtent, const VkExtent2D& newExtent) override diff --git a/include/vsg/app/ViewMatrix.h b/include/vsg/app/ViewMatrix.h index 91dddab79..c026aaca0 100644 --- a/include/vsg/app/ViewMatrix.h +++ b/include/vsg/app/ViewMatrix.h @@ -22,6 +22,15 @@ namespace vsg class VSG_DECLSPEC ViewMatrix : public Inherit { public: + ViewMatrix() + { + } + + explicit ViewMatrix(const ViewMatrix& vm, const CopyOp& copyop = {}) : + Inherit(vm, copyop) + { + } + virtual dmat4 transform() const = 0; virtual dmat4 inverse() const @@ -42,8 +51,8 @@ namespace vsg { } - LookAt(const LookAt& lookAt) : - Inherit(lookAt), + LookAt(const LookAt& lookAt, const CopyOp& copyop = {}) : + Inherit(lookAt, copyop), eye(lookAt.eye), center(lookAt.center), up(lookAt.up) @@ -68,6 +77,8 @@ namespace vsg return *this; } + ref_ptr clone(const CopyOp& copyop = {}) const override { return LookAt::create(*this, copyop); } + void transform(const dmat4& matrix) { up = normalize(matrix * (eye + up) - matrix * eye);