@@ -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;
0 commit comments