From aba69e149baf955135c0ef1a03c6890305ca7f79 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Nov 2024 15:45:08 +0000 Subject: [PATCH] Changed CoordinateFrame::orign and ViewMatrix::origin back to dvec3 to avoid odd crash when writing to ViewMatrix instances. --- include/vsg/app/ViewMatrix.h | 19 +++++++++++-------- include/vsg/nodes/CoordinateFrame.h | 2 +- src/vsg/app/ViewMatrix.cpp | 24 +++++++++++++++++++----- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/include/vsg/app/ViewMatrix.h b/include/vsg/app/ViewMatrix.h index 6ad22af99..7d974e128 100644 --- a/include/vsg/app/ViewMatrix.h +++ b/include/vsg/app/ViewMatrix.h @@ -34,14 +34,17 @@ namespace vsg /// origin value provides a means of translating the view matrix relative to the origin of any CoordinateFrame subgraphs /// to maximize the precision when moving around the CoordinateFrame subgraph. This is helpful for astronmically large /// scenes where standrd double precision is insufficient for avoiding visually significant numerical errors. - ldvec3 origin; + dvec3 origin; - virtual dmat4 transform(const vsg::ldvec3& offset = {}) const = 0; + virtual dmat4 transform(const dvec3& offset = {}) const = 0; - virtual dmat4 inverse(const vsg::ldvec3& offset = {}) const + virtual dmat4 inverse(const dvec3& offset = {}) const { return vsg::inverse(transform(offset)); } + + void read(Input& input) override; + void write(Output& output) const override; }; VSG_type_name(vsg::ViewMatrix); @@ -88,7 +91,7 @@ namespace vsg void set(const dmat4& matrix); - dmat4 transform(const ldvec3& offset = {}) const override; + dmat4 transform(const dvec3& offset = {}) const override; void read(Input& input) override; void write(Output& output) const override; @@ -123,7 +126,7 @@ namespace vsg void set(const dmat4& matrix); - dmat4 transform(const ldvec3& offset = {}) const override; + dmat4 transform(const dvec3& offset = {}) const override; }; VSG_type_name(vsg::LookDirection); @@ -138,7 +141,7 @@ namespace vsg } /// returns matrix * viewMatrix->transform() - dmat4 transform(const ldvec3& offset = {}) const override; + dmat4 transform(const dvec3& offset = {}) const override; dmat4 matrix; ref_ptr viewMatrix; @@ -161,8 +164,8 @@ namespace vsg objectPath(path.begin(), path.end()) {} /// returns matrix * computeTransfrom(objectPath) - dmat4 transform(const ldvec3& offset = {}) const override; - dmat4 inverse(const ldvec3& offset = {}) const override; + dmat4 transform(const dvec3& offset = {}) const override; + dmat4 inverse(const dvec3& offset = {}) const override; dmat4 matrix; RefObjectPath objectPath; diff --git a/include/vsg/nodes/CoordinateFrame.h b/include/vsg/nodes/CoordinateFrame.h index e30c9a2df..36fef0cec 100644 --- a/include/vsg/nodes/CoordinateFrame.h +++ b/include/vsg/nodes/CoordinateFrame.h @@ -25,7 +25,7 @@ namespace vsg CoordinateFrame(const CoordinateFrame& rhs, const CopyOp& copyop = {}); std::string name; - ldvec3 origin; + dvec3 origin; dmat4 transform(const dmat4& mv) const override; diff --git a/src/vsg/app/ViewMatrix.cpp b/src/vsg/app/ViewMatrix.cpp index 9f80d55fb..e5d2548c2 100644 --- a/src/vsg/app/ViewMatrix.cpp +++ b/src/vsg/app/ViewMatrix.cpp @@ -16,6 +16,20 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; +void ViewMatrix::read(Input& input) +{ + Object::read(input); + + input.read("origin", origin); +} + +void ViewMatrix::write(Output& output) const +{ + Object::write(output); + + output.write("origin", origin); +} + void LookAt::read(Input& input) { ViewMatrix::read(input); @@ -48,7 +62,7 @@ void LookAt::set(const dmat4& matrix) eye = matrix * dvec3(0.0, 0.0, 0.0); } -dmat4 LookAt::transform(const ldvec3& offset) const +dmat4 LookAt::transform(const dvec3& offset) const { dvec3 delta = dvec3(origin - offset); return vsg::lookAt(eye + delta, center + delta, up); @@ -60,22 +74,22 @@ void LookDirection::set(const dmat4& matrix) vsg::decompose(matrix, position, rotation, scale); } -dmat4 LookDirection::transform(const ldvec3& offset) const +dmat4 LookDirection::transform(const dvec3& offset) const { return vsg::rotate(-rotation) * vsg::translate(dvec3(offset - origin) - position); } -dmat4 RelativeViewMatrix::transform(const ldvec3& offset) const +dmat4 RelativeViewMatrix::transform(const dvec3& offset) const { return matrix * viewMatrix->transform(offset); } -dmat4 TrackingViewMatrix::transform(const ldvec3& offset) const +dmat4 TrackingViewMatrix::transform(const dvec3& offset) const { return matrix * vsg::translate(dvec3(offset - origin)) * vsg::inverse(computeTransform(objectPath)); } -dmat4 TrackingViewMatrix::inverse(const ldvec3& offset) const +dmat4 TrackingViewMatrix::inverse(const dvec3& offset) const { return vsg::computeTransform(objectPath) * vsg::translate(dvec3(offset - origin)) * vsg::inverse(matrix); }