Isometric projections

feature-alt-projections
Mike Lynch 2024-04-25 10:37:45 +10:00
parent 1ec7955861
commit 8ebb104bb3
1 changed files with 20 additions and 19 deletions

View File

@ -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 ) {