Skip to content

Commit a7a7db7

Browse files
Merge pull request #1338 from vsg-dev/CoordinateFrame_long_double
vsg::CoordinateFrame and long double support
2 parents dfa2ff5 + cbdc239 commit a7a7db7

34 files changed

+468
-64
lines changed

cmake/cppcheck-suppression-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ shadowFunction:*/src/vsg/state/DescriptorImage.cpp
208208
shadowFunction:*/src/vsg/utils/FindDynamicObjects.cpp
209209
shadowFunction:*/src/vsg/utils/LoadPagedLOD.cpp
210210
shadowFunction:*/src/vsg/utils/PropagateDynamicObjects.cpp
211+
shadowFunction:*/src/vsg/app/ViewMatrix.cpp
211212

212213
// suppress unhelpful warning of c casts
213214
cstyleCast:*/include/vsg/io/mem_stream.h

include/vsg/all.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
6060
#include <vsg/nodes/AbsoluteTransform.h>
6161
#include <vsg/nodes/Bin.h>
6262
#include <vsg/nodes/Compilable.h>
63+
#include <vsg/nodes/CoordinateFrame.h>
6364
#include <vsg/nodes/CullGroup.h>
6465
#include <vsg/nodes/CullNode.h>
6566
#include <vsg/nodes/DepthSorted.h>

include/vsg/app/RecordTraversal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace vsg
3636
class Layer;
3737
class Transform;
3838
class MatrixTransform;
39+
class CoordinateFrame;
3940
class Joint;
4041
class TileDatabase;
4142
class VertexDraw;
@@ -135,6 +136,7 @@ namespace vsg
135136
// transform nodes
136137
void apply(const Transform& transform);
137138
void apply(const MatrixTransform& mt);
139+
void apply(const CoordinateFrame& cf);
138140

139141
// Animation nodes
140142
void apply(const Joint& joint);

include/vsg/app/ViewMatrix.h

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ namespace vsg
3131
{
3232
}
3333

34-
virtual dmat4 transform() const = 0;
34+
/// origin value provides a means of translating the view matrix relative to the origin of any CoordinateFrame subgraphs
35+
/// to maximize the precision when moving around the CoordinateFrame subgraph. This is helpful for astronmically large
36+
/// scenes where standrd double precision is insufficient for avoiding visually significant numerical errors.
37+
dvec3 origin;
3538

36-
virtual dmat4 inverse() const
39+
virtual dmat4 transform(const dvec3& offset = {}) const = 0;
40+
41+
virtual dmat4 inverse(const dvec3& offset = {}) const
3742
{
38-
return vsg::inverse(transform());
43+
return vsg::inverse(transform(offset));
3944
}
45+
46+
void read(Input& input) override;
47+
void write(Output& output) const override;
4048
};
4149
VSG_type_name(vsg::ViewMatrix);
4250

@@ -79,21 +87,11 @@ namespace vsg
7987

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

82-
void transform(const dmat4& matrix)
83-
{
84-
up = normalize(matrix * (eye + up) - matrix * eye);
85-
center = matrix * center;
86-
eye = matrix * eye;
87-
}
90+
void transform(const dmat4& matrix);
8891

89-
void set(const dmat4& matrix)
90-
{
91-
up = normalize(matrix * (dvec3(0.0, 0.0, 0.0) + dvec3(0.0, 1.0, 0.0)) - matrix * dvec3(0.0, 0.0, 0.0));
92-
center = matrix * dvec3(0.0, 0.0, -1.0);
93-
eye = matrix * dvec3(0.0, 0.0, 0.0);
94-
}
92+
void set(const dmat4& matrix);
9593

96-
dmat4 transform() const override { return lookAt(eye, center, up); }
94+
dmat4 transform(const dvec3& offset = {}) const override;
9795

9896
void read(Input& input) override;
9997
void write(Output& output) const override;
@@ -104,8 +102,36 @@ namespace vsg
104102
};
105103
VSG_type_name(vsg::LookAt);
106104

105+
/// LookDirection is a ViewMatrix that uses a position and rotation to set the view matrix.
106+
class VSG_DECLSPEC LookDirection : public vsg::Inherit<ViewMatrix, LookDirection>
107+
{
108+
public:
109+
LookDirection() :
110+
position(0.0, 0.0, 0.0),
111+
rotation()
112+
{
113+
}
114+
115+
LookDirection(const LookDirection& view, const CopyOp& copyop = {}) :
116+
Inherit(view, copyop),
117+
position(view.position),
118+
rotation(view.rotation)
119+
{
120+
}
121+
122+
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return LookDirection::create(*this, copyop); }
123+
124+
dvec3 position;
125+
dquat rotation;
126+
127+
void set(const dmat4& matrix);
128+
129+
dmat4 transform(const dvec3& offset = {}) const override;
130+
};
131+
VSG_type_name(vsg::LookDirection);
132+
107133
/// RelativeViewMatrix is a ViewMatrix that decorates another ViewMatrix and pre-multiplies its transform matrix to give a relative view matrix.
108-
class RelativeViewMatrix : public Inherit<ViewMatrix, RelativeViewMatrix>
134+
class VSG_DECLSPEC RelativeViewMatrix : public Inherit<ViewMatrix, RelativeViewMatrix>
109135
{
110136
public:
111137
RelativeViewMatrix(const dmat4& m, ref_ptr<ViewMatrix> vm) :
@@ -115,10 +141,7 @@ namespace vsg
115141
}
116142

