From 54c34ca3051743fd3f1c02f73a321299af456b8a Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 1 Apr 2023 00:15:05 -0500 Subject: attempt implementing convex hull algorithm --- src/Terrain.js | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/Terrain.js (limited to 'src/Terrain.js') diff --git a/src/Terrain.js b/src/Terrain.js new file mode 100644 index 0000000..a51c0a3 --- /dev/null +++ b/src/Terrain.js @@ -0,0 +1,139 @@ +import { Mat3, Vec3, Point, RandomNormal, Shape, ConvexHull } from './Geometry.js'; + + +export function RandomPoints(n) { + const points = []; + for (let i=0; i threshold) { + return true; + } + return false; + } + + move() { + const matrix = new Mat3().rotation(this.axis, this.speed * 0.01 * Math.PI); + for (let i=0; i maxDot) { + maxDot = d; + index = i; + } + } + if (index == -1) { + console.error("no closest point", point); + } + points[index].push(point); + } + + const plates = []; + for (let p of points) { + plates.push(new Plate(p)); + } + return plates; + } + + update() { + for (let plate of this.plates) { + plate.move(); + } + } + + render(ct, view) { + for (let plate of this.plates) { + plate.render(ct, view); + } + } +} -- cgit v1.2.1