Skip to content

Commit

Permalink
Minor globe improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Nov 19, 2024
1 parent 9674cdf commit c43a8b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/World/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ function maximizeDistance(Collection $points)
$targets = $result->take(-2);

$distance = $this->distance($targets->pop(), $point);

if ($targets->isNotEmpty()) {
$distance += $this->distance($targets->pop(), $point);
$distance = $distance / 2;
}

return $distance;
Expand Down
15 changes: 13 additions & 2 deletions resources/js/globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (! WebGL.isWebGL2Available()) {
}

const node = document.getElementById('globe-visualization');
// const debug_node = document.getElementById('debug');
const points = JSON.parse(node.dataset.points);

const colorInterpolator = t => `rgba(255, 210, 210, ${ 1 - t })`;
Expand Down Expand Up @@ -94,7 +95,13 @@ function ease(k) {
}

function easeInOut (frame, frames, min, max) {
return min + (max - min) * Math.sin(Math.PI * (frame / frames)) * Math.sin(Math.PI * (frame / frames));
let eased = min + (max - min) * Math.sin(Math.PI * (frame / frames)) * Math.sin(Math.PI * (frame / frames));

if (frame > (frames /2 )) {
eased = Math.max(eased, default_z);
}

return eased;
}

function interpolate(from, to, tick, ticks) {
Expand All @@ -121,7 +128,7 @@ let frames_per_point = (60 * SECONDS_BETWEEN_POINTS); // Assume 60 fps at first
let last_timestamp = 0;
let current_z = default_z;
let last_z = default_z;
let fps = 0;
let fps = 60;

function move(frame)
{
Expand Down Expand Up @@ -178,6 +185,10 @@ function pause(frame)
fps = 1 / (timestamp - last_timestamp);
last_timestamp = timestamp;

// if (debug_node) {
// debug_node.innerText = `${ camera.position.z.toFixed(2) } (${ Math.round(fps) } fps)`;
// }

renderer.render(scene, camera);
requestAnimationFrame(animate);
})();
3 changes: 3 additions & 0 deletions resources/views/world/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

<x-slot:before>
<div id="globe-visualization" class="w-full h-32 -mb-4 sm:h-40 md:h-56 lg:h-96" data-points="{{ json_encode($points) }}"></div>
@env('local')
<div id="debug" class="absolute top-4 right-4 bg-red-800 text-white p-4 rounded"></div>
@endenv
</x-slot:before>

<x-markdown :file="base_path('README.md')" sidebar />
Expand Down

0 comments on commit c43a8b1

Please sign in to comment.