Skip to content

Commit

Permalink
Added long double support
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Nov 21, 2024
1 parent e24a0b4 commit 2dda950
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
16 changes: 8 additions & 8 deletions include/vsg/app/ViewMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ 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.
dvec3 origin;
ldvec3 origin;

virtual dmat4 transform(const vsg::dvec3& offset = {}) const = 0;
virtual dmat4 transform(const vsg::ldvec3& offset = {}) const = 0;

virtual dmat4 inverse(const vsg::dvec3& offset = {}) const
virtual dmat4 inverse(const vsg::ldvec3& offset = {}) const
{
return vsg::inverse(transform(offset));
}
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace vsg

void set(const dmat4& matrix);

dmat4 transform(const dvec3& offset = {}) const override;
dmat4 transform(const ldvec3& offset = {}) const override;

void read(Input& input) override;
void write(Output& output) const override;
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace vsg

void set(const dmat4& matrix);

dmat4 transform(const dvec3& offset = {}) const override;
dmat4 transform(const ldvec3& offset = {}) const override;
};
VSG_type_name(vsg::LookDirection);

Expand All @@ -138,7 +138,7 @@ namespace vsg
}

/// returns matrix * viewMatrix->transform()
dmat4 transform(const vsg::dvec3& offset = {}) const override;
dmat4 transform(const ldvec3& offset = {}) const override;

dmat4 matrix;
ref_ptr<ViewMatrix> viewMatrix;
Expand All @@ -161,8 +161,8 @@ namespace vsg
objectPath(path.begin(), path.end()) {}

/// returns matrix * computeTransfrom(objectPath)
dmat4 transform(const vsg::dvec3& offset = {}) const override;
dmat4 inverse(const vsg::dvec3& offset = {}) const override;
dmat4 transform(const ldvec3& offset = {}) const override;
dmat4 inverse(const ldvec3& offset = {}) const override;

dmat4 matrix;
RefObjectPath objectPath;
Expand Down
1 change: 1 addition & 0 deletions include/vsg/io/AsciiInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace vsg
void read(size_t num, uint64_t* value) override { _read(num, value); }
void read(size_t num, float* value) override { _read(num, value); }
void read(size_t num, double* value) override { _read(num, value); }
void read(size_t num, long double* value) override { _read(num, value); }

// read in an individual string
void _read(std::string& value);
Expand Down
6 changes: 6 additions & 0 deletions include/vsg/io/AsciiOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ namespace vsg
_output.precision(double_precision);
_write_real(num, value);
}
void write(size_t num, const long double* value) override
{
_output.precision(long_double_precision);
_write_real(num, value);
}

