Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ class MatrixHandler(
fun draw() {
dynamicFOV += camera.view.view.fovMultiplier

shaking.draw()
val update = shaking.update()
val fov = calculateFOV()
val view = camera.view.view
val eyePosition = view.eyePosition
val front = view.front
if (upToDate && eyePosition == this.eyePosition && front == this.front && fov == previousFOV && shaking.isEmpty) {
if (!update && upToDate && eyePosition == this.eyePosition && front == this.front && fov == previousFOV && shaking.isEmpty) {
return
}
this.eyePosition = eyePosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,55 @@ import de.bixilon.kutil.avg.FloatAverage
import de.bixilon.kutil.time.TimeUtil.millis
import de.bixilon.minosoft.config.profile.profiles.rendering.camera.shaking.ShakingC
import de.bixilon.minosoft.gui.rendering.camera.Camera
import de.bixilon.minosoft.gui.rendering.renderer.drawable.Drawable
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import kotlin.math.PI
import kotlin.math.sin

class CameraShaking(
private val camera: Camera,
private val profile: ShakingC,
) : Drawable {
) {
private var rotation = 0.0f
private var strength = FloatAverage(5 * ProtocolDefinition.TICK_TIME * 1_000_000L, 1.0f)
private val speed = FloatAverage(5 * ProtocolDefinition.TICK_TIME * 1_000_000L, 0.0f)
private var previous_velocity = 0.0f
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
private var strength = 0.02f
private val speed = FloatAverage(10 * ProtocolDefinition.TICK_TIME * 1_000_000L, 0.0f)
private val physics = camera.context.connection.camera.entity.physics

val isEmpty: Boolean get() = rotation == 0.0f

override fun draw() {
this.strength += 1.0f
val strength = this.strength.avg * profile.amplifier // strength affects how far it goes
fun update(): Boolean {
if(!this.physics.onGround){
this.speed += 0.0f
this.rotation = 0.0f
return false
}
val time = millis()
this.rotation = bobbing(time,10f,this.strength)
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
this.strength = 0.02f
return true
}

val physics = camera.context.connection.camera.entity.physics
val velocity = physics.velocity.xz.length2().toFloat() // velocity affects how quick it goes
if (velocity > 0.003 && physics.onGround) {
private fun bobbing(time: Long,frequency: Float, intensity: Float): Float {
var velocity = this.physics.velocity.xz.length2().toFloat() // velocity affects how quick it goes
if(this.previous_velocity != 0.0f){
velocity = this.previous_velocity + (velocity - this.previous_velocity) * 0.25f // interpolate
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
this.speed += velocity
} else {
this.speed += 0.0f // TODO: remove this, kutil 1.21
}else{
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
this.speed += 0.0f
}
val time = (millis() % 100L).toFloat() / 100.0f

this.rotation = sin(time * minOf(this.speed.avg, 0.5f) / 3.0f) * strength * 0.03f
this.previous_velocity = velocity
var seconds = (time/1000.0).toDouble()
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
val minimum_speed = 0.14f
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
return (sin(seconds * frequency).toFloat() * minOf(this.speed.avg, 0.1f) * intensity) / minimum_speed
}

fun onDamage() {
strength += 1000.0f
speed += 0.05f
//TODO: verify this properly, frequency may need to be changed as well
this.strength += 1f
Comment thread
turtiustrek marked this conversation as resolved.
Outdated
}

fun transform(): Mat4? {
if (rotation == 0.0f) return null
if (this.rotation == 0.0f) return null
return Mat4()
.rotateAssign(rotation, Vec3(0, 0, 1))
.rotateAssign(this.rotation, Vec3(0, 0, 1))
}
}