Rise
The Vieneo Province
Loading...
Searching...
No Matches
StreetMapProjection.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4
5// The raster map and route overlay must use the same rounded texture rectangle.
7{
8 struct Point
9 {
10 float x = 0.0f;
11 float y = 0.0f;
12 };
13
14 struct Rectangle
15 {
16 long left = 0, top = 0, right = 0, bottom = 0;
17 };
18
19 int x = 0, y = 0, width = 0, height = 0;
20 float magnification = 1.0f;
21 float bitmapOffsetX = 0.0f;
22 float overlayOffsetX = 0.0f; // Calibration relative to the road artwork, in screen pixels.
25 bool valid = false;
26
27 static Point WorldToTexture(Point position)
28 {
29 // Three sectors per dimension; preserve the original float rounding at crop boundaries.
30 return { (position.x - 519.0f) * 2048.0f * 0.3333333f,
31 (position.y - 1101.0f) * 2048.0f * 0.3333333f };
32 }
33
34 Point TextureToScreen(Point position) const
35 {
36 return { static_cast<float>(x) + bitmapOffsetX + (position.x - static_cast<float>(source.left)) * magnification,
37 static_cast<float>(y) + (position.y - static_cast<float>(source.top)) * magnification };
38 }
39
40 Point OverlayToScreen(Point texturePosition) const
41 {
42 auto position = TextureToScreen(texturePosition);
43 position.x += overlayOffsetX;
44 return position;
45 }
46
47 void CenterOverlays(float vehicleCenterX, float roadCorrectionPixels)
48 {
49 bitmapOffsetX = 0.0f;
50 overlayOffsetX = roadCorrectionPixels;
51 // The marker stays in the screen center; pan the bitmap beneath it.
52 bitmapOffsetX = std::round(vehicleCenterX - OverlayToScreen(centerTexture).x);
53 // Include enough texture to cover the full XML screen after panning.
54 source.right = source.left + static_cast<long>(std::ceil((static_cast<float>(width) - bitmapOffsetX) / magnification));
55 source.bottom = source.top + static_cast<long>(std::ceil(static_cast<float>(height) / magnification));
56 }
57
58 Point WorldToScreen(Point position) const
59 {
60 return OverlayToScreen(WorldToTexture(position));
61 }
62};
Point TextureToScreen(Point position) const
static Point WorldToTexture(Point position)
Point WorldToScreen(Point position) const
void CenterOverlays(float vehicleCenterX, float roadCorrectionPixels)
Point OverlayToScreen(Point texturePosition) const