feat: procedural fish with wandering AI & parallax camera (#7, #5)

This commit is contained in:
2026-10-06 19:34:56 +00:00
parent b7489af394
commit c803ca97d3
3 changed files with 289 additions and 1 deletions
+18 -1
View File
@@ -2,6 +2,8 @@ import * as THREE from "three";
import { createTank } from "./scene/Tank";
import { createWater } from "./scene/Water";
import { setupLighting } from "./scene/Lighting";
import { createFishSchool } from "./scene/Fish";
import { createParallaxCamera } from "./scene/Camera";
const canvas = document.querySelector<HTMLCanvasElement>("#aquarium");
if (!canvas) {
@@ -30,6 +32,15 @@ camera.lookAt(0, 1.2, 0);
setupLighting(scene, renderer);
createTank(scene);
const water = createWater(scene);
const fishSchool = createFishSchool(scene, 6);
const parallax = createParallaxCamera(camera);
// Mouse tracking (normalized to -1..1)
let mouseX = 0, mouseY = 0;
window.addEventListener("mousemove", (e) => {
mouseX = (e.clientX / window.innerWidth) * 2 - 1;
mouseY = (e.clientY / window.innerHeight) * 2 - 1;
});
// Resize handling
function resize(): void {
@@ -45,10 +56,16 @@ window.addEventListener("resize", resize);
// Render loop
const startTime = performance.now();
let lastFrameTime = performance.now();
function animate(): void {
requestAnimationFrame(animate);
const time = (performance.now() - startTime) / 1000;
const now = performance.now();
const time = (now - startTime) / 1000;
const dt = Math.min((now - lastFrameTime) / 1000, 0.1);
lastFrameTime = now;
water.update(time);
fishSchool.update(dt, time);
parallax.update(mouseX, mouseY, time, dt);
renderer.render(scene, camera);
}
animate();