mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:20:05 +00:00 
			
		
		
		
	Correct text not following map rotation
This commit is contained in:
		
							parent
							
								
									6c0b62709f
								
							
						
					
					
						commit
						f0c2f8eec0
					
				
					 2 changed files with 22 additions and 4 deletions
				
			
		|  | @ -5,6 +5,7 @@ | ||||||
| #include <scwx/qt/manager/settings_manager.hpp> | #include <scwx/qt/manager/settings_manager.hpp> | ||||||
| #include <scwx/qt/util/geographic_lib.hpp> | #include <scwx/qt/util/geographic_lib.hpp> | ||||||
| #include <scwx/qt/util/maplibre.hpp> | #include <scwx/qt/util/maplibre.hpp> | ||||||
|  | #include <scwx/common/geographic.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
| #include <fmt/format.h> | #include <fmt/format.h> | ||||||
|  | @ -59,6 +60,8 @@ public: | ||||||
|    std::uint32_t textId_ {}; |    std::uint32_t textId_ {}; | ||||||
|    glm::vec2     mapScreenCoordLocation_ {}; |    glm::vec2     mapScreenCoordLocation_ {}; | ||||||
|    float         mapScale_ {1.0f}; |    float         mapScale_ {1.0f}; | ||||||
|  |    float         mapBearingCos_ {1.0f}; | ||||||
|  |    float         mapBearingSin_ {0.0f}; | ||||||
|    float         halfWidth_ {}; |    float         halfWidth_ {}; | ||||||
|    float         halfHeight_ {}; |    float         halfHeight_ {}; | ||||||
|    bool          thresholded_ {true}; |    bool          thresholded_ {true}; | ||||||
|  | @ -149,12 +152,23 @@ void PlacefileLayer::Impl::RenderTextDrawItem( | ||||||
|                                       mapScreenCoordLocation_) * |                                       mapScreenCoordLocation_) * | ||||||
|                                      mapScale_; |                                      mapScale_; | ||||||
| 
 | 
 | ||||||
|  |       // Rotate text according to map rotation
 | ||||||
|  |       float rotatedX = screenCoordinates.x; | ||||||
|  |       float rotatedY = screenCoordinates.y; | ||||||
|  |       if (params.bearing != 0.0) | ||||||
|  |       { | ||||||
|  |          rotatedX = screenCoordinates.x * mapBearingCos_ - | ||||||
|  |                     screenCoordinates.y * mapBearingSin_; | ||||||
|  |          rotatedY = screenCoordinates.x * mapBearingSin_ + | ||||||
|  |                     screenCoordinates.y * mapBearingCos_; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|       RenderText(params, |       RenderText(params, | ||||||
|                  di->text_, |                  di->text_, | ||||||
|                  di->hoverText_, |                  di->hoverText_, | ||||||
|                  di->color_, |                  di->color_, | ||||||
|                  screenCoordinates.x + di->x_ + halfWidth_, |                  rotatedX + di->x_ + halfWidth_, | ||||||
|                  screenCoordinates.y + di->y_ + halfHeight_); |                  rotatedY + di->y_ + halfHeight_); | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -217,6 +231,8 @@ void PlacefileLayer::Render( | ||||||
|       {params.latitude, params.longitude}); |       {params.latitude, params.longitude}); | ||||||
|    p->mapScale_ = std::pow(2.0, params.zoom) * mbgl::util::tileSize_D / |    p->mapScale_ = std::pow(2.0, params.zoom) * mbgl::util::tileSize_D / | ||||||
|                   mbgl::util::DEGREES_MAX; |                   mbgl::util::DEGREES_MAX; | ||||||
|  |    p->mapBearingCos_ = std::cosf(params.bearing * common::kDegreesToRadians); | ||||||
|  |    p->mapBearingSin_ = std::sinf(params.bearing * common::kDegreesToRadians); | ||||||
|    p->halfWidth_     = params.width * 0.5f; |    p->halfWidth_     = params.width * 0.5f; | ||||||
|    p->halfHeight_    = params.height * 0.5f; |    p->halfHeight_    = params.height * 0.5f; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,6 +11,8 @@ namespace common | ||||||
| constexpr double kMilesPerMeter      = 0.00062137119; | constexpr double kMilesPerMeter      = 0.00062137119; | ||||||
| constexpr double kKilometersPerMeter = 0.001; | constexpr double kKilometersPerMeter = 0.001; | ||||||
| 
 | 
 | ||||||
|  | constexpr double kDegreesToRadians = 0.0174532925199432957692369055556; | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * @brief Coordinate type to hold latitude and longitude of a location. |  * @brief Coordinate type to hold latitude and longitude of a location. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat