99
1010// A rotation tracking view matrix. It returns the rotation component
1111// of another viewMatrix.
12- class RotationTrackingMatrix : public vsg ::Inherit<vsg::ViewMatrix, RotationTrackingMatrix> {
13- public:
12+ class RotationTrackingMatrix : public vsg ::Inherit<vsg::ViewMatrix, RotationTrackingMatrix>
13+ {
14+ public:
1415 RotationTrackingMatrix (vsg::ref_ptr<vsg::ViewMatrix> parentTransform) :
1516 parentTransform_ (parentTransform) {}
16-
17+
1718 // The transform() returns the rotation part of the tracked matrix
18- vsg::dmat4 transform (const vsg::dvec3&) const override {
19+ vsg::dmat4 transform (const vsg::dvec3&) const override
20+ {
1921
2022 vsg::dvec3 translation, scale;
21- vsg::dquat rotation;
23+ vsg::dquat rotation;
2224 vsg::decompose (parentTransform_->transform (),
2325 // output
2426 translation,
2527 rotation,
2628 scale);
27-
29+
2830 return vsg::rotate (rotation);
2931 }
30-
31- private:
32+
33+ private:
3234 vsg::ref_ptr<vsg::ViewMatrix> parentTransform_;
3335};
3436
@@ -42,29 +44,29 @@ vsg::ref_ptr<vsg::Node> createArrow(vsg::vec3 pos, vsg::vec3 dir, vsg::vec4 colo
4244 vsg::GeometryInfo geomInfo;
4345 vsg::StateInfo stateInfo;
4446
45- geomInfo.color = vsg::vec4{1 ,1 , 1 , 1 };
47+ geomInfo.color = vsg::vec4{1 , 1 , 1 , 1 };
4648 geomInfo.position = pos;
4749 geomInfo.transform = vsg::translate (0 .0f , 0 .0f , 0 .5f );
4850
4951 // If we don't point in the z-direction, then rotate the arrow
50- if (vsg::length (vsg::cross (vsg::vec3{0 ,0 , 1 }, dir)) > 0.0001 )
52+ if (vsg::length (vsg::cross (vsg::vec3{0 , 0 , 1 }, dir)) > 0.0001 )
5153 {
52- vsg::vec3 axis = vsg::cross (vsg::vec3{0 ,0 , 1 }, dir);
53- float angle = acos (vsg::dot (vsg::vec3{0 ,0 , 1 }, dir));
54+ vsg::vec3 axis = vsg::cross (vsg::vec3{0 , 0 , 1 }, dir);
55+ float angle = acos (vsg::dot (vsg::vec3{0 , 0 , 1 }, dir));
5456 geomInfo.transform = vsg::rotate (angle, axis) * geomInfo.transform ;
5557 }
5658
5759 auto axisTransform = geomInfo.transform ;
5860 geomInfo.transform = geomInfo.transform * vsg::scale (0 .1f , 0 .1f , 1 .0f );
59-
61+
6062 // Rotate geomInfo from pos in the direction of dir
6163 auto node = builder.createCylinder (geomInfo, stateInfo);
6264 arrow->addChild (node);
6365
6466 // The cone
6567 geomInfo.color = color;
6668 // This would have been cleaner with a pre_translate transform
67- geomInfo.transform = vsg::scale (0 .3f , 0 .3f , 0 .3f ) * axisTransform * vsg::translate (0 .0f , 0 .0f , 1 .0f / 0 .3f );
69+ geomInfo.transform = vsg::scale (0 .3f , 0 .3f , 0 .3f ) * axisTransform * vsg::translate (0 .0f , 0 .0f , 1 .0f / 0 .3f );
6870 node = builder.createCone (geomInfo, stateInfo);
6971 arrow->addChild (node);
7072
@@ -76,14 +78,14 @@ vsg::ref_ptr<vsg::Node> createGizmo()
7678{
7779 vsg::ref_ptr<vsg::Group> gizmo = vsg::Group::create ();
7880
79- gizmo->addChild (createArrow (vsg::vec3{0 ,0 , 0 }, vsg::vec3{1 ,0 , 0 }, vsg::vec4{1 ,0 , 0 , 1 }));
80- gizmo->addChild (createArrow (vsg::vec3{0 ,0 , 0 }, vsg::vec3{0 ,1 , 0 }, vsg::vec4{0 ,1 , 0 , 1 }));
81- gizmo->addChild (createArrow (vsg::vec3{0 ,0 , 0 }, vsg::vec3{0 ,0 , 1 }, vsg::vec4{0 ,0 , 1 , 1 }));
81+ gizmo->addChild (createArrow (vsg::vec3{0 , 0 , 0 }, vsg::vec3{1 , 0 , 0 }, vsg::vec4{1 , 0 , 0 , 1 }));
82+ gizmo->addChild (createArrow (vsg::vec3{0 , 0 , 0 }, vsg::vec3{0 , 1 , 0 }, vsg::vec4{0 , 1 , 0 , 1 }));
83+ gizmo->addChild (createArrow (vsg::vec3{0 , 0 , 0 }, vsg::vec3{0 , 0 , 1 }, vsg::vec4{0 , 0 , 1 , 1 }));
8284
8385 vsg::Builder builder;
8486 vsg::GeometryInfo geomInfo;
8587 vsg::StateInfo stateInfo;
86- geomInfo.color = vsg::vec4{1 ,1 , 1 , 1 };
88+ geomInfo.color = vsg::vec4{1 , 1 , 1 , 1 };
8789 geomInfo.transform = vsg::scale (0 .1f , 0 .1f , 0 .1f );
8890
8991 auto sphere = builder.createSphere (geomInfo, stateInfo);
@@ -95,7 +97,7 @@ vsg::ref_ptr<vsg::Node> createGizmo()
9597// Create a tracking overlay with a axes view that shows the orientation
9698// of the main camera view matrix
9799vsg::ref_ptr<vsg::View> createAxesView (vsg::ref_ptr<vsg::Camera> camera,
98- double aspectRatio)
100+ double aspectRatio)
99101{
100102 auto viewMat = RotationTrackingMatrix::create (camera->viewMatrix );
101103
@@ -104,14 +106,14 @@ vsg::ref_ptr<vsg::View> createAxesView(vsg::ref_ptr<vsg::Camera> camera,
104106 double camWidth = 10 ;
105107 double camXOffs = -8 ;
106108 double camYOffs = -8 ;
107- auto ortho = vsg::Orthographic::create (camXOffs,camXOffs+ camWidth, // left, right
108- camYOffs/ aspectRatio,(camYOffs+ camWidth)/ aspectRatio, // bottom, top
109- -1000 ,1000 ); // near, far
109+ auto ortho = vsg::Orthographic::create (camXOffs, camXOffs + camWidth, // left, right
110+ camYOffs / aspectRatio, (camYOffs + camWidth) / aspectRatio, // bottom, top
111+ -1000 , 1000 ); // near, far
110112
111113 auto gizmoCamera = vsg::Camera::create (
112- ortho,
113- viewMat,
114- camera->viewportState );
114+ ortho,
115+ viewMat,
116+ camera->viewportState );
115117
116118 auto scene = vsg::Group::create ();
117119 scene->addChild (createGizmo ());
@@ -194,7 +196,7 @@ int main(int argc, char** argv)
194196
195197 uint32_t width = window->extent2D ().width ;
196198 uint32_t height = window->extent2D ().height ;
197- double aspectRatio = (double )width/ height;
199+ double aspectRatio = (double )width / height;
198200
199201 auto renderGraph = vsg::RenderGraph::create (window);
200202
0 commit comments