Skip to content

Commit

Permalink
camera shaking: fine tune more
Browse files Browse the repository at this point in the history
  • Loading branch information
Bixilon committed May 28, 2023
1 parent 17c48d9 commit dc53209
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CameraShaking(
private val profile: ShakingC,
) {
private var rotation = 0.0f
private val speed = FloatAverage(10 * ProtocolDefinition.TICK_TIME * 1_000_000L, 0.0f)
private val speed = FloatAverage(5 * ProtocolDefinition.TICK_TIME * 1_000_000L, 0.0f)
private val physics = camera.context.connection.camera.entity.physics

val isEmpty: Boolean get() = rotation == 0.0f
Expand Down Expand Up @@ -57,15 +57,14 @@ class CameraShaking(
}
val time = millis()
this.speed += this.physics.velocity.xz.length2().toFloat() // velocity affects how quick it goes
val speed = this.speed.avg
val speed = minOf(this.speed.avg, 0.25f)
return bobbing(time, speed, FREQUENCY * profile.speed, STRENGTH * profile.intensity)
}

private fun bobbing(time: Long, speed: Float, frequency: Float, intensity: Float): Float {
val seconds = time / 1000.0

val sin = sin(seconds * frequency).toFloat()
val speed = minOf(this.speed.avg, 0.25f)
return (sin * speed * intensity) / MINIMUM_SPEED
}

Expand All @@ -81,11 +80,12 @@ class CameraShaking(
fun transform(): Mat4? {
if (this.rotation == 0.0f) return null
return Mat4()
.rotateAssign(this.rotation, Vec3(0, 0, 1))
.rotateAssign(this.rotation, ROTATION)
}

companion object {
private const val STRENGTH = 0.001f
private val ROTATION = Vec3(0, 0, 1)
private const val STRENGTH = 0.002f
private const val FREQUENCY = 10.0f
private const val MINIMUM_SPEED = 0.1f
}
Expand Down

0 comments on commit dc53209

Please sign in to comment.