Skip to content

Commit dfa41a8

Browse files
committed
fix(AttitudeDisplay): account for crosshair offset
Signed-off-by: Octol1ttle <[email protected]> Signed-off-by: Octol1ttle <[email protected]>
1 parent 908512d commit dfa41a8

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/main/kotlin/ru/octol1ttle/flightassistant/impl/display/AttitudeDisplay.kt

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,68 +33,70 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
3333
}
3434

3535
with(guiGraphics) {
36+
val centerX: Float = centerXF - 0.5f
37+
3638
pose().push()
3739
//? if <1.21.6
3840
pose().translate(0.0f, 0.0f, -200.0f)
3941
//? if >=1.21.6 {
40-
/*pose().rotateAbout(ru.octol1ttle.flightassistant.api.util.radians(-computers.hudData.roll), centerXF, centerYF)
42+
/*pose().rotateAbout(ru.octol1ttle.flightassistant.api.util.radians(-computers.hudData.roll), centerX, centerYF)
4143
*///?} else
42-
pose().rotateAround(Axis.ZN.rotationDegrees(computers.hudData.roll), centerXF, centerYF, 0.0f)
44+
pose().rotateAround(Axis.ZN.rotationDegrees(computers.hudData.roll), centerX, centerYF, 0.0f)
4345

4446
if (!FAConfig.display.drawPitchOutsideFrame) {
4547
HudFrame.scissor(this)
4648
}
4749
if (FAConfig.display.showAttitude <= DisplayOptions.AttitudeDisplayMode.HORIZON_ONLY) {
48-
renderHorizon()
50+
renderHorizon(centerX)
4951
}
5052
if (FAConfig.display.showAttitude == DisplayOptions.AttitudeDisplayMode.HORIZON_AND_LADDER) {
51-
renderPitchBars()
52-
renderPitchLimits()
53-
drawPitchReferenceMark(47.5f)
54-
drawPitchReferenceMark(-2.2f)
55-
drawPitchReferenceMark(-38.5f)
53+
renderPitchBars(centerX)
54+
renderPitchLimits(centerX)
55+
drawPitchReferenceMark(47.5f, centerX)
56+
drawPitchReferenceMark(-2.2f, centerX)
57+
drawPitchReferenceMark(-38.5f, centerX)
5658
}
5759
if (!FAConfig.display.drawPitchOutsideFrame) {
5860
disableScissor()
5961
}
6062

6163
pose().pop()
6264
if (FAConfig.display.showAutomationModes) {
63-
renderPitchTarget(centerX - 6, centerY - 10)
65+
renderPitchTarget(this.centerX - 6, centerY - 10)
6466
}
6567
}
6668
}
6769

