Skip to content

Commit a9d0a22

Browse files
committed
Added CoordinateFrame a ucoord classes.
1 parent 504ec2d commit a9d0a22

File tree

12 files changed

+287
-4
lines changed

12 files changed

+287
-4
lines changed

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/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/maths/ucoord.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#pragma once
2+
3+
/* <editor-fold desc="MIT License">
4+
5+
Copyright(c) 2018 Robert Osfield
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
13+
</editor-fold> */
14+
15+
// we can't implement the anonymous union/structs combination without causing warnings, so disable them for just this header
16+
#if defined(__GNUC__)
17+
# pragma GCC diagnostic push
18+
# pragma GCC diagnostic ignored "-Wpedantic"
19+
#endif
20+
#if defined(__clang__)
21+
# pragma clang diagnostic push
22+
# pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
23+
# pragma clang diagnostic ignored "-Wnested-anon-types"
24+
#endif
25+
26+
#include <vsg/maths/vec3.h>
27+
28+
namespace vsg
29+
{
30+
31+
/// ucoord class for managing astronomical scale coordinates
32+
struct ucoord
33+
{
34+
using value_type = double;
35+
using vec_type = t_vec3<value_type>;
36+
37+
vec_type origin;
38+
vec_type offset;
39+
40+
constexpr ucoord() {}
41+
42+
constexpr ucoord(const ucoord& uc) = default;
43+
constexpr ucoord(value_type in_x, value_type in_y, value_type in_z) :
44+
origin(0.0, 0.0, 0.0),
45+
offset(in_x, in_y, in_z) {}
46+
template<typename R>
47+
constexpr explicit ucoord(const t_vec3<R>& v) :
48+
origin(0.0, 0.0, 0.0),
49+
offset(static_cast<value_type>(v.x), static_cast<value_type>(v.y), static_cast<value_type>(v.z)) {}
50+
template<typename R>
51+
constexpr ucoord(const t_vec3<R>& in_origin, const t_vec3<R>& in_offset) :
52+
origin(in_origin),
53+
offset(in_offset){}
54+
55+
ucoord& operator=(const ucoord& rhs)
56+
{
57+
origin = rhs.origin;
58+
offset = rhs.offset;
59+
return *this;
60+
}
61+
62+
void set(value_type in_x, value_type in_y, value_type in_z)
63+
{
64+
origin.set(in_x, in_y, in_z);
65+
offset.set(in_x, in_y, in_z);
66+
}
67+
68+
inline ucoord& operator+=(const ucoord& rhs)
69+
{
70+
origin += rhs.origin;
71+
offset += rhs.offset;
72+
return *this;
73+
}
74+
75+
inline ucoord& operator-=(const ucoord& rhs)
76+
{
77+
origin -= rhs.origin;
78+
offset -= rhs.offset;
79+
return *this;
80+
}
81+
82+
explicit operator bool() const noexcept { return origin || offset; }
83+
};
84+
85+
VSG_type_name(vsg::ucoord);
86+
87+
inline constexpr bool operator==(const ucoord& lhs, const ucoord& rhs)
88+
{
89+
return lhs.origin == rhs.origin && lhs.offset == rhs.offset;
90+
}
91+
92+
inline constexpr bool operator!=(const ucoord& lhs, const ucoord& rhs)
93+
{
94+
return lhs.origin != rhs.origin || lhs.offset != rhs.offset;
95+
}
96+
97+
inline bool operator<(const ucoord& lhs, const ucoord& rhs)
98+
{
99+
ucoord::vec_type delta = (rhs.origin-lhs.origin) + (rhs.offset - lhs.offset);
100+
if (delta[0] < 0.0) return true;
101+
if (delta[0] > 0.0) return false;
102+
if (delta[1] < 0.0) return true;
103+
if (delta[1] > 0.0) return false;
104+
return (delta[2] < 0.0);
105+
}
106+
107+
inline constexpr ucoord operator-(const ucoord& lhs, const ucoord& rhs)
108+
{
109+
return ucoord(lhs.origin - rhs.origin, lhs.offset - rhs.offset);
110+
}
111+
112+
inline constexpr ucoord operator+(const ucoord& lhs, const ucoord& rhs)
113+
{
114+
return ucoord(lhs.origin + rhs.origin, lhs.offset + rhs.offset);
115+
}
116+
117+
inline constexpr ucoord::value_type length(const ucoord& uc)
118+
{
119+
return length(uc.origin + uc.offset);
120+
}
121+
122+
inline constexpr ucoord::value_type length2(const ucoord& uc)
123+
{
124+
return length2(uc.origin + uc.offset);
125+
}
126+
127+
constexpr ucoord mix(const ucoord& start, const ucoord& end, ucoord::value_type r)
128+
{
129+
ucoord::value_type one_minus_r = 1.0 - r;
130+
return ucoord(start.origin * one_minus_r + start.origin * r,
131+
start.offset * one_minus_r + end.offset * r);
132+
}
133+
134+
135+
} // namespace vsg
136+
137+
#if defined(__clang__)
138+
# pragma clang diagnostic pop
139+
#endif
140+
#if defined(__GNUC__)
141+
# pragma GCC diagnostic pop
142+
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
/* <editor-fold desc="MIT License">
4+
5+
Copyright(c) 2018 Robert Osfield
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
13+
</editor-fold> */
14+
15+
#include <vsg/nodes/Transform.h>
16+
#include <vsg/maths/ucoord.h>
17+
18+
namespace vsg
19+
{
20+
21+
/// CoordinateFrame provides support for astronomically large coordinates
22+
class VSG_DECLSPEC CoordinateFrame : public Inherit<Transform, CoordinateFrame>
23+
{
24+
public:
25+
CoordinateFrame();
26+
CoordinateFrame(const CoordinateFrame& rhs, const CopyOp& copyop = {});
27+
28+
ucoord::vec_type origin;
29+
30+
dmat4 transform(const dmat4& mv) const override;
31+
32+
public:
33+
ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return CoordinateFrame::create(*this, copyop); }
34+
int compare(const Object& rhs) const override;
35+
36+
void read(Input& input) override;
37+
void write(Output& output) const override;
38+
39+
protected:
40+
};
41+
VSG_type_name(vsg::CoordinateFrame);
42+
43+
} // namespace vsg

