Skip to content

Commit 5000f3e

Browse files
committed
fov settings
1 parent 4266828 commit 5000f3e

File tree

1 file changed

+40
-3
lines changed
  • common/src/main/kotlin/com/lambda/module/modules/render

1 file changed

+40
-3
lines changed

common/src/main/kotlin/com/lambda/module/modules/render/ViewModel.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import net.minecraft.item.ItemStack
1414
import net.minecraft.util.Arm
1515
import net.minecraft.util.Hand
1616
import net.minecraft.util.math.RotationAxis
17+
import org.joml.Matrix4f
1718
import org.joml.Vector3f
1819
import org.joml.Vector3i
20+
import kotlin.math.tan
1921

2022
object ViewModel : Module(
2123
name = "View Model",
@@ -61,8 +63,10 @@ object ViewModel : Module(
6163
private var rightZRotation by setting("Right Z Rotation", 0, -180..180, 1) { page == Page.Rotation && !linkedRotation }
6264

6365
private val linkedFOV by setting("Linked FOV", true, "Links both hands FOV settings") { page == Page.FOV }
64-
private val leftFOV by setting ("Left FOV", 80, 10..180, 1) { page == Page.FOV }.apply { onValueChange { _, to -> if (linkedFOV) rightFOV = to } }
65-
private var rightFOV by setting ("Right FOV", 80, 10..180, 1) { page == Page.FOV && !linkedFOV }
66+
private val leftFOV by setting("Left FOV", 70, 10..180, 1) { page == Page.FOV }.apply { onValueChange { _, to -> if (linkedFOV) rightFOV = to } }
67+
private var leftFOVAnchorDistance by setting("Left FOV Anchor Distance", 0.5f, 0.0f..1.0f, 0.01f, "The distance to anchor the left hands fov transformation from") { page == Page.FOV }.apply { onValueChange { _, to -> if (linkedFOV) rightFOVAnchorDistance = to } }
68+
private var rightFOV by setting("Right FOV", 70, 10..180, 1) { page == Page.FOV && !linkedFOV }
69+
private var rightFOVAnchorDistance by setting("Right FOV Anchor Distance", 0.5f, 0.0f..1.0f, 0.01f, "The distance to anchor the right hands fov transformation from") { page == Page.FOV && !linkedFOV }
6670

6771
private val handXScale by setting("Hand X Scale", 1.0f, -1.0f..1.0f, 0.025f) { page == Page.Hand }
6872
private val handYScale by setting("Hand Y Scale", 1.0f, -1.0f..1.0f, 0.025f) { page == Page.Hand }
@@ -73,7 +77,8 @@ object ViewModel : Module(
7377
private var handXRotation by setting("Hand X Rotation", 0, -180..180, 1) { page == Page.Hand }
7478
private var handYRotation by setting("Hand Y Rotation", 0, -180..180, 1) { page == Page.Hand }
7579
private var handZRotation by setting("Hand Z Rotation", 0, -180..180, 1) { page == Page.Hand }
76-
private val handFOV by setting("Hand FOV", 80, 10..180, 1) { page == Page.Hand }
80+
private val handFOV by setting("Hand FOV", 70, 10..180, 1) { page == Page.Hand }
81+
private var handFOVAnchorDistance by setting("Hand FOV Anchor Distance", 0.5f, 0.0f..1.0f, 0.01f, "The distance to anchor the hands fov transformation from") { page == Page.Hand }
7782

7883
private var attackKeyTicksPressed = -1
7984

@@ -114,11 +119,43 @@ object ViewModel : Module(
114119
val emptyHand = itemStack.isEmpty
115120
if (ignoreHand && emptyHand) return
116121

122+
applyItemFOV(matrices, side, emptyHand)
117123
scale(side, matrices, emptyHand)
118124
position(side, matrices, emptyHand)
119125
rotate(side, matrices, emptyHand)
120126
}
121127

128+
private fun applyItemFOV(matrices: MatrixStack, side: Side, emptyHand: Boolean) {
129+
val fov = when {
130+
side == Side.Left -> leftFOV
131+
emptyHand -> handFOV
132+
else -> rightFOV
133+
}.toFloat()
134+
135+
if (fov == 70f) return
136+
137+
val fovRatio = tan(Math.toRadians(fov.toDouble()/2)).toFloat() / tan(Math.toRadians(70.0/2)).toFloat()
138+
139+
val matrix = matrices.peek().positionMatrix
140+
141+
val distance = if (emptyHand) {
142+
handFOVAnchorDistance
143+
} else {
144+
when (side) {
145+
Side.Left -> leftFOVAnchorDistance
146+
Side.Right -> rightFOVAnchorDistance
147+
}
148+
}
149+
150+
val warpMatrix = Matrix4f().apply {
151+
translate(0f, 0f, -distance)
152+
scale(1f, 1f, fovRatio)
153+
translate(0f, 0f, distance)
154+
}
155+
156+
matrix.mul(warpMatrix)
157+
}
158+
122159
private fun scale(side: Side, matrices: MatrixStack, emptyHand: Boolean) {
123160
val scaleVec = getScaleVec(side, emptyHand)
124161
matrices.scale(scaleVec.x, scaleVec.y, scaleVec.z)

0 commit comments

Comments
 (0)