117143
/// returns matrix * viewMatrix->transform()
118-
dmat4 transform() const override
119-
{
120-
return matrix * viewMatrix->transform();
121-
}
144+
dmat4 transform(const dvec3& offset = {}) const override;
122145

123146
dmat4 matrix;
124147
ref_ptr<ViewMatrix> viewMatrix;
@@ -141,8 +164,8 @@ namespace vsg
141164
objectPath(path.begin(), path.end()) {}
142165

143166
/// returns matrix * computeTransfrom(objectPath)
144-
dmat4 transform() const override;
145-
dmat4 inverse() const override;
167+
dmat4 transform(const dvec3& offset = {}) const override;
168+
dmat4 inverse(const dvec3& offset = {}) const override;
146169

147170
dmat4 matrix;
148171
RefObjectPath objectPath;

include/vsg/core/ConstVisitor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ namespace vsg
3434
class StateGroup;
3535
class CullGroup;
3636
class CullNode;
37-
class MatrixTransform;
3837
class Transform;
38+
class MatrixTransform;
39+
class CoordinateFrame;
3940
class Geometry;
4041
class VertexDraw;
4142
class VertexIndexDraw;
@@ -323,8 +324,9 @@ namespace vsg
323324
virtual void apply(const StateGroup&);
324325
virtual void apply(const CullGroup&);
325326
virtual void apply(const CullNode&);
326-
virtual void apply(const MatrixTransform&);
327327
virtual void apply(const Transform&);
328+
virtual void apply(const MatrixTransform&);
329+
virtual void apply(const CoordinateFrame&);
328330
virtual void apply(const Geometry&);
329331
virtual void apply(const VertexDraw&);
330332
virtual void apply(const VertexIndexDraw&);

include/vsg/core/Visitor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ namespace vsg
3434
class StateGroup;
3535
class CullGroup;
3636
class CullNode;
37-
class MatrixTransform;
3837
class Transform;
38+
class MatrixTransform;
39+
class CoordinateFrame;
3940
class Geometry;
4041
class VertexDraw;
4142
class VertexIndexDraw;
@@ -323,8 +324,9 @@ namespace vsg
323324
virtual void apply(StateGroup&);
324325
virtual void apply(CullGroup&);
325326
virtual void apply(CullNode&);
326-
virtual void apply(MatrixTransform&);
327327
virtual void apply(Transform&);
328+
virtual void apply(MatrixTransform&);
329+
virtual void apply(CoordinateFrame&);
328330
virtual void apply(Geometry&);
329331
virtual void apply(VertexDraw&);
330332
virtual void apply(VertexIndexDraw&);

include/vsg/io/AsciiInput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace vsg
8585
void read(size_t num, uint64_t* value) override { _read(num, value); }
8686
void read(size_t num, float* value) override { _read(num, value); }
8787
void read(size_t num, double* value) override { _read(num, value); }
88+
void read(size_t num, long double* value) override { _read(num, value); }
8889

8990
// read in an individual string
9091
void _read(std::string& value);

include/vsg/io/AsciiOutput.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ namespace vsg
136136
_output.precision(double_precision);
137137
_write_real(num, value);
138138
}
139+
void write(size_t num, const long double* value) override
140+
{
141+
_output.precision(long_double_precision);
142+
_write_real(num, value);
143+
}
139144

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

162167
int float_precision = 6;
163168
int double_precision = 12;
169+
int long_double_precision = 24;
164170

165171
protected:
166172
std::ostream& _output;

include/vsg/io/BinaryInput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace vsg
5555
void read(size_t num, uint64_t* value) override { _read(num, value); }
5656
void read(size_t num, float* value) override { _read(num, value); }
5757
void read(size_t num, double* value) override { _read(num, value); }
58+
void read(size_t num, long double* value) override;
5859

5960
// read in an individual string
6061
void _read(std::string& value);

include/vsg/io/BinaryOutput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace vsg
5050
void write(size_t num, const uint64_t* value) override { _write(num, value); }
5151
void write(size_t num, const float* value) override { _write(num, value); }
5252
void write(size_t num, const double* value) override { _write(num, value); }
53+
void write(size_t num, const long double* value) override;
5354

5455
void _write(const std::string& str);
5556
void _write(const std::wstring& str);

0 commit comments

Comments
 (0)