Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added copy and clone for view and projection matrix #1299

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions include/vsg/app/ProjectionMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ namespace vsg
class VSG_DECLSPEC ProjectionMatrix : public Inherit<Object, ProjectionMatrix>
{
public:
ProjectionMatrix()
{
}

explicit ProjectionMatrix(const ProjectionMatrix& pm, const CopyOp& copyop = {}) :
Inherit(pm, copyop)
{
}

virtual dmat4 transform() const = 0;

virtual dmat4 inverse() const
Expand All @@ -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),
Expand All @@ -56,6 +74,8 @@ namespace vsg
{
}

ref_ptr<Object> 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
Expand Down Expand Up @@ -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),
Expand All @@ -101,6 +132,8 @@ namespace vsg
{
}

ref_ptr<Object> 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
Expand Down
15 changes: 13 additions & 2 deletions include/vsg/app/ViewMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ namespace vsg
class VSG_DECLSPEC ViewMatrix : public Inherit<Object, ViewMatrix>
{
public:
ViewMatrix()
{
}

explicit ViewMatrix(const ViewMatrix& vm, const CopyOp& copyop = {}) :
Inherit(vm, copyop)
{
}

virtual dmat4 transform() const = 0;

virtual dmat4 inverse() const
Expand All @@ -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)
Expand All @@ -68,6 +77,8 @@ namespace vsg
return *this;
}

ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return LookAt::create(*this, copyop); }

void transform(const dmat4& matrix)
{
up = normalize(matrix * (eye + up) - matrix * eye);
Expand Down
Loading