src/vsg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(SOURCES
3434
nodes/PagedLOD.cpp
3535
nodes/AbsoluteTransform.cpp
3636
nodes/MatrixTransform.cpp
37+
nodes/CoordinateFrame.cpp
3738
nodes/Transform.cpp
3839
nodes/VertexDraw.cpp
3940
nodes/VertexIndexDraw.cpp

src/vsg/app/RecordTraversal.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
3535
#include <vsg/nodes/LOD.h>
3636
#include <vsg/nodes/Layer.h>
3737
#include <vsg/nodes/MatrixTransform.h>
38+
#include <vsg/nodes/CoordinateFrame.h>
3839
#include <vsg/nodes/PagedLOD.h>
3940
#include <vsg/nodes/QuadGroup.h>
4041
#include <vsg/nodes/RegionOfInterest.h>
@@ -435,6 +436,28 @@ void RecordTraversal::apply(const MatrixTransform& mt)
435436
_state->dirty = true;
436437
}
437438

439+
void RecordTraversal::apply(const CoordinateFrame& cf)
440+
{
441+
GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "CoordinateFrame", COLOR_RECORD_L2, &cf);
442+
443+
_state->modelviewMatrixStack.push(cf);
444+
_state->dirty = true;
445+
446+
if (cf.subgraphRequiresLocalFrustum)
447+
{
448+
_state->pushFrustum();
449+
cf.traverse(*this);
450+
_state->popFrustum();
451+
}
452+
else
453+
{
454+
cf.traverse(*this);
455+
}
456+
457+
_state->modelviewMatrixStack.pop();
458+
_state->dirty = true;
459+
}
460+
438461
// Animation nodes
439462
void RecordTraversal::apply(const Joint&)
440463
{

src/vsg/core/ConstVisitor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ void ConstVisitor::apply(const MatrixTransform& value)
573573
{
574574
apply(static_cast<const Transform&>(value));
575575
}
576+
void ConstVisitor::apply(const CoordinateFrame& value)
577+
{
578+
apply(static_cast<const Transform&>(value));
579+
}
576580
void ConstVisitor::apply(const Geometry& value)
577581
{
578582
apply(static_cast<const Command&>(value));

src/vsg/core/Visitor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ void Visitor::apply(MatrixTransform& value)
573573
{
574574
apply(static_cast<Transform&>(value));
575575
}
576+
void Visitor::apply(CoordinateFrame& value)
577+
{
578+
apply(static_cast<Transform&>(value));
579+
}
576580
void Visitor::apply(Geometry& value)
577581
{
578582
apply(static_cast<Command&>(value));

0 commit comments

Comments
 (0)