Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
Altitmeter2.cpp
Go to the documentation of this file.
1
#include "
../Instrument.h
"
2
#include "
../../Bus.h
"
3
#include "
../../StringUtilities.h
"
4
#include "
../../MathUtilities.h
"
5
6
Altimeter2::Altimeter2
(
int
prmX,
int
prmY,
float
prmXScale,
float
prmYScale,
Bus
* prmBus,
Logger
* prmLogger,
DeviceObject
* prmDevice, std::vector<Font*> prmFonts) :
7
Instrument
(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
8
{
9
logger
->
AddToCallStack
(
"Altimeter2::ctor"
);
10
defaultFont
= 1;
11
12
tape
=
new
Sprite
(
logger
,
pDevice
,
"Textures/Instruments/alttape.png"
, prmX, prmY, 0.1f, 0, 0, 36, 263, 0xFFFFFFFF);
13
ground
=
new
Sprite
(
logger
,
pDevice
,
"Textures/Instruments/cas-bar.png"
, prmX, prmY, 0.3f, 0, 0, 36, 131, 0xFFffaa00);
14
bug
=
new
Sprite
(
logger
,
pDevice
,
"Textures/Instruments/altitudeBug.png"
, prmX, prmY, 0.8f, 0, 0, 18, 33, 0xFFff3be9, 0.3f, 0.4f);
15
trend
=
new
Sprite
(
logger
,
pDevice
,
"Textures/Instruments/cas-bar.png"
, prmX, prmY, 1.0f, 0, 0, 3, 256, 0xFFFFFFFF);
16
17
vsi
=
new
Sprite
(
logger
,
pDevice
,
"Textures/Instruments/needle.png"
, prmX + 20, prmY + 54, 0.95f, 0, 0, 128, 10, 0xFFFFFFFF);
18
}
19
20
void
Altimeter2::Render
()
21
{
22
tape
->
Draw
();
23
if
(
bus
->
RadioAltitudeKm
< 0.442f)
24
ground
->
Draw
();
25
bug
->
Draw
();
26
DrawTextW(
alt1
, 9,
yoffset1
, 0.2f, DT_NOCLIP, 0xffe0e0e0, 1,
""
);
27
DrawTextW(
alt2
, 9,
yoffset2
, 0.2f, DT_NOCLIP, 0xffe0e0e0, 1,
""
);
28
trend
->
Draw
();
29
30
if
(fabsf(
climbRate
) > 0.1f)
31
vsi
->
Draw
();
32
33
DrawTextW(
ivsi
, 34, 52, 1.0f, DT_NOCLIP, 0xff00ff00, 1,
""
);
34
}
35
36
void
Altimeter2::FrameMove
(
float
fElapsed)
37
{
38
// alt tape
39
// test mode
40
//bus->PressureAltitudeKm = 0;
41
const
float
fmodf1 = fmodf(
bus
->
PressureAltitudeKm
, 1.0f);
42
short
offsety = 73 -
static_cast<
short
>
(fmodf1 * 131.0f);
43
if
(offsety < 0)
44
offsety += 131;
45
tape
->
SetRectangle
(offsety, 0, 36, 116 + offsety);
46
tape
->
Update
();
47
48
// we are .136 ... next increment up is .500
49
// so the 2 from top to bottom are 500, 0
50
float
nextAltUp;
51
if
(fmodf1 >= 0.5f)
52
nextAltUp =
bus
->
PressureAltitudeKm
+ 1 - fmodf1;
53
else
54
nextAltUp =
bus
->
PressureAltitudeKm
+ 0.5f - fmodf1;
55
yoffset1
= 126 - offsety - 66;
56
if
(
yoffset1
< -16)
57
yoffset1
+= 66;
58
else
if
(
yoffset1
> 50)
59
yoffset1
-= 66;
60
yoffset2
=
yoffset1
+ 66;
61
Format4Sig
(
alt1
, nextAltUp);
62
Format4Sig
(
alt2
, nextAltUp - 0.5f);
63
64
offsety =
static_cast<
short
>
(
bus
->
RadioAltitudeKm
* 131.0f);
65
ground
->
SetLocation
(
x
,
y
+ 58 + offsety);
66
ground
->
SetRectangle
(offsety, 0, 36, 58);
67
ground
->
Update
();
68
69
// test mode
70
//bus->AFCS.DesiredAltitudeKm = 0.5f;
71
if
(
bus
->
AFCS
.
CurrentVerticalMode
==
Bus::Afcs::VerticalModes::AltitudeMsl
)
72
offsety =
static_cast<
short
>
((
bus
->
PressureAltitudeKm
-
bus
->
AFCS
.
DesiredAltitudeKm
) * 131.0f);
73
else
74
offsety =
static_cast<
short
>
((
f_AGL
-
bus
->
AFCS
.
DesiredAltitudeKm
) * 131.0f);
75
bug
->
SetLocation
(
x
,
y
+ 51 + offsety);
76
bug
->
Update
();
77
78
const
float
delta = (
bus
->
PressureAltitudeKm
-
oldPressureAltitudeKm
) / fElapsed * 10.0f;
79
oldPressureAltitudeKm
=
bus
->
PressureAltitudeKm
;
80
smoothDelta
+= (delta -
smoothDelta
) * fElapsed;
81
const
int
scaledDelta =
static_cast<
int
>
(
smoothDelta
* 131.0f);
82
const
int
bottom =
RiseMath::Max
(-57,
RiseMath::Min
(70, scaledDelta));
83
trend
->
SetRectangle
(0, 0, 3, bottom);
84
trend
->
SetLocation
(
x
- 3, 97 - bottom);
85
trend
->
Update
();
86
87
//float climbRate = sinf(Rendering::ClientTime()); // test mode
88
float
radians = 1385.546f + (0.0007706635f - 1385.546f) / (1.0f + powf(fabsf(
bus
->
VerticalSpeedKms
) / 568273600.0f, 0.3453538f));
89
radians *= copysignf(1.0f,
bus
->
VerticalSpeedKms
);
90
float
newClimbRate =
Clamp
(radians, -1.0f, 1.0f);
// so kms to mps to full-scale deflection at 500
91
// 100 mps is .5 and 200 mps is 1 ... so .1kms we are at 0.2 (should be 0.1) and .2kms we are at 0.4 (should be 0.2?)
92
climbRate
+= (newClimbRate -
climbRate
) * fElapsed;
93
// so if it is below 0.2 the resolution is double
94
vsi
->
rotate
= -
climbRate
;
95
vsi
->
SetLocation
(
static_cast<
int
>
(
static_cast<
float
>
(
x
) + 20.0f + (1.0f - fabsf(
climbRate
)) * 22.0f),
y
+ 54);
96
vsi
->
Update
();
97
98
// when it gets to 4 digits replace k 1.1
99
float
tempvsi = fabsf(
bus
->
VerticalSpeedKms
* 1000.0f);
100
if
(tempvsi >= 999.5f)
101
swprintf_s(
ivsi
, 16, L
"%4.1fk"
, tempvsi * 0.001f);
102
else
103
swprintf_s(
ivsi
, 16, L
"%4.0f"
, tempvsi);
104
}
Bus.h
Instrument.h
MathUtilities.h
Clamp
constexpr auto Clamp(T1 val, T2 min, T3 max)
Definition
MathUtilities.h:4
StringUtilities.h
Format4Sig
void Format4Sig(wchar_t *res, const float num)
Definition
StringUtilities.h:3
Altimeter2::yoffset1
int yoffset1
Definition
Instrument.h:661
Altimeter2::bug
Sprite * bug
Definition
Instrument.h:658
Altimeter2::alt2
WCHAR alt2[16]
Definition
Instrument.h:664
Altimeter2::vsi
Sprite * vsi
Definition
Instrument.h:660
Altimeter2::oldPressureAltitudeKm
float oldPressureAltitudeKm
Definition
Instrument.h:666
Altimeter2::tape
Sprite * tape
Definition
Instrument.h:656
Altimeter2::ivsi
WCHAR ivsi[16]
Definition
Instrument.h:665
Altimeter2::FrameMove
void FrameMove(float fElapsed) override
Definition
Altitmeter2.cpp:36
Altimeter2::alt1
WCHAR alt1[16]
Definition
Instrument.h:663
Altimeter2::Altimeter2
Altimeter2(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Definition
Altitmeter2.cpp:6
Altimeter2::Render
void Render() override
Definition
Altitmeter2.cpp:20
Altimeter2::trend
Sprite * trend
Definition
Instrument.h:659
Altimeter2::ground
Sprite * ground
Definition
Instrument.h:657
Altimeter2::smoothDelta
float smoothDelta
Definition
Instrument.h:667
Altimeter2::climbRate
float climbRate
Definition
Instrument.h:668
Altimeter2::yoffset2
int yoffset2
Definition
Instrument.h:662
Bus
Definition
Bus.h:20
Bus::PressureAltitudeKm
float PressureAltitudeKm
Definition
Bus.h:31
Bus::AFCS
struct Bus::Afcs AFCS
Bus::RadioAltitudeKm
float RadioAltitudeKm
Definition
Bus.h:157
Bus::VerticalSpeedKms
float VerticalSpeedKms
Definition
Bus.h:451
DeviceObject
Definition
DeviceObject.h:8
Instrument::bus
Bus * bus
Definition
Instrument.h:22
Instrument::x
int x
Definition
Instrument.h:17
Instrument::y
int y
Definition
Instrument.h:18
Instrument::Instrument
Instrument(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Definition
Instrument.h:36
Instrument::logger
Logger * logger
Definition
Instrument.h:23
Instrument::pDevice
DeviceObject * pDevice
Definition
Instrument.h:21
Instrument::defaultFont
UINT defaultFont
Definition
Instrument.h:24
Logger
Definition
Logger.h:11
Logger::AddToCallStack
void AddToCallStack(const char *msg)
Definition
Logger.cpp:355
Sprite::SetLocation
void SetLocation(int absoluteX, int absoluteY)
Definition
Sprite.cpp:99
Sprite::rotate
float rotate
Definition
Sprite.h:35
Sprite::Sprite
Sprite(Logger *prmLogger, DeviceObject *prmpDevice, std::string prmPathAndFilename, int prmX, int prmY, float prmZ, int prmTop, int prmLeft, int prmWidth, int prmHeight, DWORD prmColor, float scaleX=1.0f, float scaleY=1.0f)
Definition
Sprite.cpp:5
Sprite::Draw
void Draw(RiseMath::Color prmColor)
Definition
Sprite.cpp:75
Sprite::Update
void Update()
Definition
Sprite.cpp:50
Sprite::SetRectangle
void SetRectangle(int top, int left, int right, int bottom)
Definition
Sprite.cpp:105
f_AGL
float f_AGL
Definition
globals.cpp:9
RiseMath::Min
constexpr auto Min(A first, B second)
Definition
ClientMath.h:15
RiseMath::Max
constexpr auto Max(A first, B second)
Definition
ClientMath.h:16
Bus::Afcs::DesiredAltitudeKm
float DesiredAltitudeKm
Definition
Bus.h:122
Bus::Afcs::AltitudeMsl
@ AltitudeMsl
Definition
Bus.h:102
Bus::Afcs::CurrentVerticalMode
enum Bus::Afcs::VerticalModes CurrentVerticalMode
Instruments
PFD
Altitmeter2.cpp
Generated on
for Rise by
1.18.0