void _write(const std::string& str)
{
Expand All @@ -161,6 +166,7 @@ namespace vsg

int float_precision = 6;
int double_precision = 12;
int long_double_precision = 24;

protected:
std::ostream& _output;
Expand Down
1 change: 1 addition & 0 deletions include/vsg/io/BinaryInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace vsg
void read(size_t num, uint64_t* value) override { _read(num, value); }
void read(size_t num, float* value) override { _read(num, value); }
void read(size_t num, double* value) override { _read(num, value); }
void read(size_t num, long double* value) override { _read(num, value); }

// read in an individual string
void _read(std::string& value);
Expand Down
1 change: 1 addition & 0 deletions include/vsg/io/BinaryOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace vsg
void write(size_t num, const uint64_t* value) override { _write(num, value); }
void write(size_t num, const float* value) override { _write(num, value); }
void write(size_t num, const double* value) override { _write(num, value); }
void write(size_t num, const long double* value) override { _write(num, value); }

void _write(const std::string& str);
void _write(const std::wstring& str);
Expand Down
4 changes: 4 additions & 0 deletions include/vsg/io/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace vsg
virtual void read(size_t num, uint64_t* value) = 0;
virtual void read(size_t num, float* value) = 0;
virtual void read(size_t num, double* value) = 0;
virtual void read(size_t num, long double* value) = 0;
virtual void read(size_t num, std::string* value) = 0;
virtual void read(size_t num, std::wstring* value) = 0;
virtual void read(size_t num, Path* value) = 0;
Expand All @@ -78,6 +79,9 @@ namespace vsg
void read(size_t num, vec4* value) { read(num * value->size(), value->data()); }
void read(size_t num, dvec2* value) { read(num * value->size(), value->data()); }
void read(size_t num, dvec3* value) { read(num * value->size(), value->data()); }
void read(size_t num, ldvec4* value) { read(num * value->size(), value->data()); }
void read(size_t num, ldvec2* value) { read(num * value->size(), value->data()); }
void read(size_t num, ldvec3* value) { read(num * value->size(), value->data()); }
void read(size_t num, dvec4* value) { read(num * value->size(), value->data()); }
void read(size_t num, bvec2* value) { read(num * value->size(), value->data()); }
void read(size_t num, bvec3* value) { read(num * value->size(), value->data()); }
Expand Down
4 changes: 4 additions & 0 deletions include/vsg/io/Output.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace vsg
virtual void write(size_t num, const uint64_t* value) = 0;
virtual void write(size_t num, const float* value) = 0;
virtual void write(size_t num, const double* value) = 0;
virtual void write(size_t num, const long double* value) = 0;
virtual void write(size_t num, const std::string* value) = 0;
virtual void write(size_t num, const std::wstring* value) = 0;
virtual void write(size_t num, const Path* value) = 0;
Expand All @@ -79,6 +80,9 @@ namespace vsg
void write(size_t num, const dvec2* value) { write(num * value->size(), value->data()); }
void write(size_t num, const dvec3* value) { write(num * value->size(), value->data()); }
void write(size_t num, const dvec4* value) { write(num * value->size(), value->data()); }
void write(size_t num, const ldvec2* value) { write(num * value->size(), value->data()); }
void write(size_t num, const ldvec3* value) { write(num * value->size(), value->data()); }
void write(size_t num, const ldvec4* value) { write(num * value->size(), value->data()); }
void write(size_t num, const bvec2* value) { write(num * value->size(), value->data()); }
void write(size_t num, const bvec3* value) { write(num * value->size(), value->data()); }
void write(size_t num, const bvec4* value) { write(num * value->size(), value->data()); }
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;
dvec3 origin;
ldvec3 origin;

dmat4 transform(const dmat4& mv) const override;

Expand Down
18 changes: 9 additions & 9 deletions src/vsg/app/ViewMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ void LookAt::set(const dmat4& matrix)
eye = matrix * dvec3(0.0, 0.0, 0.0);
}

dmat4 LookAt::transform(const dvec3& offset) const
dmat4 LookAt::transform(const ldvec3& offset) const
{
dvec3 delta = origin - offset;
dvec3 delta = dvec3(origin - offset);
return vsg::lookAt(eye + delta, center + delta, up);
}

Expand All @@ -60,22 +60,22 @@ void LookDirection::set(const dmat4& matrix)
vsg::decompose(matrix, position, rotation, scale);
}

dmat4 LookDirection::transform(const dvec3& offset) const
dmat4 LookDirection::transform(const ldvec3& offset) const
{
return vsg::rotate(-rotation) * vsg::translate(offset - origin - position);
return vsg::rotate(-rotation) * vsg::translate(dvec3(origin - offset) - position);
}

dmat4 RelativeViewMatrix::transform(const dvec3& offset) const
dmat4 RelativeViewMatrix::transform(const ldvec3& offset) const
{
return matrix * viewMatrix->transform(offset);
}

dmat4 TrackingViewMatrix::transform(const dvec3& offset) const
dmat4 TrackingViewMatrix::transform(const ldvec3& offset) const
{
return matrix * vsg::translate(offset - origin) * vsg::inverse(computeTransform(objectPath));
return matrix * vsg::translate(dvec3(origin - offset)) * vsg::inverse(computeTransform(objectPath));
}

dmat4 TrackingViewMatrix::inverse(const dvec3& offset) const
dmat4 TrackingViewMatrix::inverse(const ldvec3& offset) const
{
return vsg::computeTransform(objectPath) * vsg::translate(origin - offset) * vsg::inverse(matrix);
return vsg::computeTransform(objectPath) * vsg::translate(dvec3(origin - offset)) * vsg::inverse(matrix);
}
2 changes: 1 addition & 1 deletion src/vsg/nodes/CoordinateFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ void CoordinateFrame::write(Output& output) const

dmat4 CoordinateFrame::transform(const dmat4& mv) const
{
return mv * translate(origin);
return mv * translate(dvec3(origin));
}

0 comments on commit 2dda950

Please sign in to comment.