Rise
The Vieneo Province
Toggle main menu visibility
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.
6
struct
StreetMapProjection
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.
23
Point
centerTexture
;
24
Rectangle
source
;
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
};
StreetMapProjection::Point
Definition
StreetMapProjection.h:9
StreetMapProjection::Point::y
float y
Definition
StreetMapProjection.h:11
StreetMapProjection::Point::x
float x
Definition
StreetMapProjection.h:10
StreetMapProjection::Rectangle
Definition
StreetMapProjection.h:15
StreetMapProjection::Rectangle::bottom
long bottom
Definition
StreetMapProjection.h:16
StreetMapProjection::Rectangle::right
long right
Definition
StreetMapProjection.h:16
StreetMapProjection::Rectangle::left
long left
Definition
StreetMapProjection.h:16
StreetMapProjection::Rectangle::top
long top
Definition
StreetMapProjection.h:16
StreetMapProjection
Definition
StreetMapProjection.h:7
StreetMapProjection::magnification
float magnification
Definition
StreetMapProjection.h:20
StreetMapProjection::TextureToScreen
Point TextureToScreen(Point position) const
Definition
StreetMapProjection.h:34
StreetMapProjection::WorldToTexture
static Point WorldToTexture(Point position)
Definition
StreetMapProjection.h:27
StreetMapProjection::centerTexture
Point centerTexture
Definition
StreetMapProjection.h:23
StreetMapProjection::WorldToScreen
Point WorldToScreen(Point position) const
Definition
StreetMapProjection.h:58
StreetMapProjection::overlayOffsetX
float overlayOffsetX
Definition
StreetMapProjection.h:22
StreetMapProjection::CenterOverlays
void CenterOverlays(float vehicleCenterX, float roadCorrectionPixels)
Definition
StreetMapProjection.h:47
StreetMapProjection::y
int y
Definition
StreetMapProjection.h:19
StreetMapProjection::source
Rectangle source
Definition
StreetMapProjection.h:24
StreetMapProjection::x
int x
Definition
StreetMapProjection.h:19
StreetMapProjection::valid
bool valid
Definition
StreetMapProjection.h:25
StreetMapProjection::bitmapOffsetX
float bitmapOffsetX
Definition
StreetMapProjection.h:21
StreetMapProjection::OverlayToScreen
Point OverlayToScreen(Point texturePosition) const
Definition
StreetMapProjection.h:40
StreetMapProjection::height
int height
Definition
StreetMapProjection.h:19
StreetMapProjection::width
int width
Definition
StreetMapProjection.h:19
Instruments
StreetMapProjection.h
Generated on
for Rise by
1.18.0