Blaarkies / ksp-visual-calculator

Online tool for Kerbal Space Program that helps players determine delta-v requirements for a mission, and what type of comms dishes a certain satellite requires.
https://ksp-visual-calculator.blaarkies.com
Other
23 stars 0 forks source link

Improve camera performance #46

Closed Blaarkies closed 1 year ago

Blaarkies commented 2 years ago

Current camera logic determine where planets/moons are place by adjusting their left: 420px and top: 69px CSS values. This is affected by camera position and scale, meaning that every object in universe is update when the camera moves.

A possibly more efficient way of handling this by using multiple layers of position: absolute and position: relative, and setting the position of planets with a left: 42% to position them on the camera backboard layer

By deferring this logic to the CSS engine, simple camera updates could become smoother on Firefox and mobile.

Some pseudo code of how this fits together:

<div class="camera-backboard"  style="position: absolute; 
            left: camera.x; 
            top: camera.y;
            width: camera.scale  * 1000px;
            height: camera.scale * 1000px;">

    <div style="position: relative">

        <div class="planet" style="position: absolute; 
                left: (body.x / 10)%; 
                top: (body.y / 10)%">
        </div>
    </div>
</div>