Skip to content

Commit

Permalink
refactor: direction vector from Vec3d.fromPolar(...)
Browse files Browse the repository at this point in the history
Fixes the inaccuracy of the old implementation.
  • Loading branch information
1zun4 committed Feb 15, 2025
1 parent 8ae833f commit 2ca2f75
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private Vec3d hookModifyFallFlyingRotationVector(Vec3d original) {
return original;
}

return rotation.getRotationVec();
return rotation.getDirectionVector();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static Vec3d hookFixRotation(Vec3d original, World world, PlayerEntity p
var rotation = RotationManager.INSTANCE.getCurrentRotation();

if (player == MinecraftClient.getInstance().player && rotation != null) {
return rotation.getRotationVec();
return rotation.getDirectionVector();
}

return original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private Vec3d hookRotationVector(Vec3d original, Entity camera, double blockInte
}

var rotation = RotationManager.INSTANCE.getCurrentRotation();
return rotation != null ? rotation.getRotationVec() : original;
return rotation != null ? rotation.getDirectionVector() : original;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ object KillAuraFightBot : NavigationBaseConfigurable<CombatContext>(ModuleKillAu
return (-180..180 step 45)
.mapNotNull { yaw ->
val rotation = Rotation(yaw = yaw.toFloat(), pitch = 0.0F)
val position = leaderPosition.add(rotation.rotationVec * LeaderFollower.radius.toDouble())
val position = leaderPosition.add(rotation.directionVector * LeaderFollower.radius.toDouble())
ModuleDebug.debugGeometry(
this,
"Possible Position $yaw",
Expand All @@ -170,20 +170,20 @@ object KillAuraFightBot : NavigationBaseConfigurable<CombatContext>(ModuleKillAu

private fun calculateRunawayPosition(context: CombatContext, combatTarget: CombatTarget): Vec3d {
return context.playerPosition.add(
combatTarget.requiredTargetRotation.rotationVec * combatTarget.range.toDouble()
combatTarget.requiredTargetRotation.directionVector * combatTarget.range.toDouble()
)
}

private fun calculateAttackPosition(context: CombatContext, combatTarget: CombatTarget): Vec3d {
val target = combatTarget.entity
val targetLookPosition = target.pos.add(
combatTarget.targetRotation.rotationVec * combatTarget.range.toDouble()
combatTarget.targetRotation.directionVector * combatTarget.range.toDouble()
)

return (-180..180 step 10)
.mapNotNull { yaw ->
val rotation = Rotation(yaw = yaw.toFloat(), pitch = 0.0F)
val position = target.pos.add(rotation.rotationVec * combatTarget.range.toDouble())
val position = target.pos.add(rotation.directionVector * combatTarget.range.toDouble())

val isInAngle = rotation.angleTo(combatTarget.targetRotation) <= dangerousYawDiff
ModuleDebug.debugGeometry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal object KillAuraNotifyWhenFail {
when (mode.activeChoice) {
Box -> {
val centerDistance = entity.box.center.subtract(player.eyePos).length()
val boxSpot = player.eyePos.add(rotation.rotationVec.multiply(centerDistance))
val boxSpot = player.eyePos.add(rotation.directionVector.multiply(centerDistance))

failedHits.add(ObjectLongMutablePair(boxSpot, 0L))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object ModuleFreeCam : ClientModule("FreeCam", Category.RENDER, disableOnQuit =
val target = raycast(
range = 100.0,
start = cameraPosition,
direction = mc.cameraEntity?.rotation?.rotationVec ?: return null
direction = mc.cameraEntity?.rotation?.directionVector ?: return null
)

return target.pos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object ModuleRotations : ClientModule("Rotations", Category.RENDER) {
val previousRotation = RotationManager.previousRotation ?: currentRotation
val camera = mc.gameRenderer.camera

val interpolatedRotationVec = previousRotation.rotationVec.lerp(currentRotation.rotationVec,
val interpolatedRotationVec = previousRotation.directionVector.lerp(currentRotation.directionVector,
partialTicks.toDouble()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import net.ccbluex.liquidbounce.utils.kotlin.Priority
import net.minecraft.block.*
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.enchantment.Enchantments
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.util.Hand
import net.minecraft.util.hit.HitResult
Expand Down Expand Up @@ -127,7 +125,7 @@ object ModuleAutoFarm : ClientModule("AutoFarm", Category.WORLD) {
val rayTraceResult = world.raycast(
RaycastContext(
player.eyePos,
player.eyePos.add(currentRotation.rotationVec.multiply(range.toDouble())),
player.eyePos.add(currentRotation.directionVector.multiply(range.toDouble())),
RaycastContext.ShapeType.OUTLINE,
RaycastContext.FluidHandling.NONE,
player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object ScaffoldGodBridgeTechnique : ScaffoldTechnique("GodBridge"), ScaffoldLedg

return if (snapshotOne.clipLedged) {
val cameraPosition = snapshotOne.pos.add(0.0, player.standingEyeHeight.toDouble(), 0.0)
val currentCrosshairTarget = raycast(start = cameraPosition, direction = rotation.rotationVec)
val currentCrosshairTarget = raycast(start = cameraPosition, direction = rotation.directionVector)

if (target == null) {
return LedgeAction.NO_LEDGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class PointTracker(
)
}),
ASSIST("Assist", { box, eyes ->
val vec3 = eyes + player.rotation.rotationVec
val vec3 = eyes + player.rotation.directionVector

Vec3d(
vec3.x.coerceAtMost(box.maxX).coerceAtLeast(box.minX),
Expand Down Expand Up @@ -267,7 +267,7 @@ class PointTracker(
val positionDifference = playerPosition.y - entity.pos.y

if (intersectsBox && player.box.intersects(entity.box)) {
return Point(playerEyes, playerEyes + currentRotation.rotationVec, entity.box, entity.box)
return Point(playerEyes, playerEyes + currentRotation.directionVector, entity.box, entity.box)
}

// Predicted target position of the enemy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun raytraceEntity(
val entity = mc.cameraEntity ?: return null

val cameraVec = entity.eyePos
val rotationVec = rotation.rotationVec
val rotationVec = rotation.directionVector

val vec3d3 = cameraVec.add(rotationVec.x * range, rotationVec.y * range, rotationVec.z * range)
val box = entity.boundingBox.stretch(rotationVec.multiply(range)).expand(1.0, 1.0, 1.0)
Expand All @@ -89,7 +89,7 @@ fun raytraceBlock(
val entity: Entity = mc.cameraEntity ?: return null

val start = entity.eyePos
val rotationVec = rotation.rotationVec
val rotationVec = rotation.directionVector

val end = start.add(rotationVec.x * range, rotationVec.y * range, rotationVec.z * range)

Expand All @@ -112,7 +112,7 @@ fun raycast(
range = range,
includeFluids = includeFluids,
start = player.getCameraPosVec(tickDelta),
direction = rotation.rotationVec
direction = rotation.directionVector
)
}

Expand Down Expand Up @@ -167,7 +167,7 @@ fun facingEnemy(
wallsRange: Double,
): Boolean {
val cameraVec = fromEntity.eyePos
val rotationVec = rotation.rotationVec
val rotationVec = rotation.directionVector

val rangeSquared = range.sq()
val wallsRangeSquared = wallsRange.sq()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,8 @@ data class Rotation(
}
}

val rotationVec: Vec3d
get() {
val yawCos = MathHelper.cos(-yaw * 0.017453292f)
val yawSin = MathHelper.sin(-yaw * 0.017453292f)
val pitchCos = MathHelper.cos(pitch * 0.017453292f)
val pitchSin = MathHelper.sin(pitch * 0.017453292f)
return Vec3d((yawSin * pitchCos).toDouble(), (-pitchSin).toDouble(), (yawCos * pitchCos).toDouble())
}
val directionVector: Vec3d
get() = Vec3d.fromPolar(pitch, yaw)

/**
* Fixes GCD and Modulo 360° at yaw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package net.ccbluex.liquidbounce.utils.aiming

import net.ccbluex.liquidbounce.utils.client.player
import net.ccbluex.liquidbounce.utils.entity.*
import net.ccbluex.liquidbounce.utils.entity.rotation
import net.ccbluex.liquidbounce.utils.math.plus
import net.ccbluex.liquidbounce.utils.math.times
import net.minecraft.util.math.Vec3d
Expand All @@ -41,7 +41,7 @@ class LeastDifferencePreference(
return this.basePoint
}

return eyesPos + this.baseRotation.rotationVec * range
return eyesPos + this.baseRotation.directionVector * range
}

override fun compare(o1: Rotation, o2: Rotation): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class NearestRotationTargetPositionFactory(val config: PositionFactoryConfigurat

val currentRotation = RotationManager.serverRotation

val rotationLine = Line(config.eyePos.subtract(Vec3d.of(targetPos)), currentRotation.rotationVec)
val rotationLine = Line(config.eyePos.subtract(Vec3d.of(targetPos)), currentRotation.directionVector)

val pointOnFace = face.nearestPointTo(rotationLine)

Expand All @@ -140,7 +140,7 @@ class NearestRotationTargetPositionFactory(val config: PositionFactoryConfigurat
"daLine",
ModuleDebug.DebuggedLine(Line(
config.eyePos,
currentRotation.rotationVec
currentRotation.directionVector
), Color4b(0, 0, 255, 255))
)

Expand Down

0 comments on commit 2ca2f75

Please sign in to comment.