1#include "graphics.h"
2
3// helper functions
4void IGraphics::CalcScreenParams(float Aspect, float Zoom, float *pWidth, float *pHeight) const
5{
6 const float Amount = 1150 * 1000;
7 const float WMax = 1500;
8 const float HMax = 1050;
9
10 const float f = std::sqrt(x: Amount) / std::sqrt(x: Aspect);
11 *pWidth = f * Aspect;
12 *pHeight = f;
13
14 // limit the view
15 if(*pWidth > WMax)
16 {
17 *pWidth = WMax;
18 *pHeight = *pWidth / Aspect;
19 }
20
21 if(*pHeight > HMax)
22 {
23 *pHeight = HMax;
24 *pWidth = *pHeight * Aspect;
25 }
26
27 *pWidth *= Zoom;
28 *pHeight *= Zoom;
29}
30
31CScreenRect IGraphics::MapScreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
32 float ParallaxZoom, float OffsetX, float OffsetY, float Aspect, float Zoom) const
33{
34 float Width, Height;
35 CalcScreenParams(Aspect, Zoom, pWidth: &Width, pHeight: &Height);
36
37 float Scale = (ParallaxZoom * (Zoom - 1.0f) + 100.0f) / 100.0f / Zoom;
38 Width *= Scale;
39 Height *= Scale;
40
41 CenterX *= ParallaxX / 100.0f;
42 CenterY *= ParallaxY / 100.0f;
43
44 return CScreenRect(
45 OffsetX + CenterX - Width / 2,
46 OffsetY + CenterY - Height / 2,
47 Width,
48 Height);
49}
50
51void IGraphics::MapScreenToInterface(float CenterX, float CenterY, float Zoom)
52{
53 CScreenRect ScreenRect = MapScreenToWorld(CenterX, CenterY, ParallaxX: 100.0f, ParallaxY: 100.0f, ParallaxZoom: 100.0f,
54 OffsetX: 0, OffsetY: 0, Aspect: ScreenAspect(), Zoom);
55 MapScreen(ScreenRect);
56}
57
58void IGraphics::MapScreenToSize(float Width, float Height)
59{
60 MapScreen(ScreenRect: CScreenRect(0, 0, Width, Height));
61}
62