-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Camera interpolation on fixed update (#2868)
Fixes an issue spotted by @mattjennings where the camera is not interpolated during fixed update causing noticeable stutter on the screen with camera locked strategies
- Loading branch information
Showing
7 changed files
with
73 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Transform } from '../Math/transform'; | ||
|
||
/** | ||
* Blend 2 transforms for interpolation | ||
*/ | ||
export function blendTransform(oldTx: Transform, newTx: Transform, blend: number, target?: Transform): Transform { | ||
let interpolatedPos = newTx.pos; | ||
let interpolatedScale = newTx.scale; | ||
let interpolatedRotation = newTx.rotation; | ||
|
||
interpolatedPos = newTx.pos.scale(blend).add( | ||
oldTx.pos.scale(1.0 - blend) | ||
); | ||
interpolatedScale = newTx.scale.scale(blend).add( | ||
oldTx.scale.scale(1.0 - blend) | ||
); | ||
// Rotational lerp https://stackoverflow.com/a/30129248 | ||
const cosine = (1.0 - blend) * Math.cos(oldTx.rotation) + blend * Math.cos(newTx.rotation); | ||
const sine = (1.0 - blend) * Math.sin(oldTx.rotation) + blend * Math.sin(newTx.rotation); | ||
interpolatedRotation = Math.atan2(sine, cosine); | ||
|
||
const tx = target ?? new Transform(); | ||
tx.setTransform(interpolatedPos, interpolatedRotation, interpolatedScale); | ||
return tx; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters