Fix preffered rotation snapping

This commit is contained in:
Erimel committed 2026-11-12 16:07:14 -05:00
1 parent 9942e843ff
commit 8c1478d3e4
3 files changed
+6 -12

No files matched your search

@@ -115,7 +115,7 @@ val BODY_PART_CONSTRAINT_MAP: BodyPartMap<Constraint> = BodyPartMap(
BodyPart.LEFT_LOWER_LEG to LooseHingeConstraint(
-150f * FastMath.DEG_TO_RAD,
6f * FastMath.DEG_TO_RAD,
50f * FastMath.DEG_TO_RAD,
65f * FastMath.DEG_TO_RAD,
),
BodyPart.LEFT_FOOT to LooseHingeConstraint(
-45f * FastMath.DEG_TO_RAD,
@@ -132,7 +132,7 @@ val BODY_PART_CONSTRAINT_MAP: BodyPartMap<Constraint> = BodyPartMap(
BodyPart.RIGHT_LOWER_LEG to LooseHingeConstraint(
-150f * FastMath.DEG_TO_RAD,
6f * FastMath.DEG_TO_RAD,
50f * FastMath.DEG_TO_RAD,
65f * FastMath.DEG_TO_RAD,
),
BodyPart.RIGHT_FOOT to LooseHingeConstraint(
-45f * FastMath.DEG_TO_RAD,
@@ -41,15 +41,9 @@ fun adjustToPreferredRotations(
) {
val changedBodyParts = mutableSetOf<BodyPart>()
for (goal in goals) {
val distanceFromTarget = chainDistanceFromTarget(mutableComputedSkeleton, goal.chain, goal.target).toDouble()
val chainEndToTarget = chainDistanceFromTarget(mutableComputedSkeleton, goal.chain, goal.target).toDouble()
val maxChainLength = chainOffsetsLength(mutableComputedSkeleton, goal.chain)
val chainStartToTarget = (goal.target - requireBone(mutableComputedSkeleton, goal.chain.first()).headPosition).len()
val distanceRatio = if (chainStartToTarget < maxChainLength) {
(distanceFromTarget / maxChainLength).coerceAtMost(1.0)
} else {
// Unreachable
continue
}
val distanceRatio = (chainEndToTarget / maxChainLength).coerceAtMost(1.0)
val t = (log(PREFERRED_ROTATION_START_BIAS + (distanceRatio * PREFERRED_ROTATION_START_BIAS_MULTIPLIER), PREFERRED_ROTATION_START_BIAS) - 1).toFloat()
for (bodyPart in goal.chain) {
val preferredRotation = BODY_PART_PREFERRED_ROTATION[bodyPart] ?: continue
@@ -8,8 +8,8 @@ import solarxr_protocol.datatypes.BodyPart
// Neck bends less when looking up
private const val UP_RATIO = 0.74f
// Neck bends slightly more when looking down.
private const val DOWN_RATIO = 1.14f
// Neck bends more when looking down.
private const val DOWN_RATIO = 1.24f
/**
* Guesses where the neck is supposed to be when the user has a head tracker but no neck tracker.