From 1411e1f73a7fe682b833f58876daac2b25b3994a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 3 Aug 2018 10:22:34 +0200 Subject: [PATCH] GAL: added methods to modify rotation in the transformation matrix --- common/gal/graphics_abstraction_layer.cpp | 10 ++++++---- include/gal/graphics_abstraction_layer.h | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index aa945d3bfd..15c5e4c404 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -48,6 +48,7 @@ GAL::GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions ) : SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetLookAtPoint( VECTOR2D( 0, 0 ) ); SetZoomFactor( 1.0 ); + SetRotation( 0.0 ); SetWorldUnitLength( 1.0 / METRIC_UNIT_LENGTH * 2.54 ); // 1 inch in nanometers SetScreenDPI( 106 ); // Display resolution setting SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) ); @@ -178,18 +179,19 @@ void GAL::ComputeWorldScreenMatrix() { computeWorldScale(); - worldScreenMatrix.SetIdentity(); - MATRIX3x3D translation; translation.SetIdentity(); translation.SetTranslation( 0.5 * VECTOR2D( screenSize ) ); + MATRIX3x3D rotate; + rotate.SetIdentity(); + rotate.SetRotation( rotation ); + MATRIX3x3D scale; scale.SetIdentity(); scale.SetScale( VECTOR2D( worldScale, worldScale ) ); MATRIX3x3D flip; - flip.SetIdentity(); flip.SetScale( VECTOR2D( globalFlipX ? -1.0 : 1.0, globalFlipY ? -1.0 : 1.0 ) ); @@ -197,7 +199,7 @@ void GAL::ComputeWorldScreenMatrix() lookat.SetIdentity(); lookat.SetTranslation( -lookAtPoint ); - worldScreenMatrix = translation * flip * scale * lookat * worldScreenMatrix; + worldScreenMatrix = translation * rotate * flip * scale * lookat; screenWorldMatrix = worldScreenMatrix.Inverse(); } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index ddecf6b470..713c42e581 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -506,7 +506,7 @@ public: /** * @brief Transform the context. * - * @param aTransformation is the ransformation matrix. + * @param aTransformation is the transformation matrix. */ virtual void Transform( const MATRIX3x3D& aTransformation ) {}; @@ -695,6 +695,26 @@ public: return zoomFactor; } + /** + * @brief Set the rotation angle. + * + * @param aRotation is the new rotation angle (radians). + */ + void SetRotation( double aRotation ) + { + rotation = aRotation; + } + + /** + * Get the rotation angle. + * + * @return The rotation angle (radians). + */ + double GetRotation() const + { + return rotation; + } + /** * @brief Set the range of the layer depth. * @@ -1009,6 +1029,7 @@ protected: VECTOR2D lookAtPoint; ///< Point to be looked at in world space double zoomFactor; ///< The zoom factor + double rotation; ///< Rotation transformation (radians) MATRIX3x3D worldScreenMatrix; ///< World transformation MATRIX3x3D screenWorldMatrix; ///< Screen transformation double worldScale; ///< The scale factor world->screen