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
31void IGraphics::MapScreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
32 float ParallaxZoom, float OffsetX, float OffsetY, float Aspect, float Zoom, float *pPoints) 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 pPoints[0] = OffsetX + CenterX - Width / 2;
44 pPoints[1] = OffsetY + CenterY - Height / 2;
45 pPoints[2] = pPoints[0] + Width;
46 pPoints[3] = pPoints[1] + Height;
47}
48
49void IGraphics::MapScreenToInterface(float CenterX, float CenterY, float Zoom)
50{
51 float aPoints[4];
52 MapScreenToWorld(CenterX, CenterY, ParallaxX: 100.0f, ParallaxY: 100.0f, ParallaxZoom: 100.0f,
53 OffsetX: 0, OffsetY: 0, Aspect: ScreenAspect(), Zoom, pPoints: aPoints);
54 MapScreen(TopLeftX: aPoints[0], TopLeftY: aPoints[1], BottomRightX: aPoints[2], BottomRightY: aPoints[3]);
55}
56