Skip to content

Commit

Permalink
Changed CoordinateFrame::orign and ViewMatrix::origin back to dvec3 t…
Browse files Browse the repository at this point in the history
…o avoid odd crash when writing to ViewMatrix instances.
  • Loading branch information
robertosfield committed Nov 22, 2024
1 parent 8115551 commit aba69e1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
19 changes: 11 additions & 8 deletions include/vsg/app/ViewMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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> viewMatrix;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/vsg/nodes/CoordinateFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 19 additions & 5 deletions src/vsg/app/ViewMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

0 comments on commit aba69e1

Please sign in to comment.