Skip to content

Commit dfacc21

Browse files
committed
Gaussian rotation speed calculation
1 parent 5269725 commit dfacc21

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

common/src/main/kotlin/com/lambda/config/groups/IRotationConfig.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ interface IRotationConfig {
2525
* Ticks to rotate back to the actual rotation.
2626
*/
2727
val resetTicks: Int
28+
29+
val mean: Double
30+
val derivation: Double
2831
}

common/src/main/kotlin/com/lambda/config/groups/RotationSettings.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.lambda.config.groups
22

33
import com.lambda.config.Configurable
44
import com.lambda.interaction.rotation.RotationMode
5-
import kotlin.math.max
6-
import kotlin.math.min
5+
import kotlin.math.PI
6+
import kotlin.math.cos
7+
import kotlin.math.ln
8+
import kotlin.math.sqrt
79
import kotlin.random.Random
810

911
class RotationSettings(
@@ -13,19 +15,18 @@ class RotationSettings(
1315
override var rotationMode by c.setting("Mode", RotationMode.SYNC, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera", vis)
1416
override val keepTicks by c.setting("Keep Rotation", 3, 1..10, 1, "Ticks to keep rotation", " ticks", vis)
1517
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", " ticks", vis)
18+
override var mean by c.setting("Mean", 90.0, 1.0..180.0, 0.1, "Average rotation speed", "", vis)
19+
override var derivation by c.setting("Standard Deviation", 10.0, 0.0..100.0, 0.1, "Spread of rotation speeds", "", vis)
1620

17-
var r1 by c.setting("Turn Speed 1", 70.0, 1.0..180.0, 0.1, "Rotation Speed 1", "", vis)
18-
var r2 by c.setting("Turn Speed 2", 110.0, 1.0..180.0, 0.1, "Rotation Speed 2", "", vis)
19-
20-
override val turnSpeed get() = Random.nextDouble(min(r1, r2), max(r1, r2) + 0.01)
21+
override val turnSpeed get() = nextGaussian(mean, derivation)
2122

2223
var speedMultiplier = 1.0
2324

24-
fun slowdownIf(flag: Boolean) {
25-
speedMultiplier = (if (flag) 0.0 else 1.0)
26-
.coerceIn(
27-
speedMultiplier - 0.3, // slowdown faster
28-
speedMultiplier + 0.15 // accelerate slower
29-
)
25+
private fun nextGaussian(mean: Double = 0.0, standardDeviation: Double = 1.0): Double {
26+
val u1 = Random.nextDouble()
27+
val u2 = Random.nextDouble()
28+
29+
val randStdNormal = sqrt(-2.0 * ln(u1)) * cos(2.0 * PI * u2)
30+
return mean + standardDeviation * randStdNormal
3031
}
3132
}

0 commit comments

Comments
 (0)