Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Fix waveform shaking in presentation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislo27 committed Oct 1, 2017
1 parent 087e382 commit 9beeef9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions core/src/main/kotlin/io/github/chrislo27/rhre3/editor/Editor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,26 @@ class Editor(val main: RHRE3Application, stageCamera: OrthographicCamera)
camera.position.y = 1f
camera.zoom = MathUtils.lerp(camera.zoom, if (isGameBoundariesInViews) 1.5f else 1f,
Gdx.graphics.deltaTime * 6.5f)
val oldCameraX = camera.position.x
val oldCameraY = camera.position.y
var adjustedCameraX = oldCameraX
var adjustedCameraY = oldCameraY
if (remix.playState == PlayState.PLAYING && remix.currentShakeEntities.isNotEmpty()) {
val shakeValue = remix.currentShakeEntities.fold(1f) { acc, it ->
acc * ShakeEntity.getShakeIntensity(it.semitone)
}
val intensity = 0.125f
val oldX = camera.position.x
val oldY = camera.position.y

camera.position.y += intensity * MathUtils.randomSign() * MathUtils.random(shakeValue)
camera.position.x += intensity * MathUtils.randomSign() * MathUtils.random(shakeValue) *
(ENTITY_HEIGHT / ENTITY_WIDTH)

camera.update()

camera.position.x = oldX
camera.position.y = oldY
adjustedCameraX = camera.position.x
adjustedCameraY = camera.position.y
camera.position.x = oldCameraX
camera.position.y = oldCameraY
} else {
camera.update()
}
Expand Down Expand Up @@ -398,10 +402,13 @@ class Editor(val main: RHRE3Application, stageCamera: OrthographicCamera)
val h = if (isPresentationMode) Math.abs(rawH) else rawH.coerceIn(-2f, 2f)
val width = viewportWidth / fineness.toFloat() * camera.zoom
if (!isPresentationMode) {
batch.fillRect((camera.position.x - viewportWidth / 2 * camera.zoom) + x * width, centre - h / 2,
width, h)
batch.fillRect((camera.position.x - viewportWidth / 2 * camera.zoom) + x * width,
centre - h / 2, width, h)
} else {
batch.fillRect((camera.position.x - viewportWidth / 2 * camera.zoom) + x * width, -3f, width, h / 2)
val cameraAdjX = (oldCameraX - adjustedCameraX)
val cameraAdjY = (oldCameraY - adjustedCameraY)
batch.fillRect((camera.position.x - cameraAdjX - viewportWidth / 2 * camera.zoom) + x * width,
-3f - cameraAdjY, width, h / 2)
}
}

Expand Down

0 comments on commit 9beeef9

Please sign in to comment.