From 8ebb104bb3f6a365db416f66b872bb7ef8c368ca Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Thu, 25 Apr 2024 10:37:45 +1000 Subject: [PATCH] Isometric projections --- fourDShape.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/fourDShape.js b/fourDShape.js index d42ac17..e5d125e 100644 --- a/fourDShape.js +++ b/fourDShape.js @@ -20,6 +20,7 @@ class FourDShape extends THREE.Group { this.node_scale = 1; this.link_scale = 1; this.hyperplane = HYPERPLANE; + this.projection = 1; this.initShapes(); } @@ -100,15 +101,6 @@ class FourDShape extends THREE.Group { } - fourDtoV3_old(x, y, z, w, rotations) { - const v4 = new THREE.Vector4(x, y, z, w); - for ( const m4 of rotations ) { - v4.applyMatrix4(m4); - } - const k = this.fourDscale(v4.w); - return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k); - } - fourDscale(w) { return this.hyperplane / ( this.hyperplane + w ); } @@ -121,11 +113,24 @@ class FourDShape extends THREE.Group { return v4; } - fourDtoV3(v4) { + renderNodePerspective(n, rotations) { + const v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations); const k = this.fourDscale(v4.w); - return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k); + const position = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k); + const s4 = k * this.node_scale * NODE_FORESHORTENING; + const scale = new THREE.Vector3(s4, s4, s4); + return { position: position, scale: scale } } + renderNodeIsometric(n, rotations) { + const v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations); + const position = new THREE.Vector3(v4.x, v4.y + v4.w, v4.z); + const s4 = this.node_scale; + const scale = new THREE.Vector3(s4, s4, s4); + return { position: position, scale: scale } + } + + initShapes() { for( const n of this.nodes4 ) { const k = this.fourDscale(n.w); @@ -151,14 +156,10 @@ class FourDShape extends THREE.Group { render3(rotations, nodes_show, links_show) { this.scalev3 = new THREE.Vector3(this.node_scale, this.node_scale, this.node_scale); for( const n of this.nodes4 ) { - const v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations); - const k = this.fourDscale(v4.w); - const v3 = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k); - const s4 = k * this.node_scale * NODE_FORESHORTENING; - const s3 = new THREE.Vector3(s4, s4, s4); - this.nodes3[n.id].v3 = v3; - this.nodes3[n.id].object.position.copy(v3); - this.nodes3[n.id].object.scale.copy(s3); + const node3d = this.renderNodeIsometric(n, rotations); + this.nodes3[n.id].v3 = node3d.position; + this.nodes3[n.id].object.position.copy(node3d.position); + this.nodes3[n.id].object.scale.copy(node3d.scale); this.nodes3[n.id].object.visible = ( !nodes_show || n.label in nodes_show ); } for( const l of this.links ) {