68-
private fun GuiGraphics.renderHorizon() {
70+
private fun GuiGraphics.renderHorizon(centerX: Float) {
6971
ScreenSpace.getY(0.0f)?.let {
7072
val color = getPitchBarColor(0.0f)
7173

72-
val leftXEnd: Int = (centerXF - halfWidth * 0.025f).toInt()
74+
val leftXEnd: Int = (centerX - halfWidth * 0.025f).toInt()
7375
val leftXStart: Int = (leftXEnd - halfWidth * 0.3f).toInt()
7476
drawRightAlignedString("0", leftXStart - 3, it - 3, color)
7577
hLine(leftXStart, leftXEnd, it, color)
7678

77-
val rightXStart: Int = (centerXF + halfWidth * 0.025f).toInt()
79+
val rightXStart: Int = (centerX + halfWidth * 0.025f).toInt()
7880
val rightXEnd: Int = (rightXStart + halfWidth * 0.3f).toInt()
7981
hLine(rightXStart, rightXEnd, it, color)
8082
drawString("0", rightXEnd + 5, it - 3, color)
8183
}
8284
}
8385

84-
private fun GuiGraphics.renderPitchBars() {
86+
private fun GuiGraphics.renderPitchBars(centerX: Float) {
8587
val step: Int = FAConfig.display.attitudeDegreeStep
8688
val nextUp: Int = Mth.roundToward(computers.data.pitch.toInt(), step)
8789
for (i: Int in nextUp..90 step step) {
88-
drawPitchBar(i, (ScreenSpace.getY(i.toFloat()) ?: break))
90+
drawPitchBar(i, centerX, (ScreenSpace.getY(i.toFloat()) ?: break))
8991
}
9092

9193
val nextDown: Int = Mth.quantize(computers.data.pitch.toDouble(), step)
9294
for (i: Int in nextDown downTo -90 step step) {
93-
drawPitchBar(i, (ScreenSpace.getY(i.toFloat()) ?: break))
95+
drawPitchBar(i, centerX, (ScreenSpace.getY(i.toFloat()) ?: break))
9496
}
9597
}
9698

97-
private fun GuiGraphics.renderPitchLimits() {
99+
private fun GuiGraphics.renderPitchLimits(centerX: Float) {
98100
val step: Int = FAConfig.display.attitudeDegreeStep / 2
99101

100102
val arrowText: Component = Component.literal("V")
@@ -107,15 +109,15 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
107109
while (max <= 180) {
108110
val y: Int = ScreenSpace.getY(max) ?: break
109111

110-
drawMiddleAlignedString(arrowText, centerX, y - 9, if (maxInput?.status == ControlInput.Status.ACTIVE) warningColor else cautionColor)
112+
drawMiddleAlignedString(arrowText, centerX.toInt(), y - 9, if (maxInput?.status == ControlInput.Status.ACTIVE) warningColor else cautionColor)
111113

112114
max += step
113115
}
114116
while (min >= -180) {
115117
val y: Int = ScreenSpace.getY(min) ?: break
116118
pose().push()
117119

118-
pose().translate(centerXF, y.toFloat() /*? if <1.21.6 {*/, 0.0f /*?}*/) // Rotate around the middle of the arrow
120+
pose().translate(centerX, y.toFloat() /*? if <1.21.6 {*/, 0.0f /*?}*/) // Rotate around the middle of the arrow
119121
//? if >=1.21.6 {
120122
/*pose().rotate(ru.octol1ttle.flightassistant.api.util.radians(180.0f))
121123
*///?} else
@@ -127,31 +129,31 @@ class AttitudeDisplay(computers: ComputerBus) : Display(computers) {
127129
}
128130
}
129131

130-
private fun GuiGraphics.drawPitchReferenceMark(pitch: Float) {
132+
private fun GuiGraphics.drawPitchReferenceMark(pitch: Float, centerX: Float) {
131133
val y = ScreenSpace.getY(pitch) ?: return
132134

133135
val color: Int = getPitchBarColor(pitch)
134-
val leftXEnd: Int = (centerXF - halfWidth * 0.025f).toInt()
136+
val leftXEnd: Int = (centerX - halfWidth * 0.025f).toInt()
135137
val leftXStart: Int = (leftXEnd - halfWidth * 0.05f).toInt()
136138
hLineDashed(leftXStart, leftXEnd, y, 2, color)
137139

138-
val rightXStart: Int = (centerXF + halfWidth * 0.025f).toInt()
140+
val rightXStart: Int = (centerX + halfWidth * 0.025f).toInt()
139141
val rightXEnd: Int = (rightXStart + halfWidth * 0.05f).toInt()
140142
hLineDashed(rightXStart, rightXEnd, y, 2, color)
141143
}
142144

143-
private fun GuiGraphics.drawPitchBar(pitch: Int, y: Int) {
145+
private fun GuiGraphics.drawPitchBar(pitch: Int, centerX: Float, y: Int) {
144146
if (pitch == 0) return
145147

146148
val color: Int = getPitchBarColor(pitch.toFloat())
147149

148-
val leftXEnd: Int = (centerXF - halfWidth * 0.05f).toInt()
150+
val leftXEnd: Int = (centerX - halfWidth * 0.05f).toInt()
149151
val leftXStart: Int = (leftXEnd - halfWidth * 0.075f).toInt()
150152
drawRightAlignedString(pitch.toString(), leftXStart - 2, if (pitch > 0) y else y - 4, color)
151153
vLine(leftXStart, y, y + 5 * pitch.sign, color)
152154
hLineDashed(leftXStart, leftXEnd, y, if (pitch < 0) 3 else 1, color)
153155

154-
val rightXStart: Int = (centerXF + halfWidth * 0.05f).toInt()
156+
val rightXStart: Int = (centerX + halfWidth * 0.05f).toInt()
155157
val rightXEnd: Int = (rightXStart + halfWidth * 0.075f).toInt()
156158
hLineDashed(rightXStart, rightXEnd, y, if (pitch < 0) 3 else 1, color)
157159
vLine(rightXEnd, y, y + 5 * pitch.sign, color)

0 commit comments

Comments
 (0)