Skip to content

Commit 112eccd

Browse files
committed
Update help.ts, me.ts, render.ts, class.ts
1 parent 2187f11 commit 112eccd

4 files changed

Lines changed: 58 additions & 25 deletions

File tree

class.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11

2+
namespace Fx {
3+
4+
export function isin(theta: Fx8) {
5+
return (Math.isin((theta as any as number * 0.2) & 0xff) - 128) as any as Fx8;
6+
}
7+
8+
export function icos(theta: Fx8) {
9+
return (Math.isin((theta as any as number * 0.2 + 64) & 0xff) - 128) as any as Fx8;
10+
}
11+
}
12+
213
class polyview {
314
protected __prop_upd: control.FrameCallback; __del: boolean; protected __unDel: boolean;
415

@@ -9,7 +20,7 @@ class polyview {
920
public loop() {
1021
this.__prop_upd = control.eventContext().registerFrameHandler(scene.PRE_RENDER_UPDATE_PRIORITY, () => {
1122
const delta = Fx8(control.eventContext().deltaTime)
12-
this.motionUpdateRot(delta), this.motionUpdatePos(delta);
23+
this.motionUpdateRot(delta), this.motionUpdatePos(delta), this.motionUpdateWave();
1324
this.__onLoop();
1425
});
1526
}
@@ -32,9 +43,28 @@ class polyview {
3243
del() {
3344
if (this.__unDel) return;
3445
this.__del = true; control.eventContext().unregisterFrameHandler(this.__prop_upd);
46+
this.pos = null, this.rot = null, this.wave = null;
3547
this.__onDel();
3648
}
3749

50+
protected wave_sinX: Fx8; protected wave_sinY: Fx8; protected wave_sinZ: Fx8;
51+
protected wave_cosX: Fx8; protected wave_cosY: Fx8; protected wave_cosZ: Fx8;
52+
set wave(v: Polymesh.Wave3) {
53+
if (!v || v == null) {
54+
this.wave_sinX = null; this.wave_sinY = null; this.wave_sinZ = null;
55+
this.wave_cosX = null; this.wave_cosY = null; this.wave_cosZ = null;
56+
return
57+
}
58+
this.wave_sinX = Fx8(v.sinX); this.wave_sinY = Fx8(v.sinY); this.wave_sinZ = Fx8(v.sinZ);
59+
this.wave_cosX = Fx8(v.cosX); this.wave_cosY = Fx8(v.cosY); this.wave_cosZ = Fx8(v.cosZ);
60+
}
61+
get wave(): Polymesh.Wave3 {
62+
return {
63+
sinX: Fx.toFloat(this.wave_sinX) * Polymesh.THETA2RADIAN, sinY: Fx.toFloat(this.wave_sinY) * Polymesh.THETA2RADIAN, sinZ: Fx.toFloat(this.wave_sinZ) * Polymesh.THETA2RADIAN,
64+
cosX: Fx.toFloat(this.wave_cosX) * Polymesh.THETA2RADIAN, cosY: Fx.toFloat(this.wave_cosY) * Polymesh.THETA2RADIAN, cosZ: Fx.toFloat(this.wave_cosZ) * Polymesh.THETA2RADIAN,
65+
}
66+
}
67+
3868
protected rot_x: Fx8; protected rot_y: Fx8; protected rot_z: Fx8;
3969
protected rot_vx: Fx8; protected rot_vy: Fx8; protected rot_vz: Fx8;
4070
protected rot_ax: Fx8; protected rot_ay: Fx8; protected rot_az: Fx8;
@@ -87,6 +117,10 @@ class polyview {
87117
}
88118
}
89119

120+
protected motionUpdateWave() {
121+
this.wave_sinX = Fx.isin(this.rot_x), this.wave_sinY = Fx.isin(this.rot_y), this.wave_sinZ = Fx.isin(this.rot_z)
122+
this.wave_cosX = Fx.icos(this.rot_x), this.wave_cosY = Fx.icos(this.rot_y), this.wave_cosZ = Fx.icos(this.rot_z)
123+
}
90124
protected motionUpdatePos(delta: Fx8) {
91125
const zeroF = Fx8(0), oneF = Fx8(1)
92126
// Acceleration of position
@@ -333,7 +367,7 @@ class polymesh extends polyview {
333367
return this.points.map(v => {
334368
const vpoint = { x: this.pos.x + v.x, y: this.pos.y + v.y, z: this.pos.z + v.z };
335369
const vpivot = { x: this.pos.x + this.pivot.x, y: this.pos.y + this.pivot.y, z: this.pos.z + this.pivot.z };
336-
return f(Polymesh.rotatePoint3Dxyz(vpoint, vpivot, this.rot));
370+
return f(Polymesh.rotatePoint3Dxyz(vpoint, vpivot, this.wave));
337371
})
338372
};
339373

@@ -358,7 +392,7 @@ class polymesh extends polyview {
358392
}
359393

360394
__onDel() {
361-
this.faces_imgs_cache_ref = null, this.faces_imgs = null, this.faces = null, this.points = null, this.pivot = null, this.rot = null, this.pos = null, this.flag = null, this.data = null;
395+
this.faces_imgs_cache_ref = null, this.faces_imgs = null, this.faces = null, this.points = null, this.pivot = null, this.flag = null, this.data = null;
362396
Polymesh.__meshes_del(this);
363397
}
364398

help.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@ namespace Polymesh {
2626
return htxt;
2727
}
2828

29-
export const rotatePoint3Dxyz = (point: Vector3, pivot: Vector3, angle: Vector3): Vector3 => {
29+
export const makeWave = (angle: Vector3): Wave3 => ({
30+
cosX: Math.cos(angle.x), sinX: Math.sin(angle.x),
31+
cosY: Math.cos(angle.y), sinY: Math.sin(angle.y),
32+
cosZ: Math.cos(angle.z), sinZ: Math.sin(angle.z),
33+
})
34+
35+
export const rotatePoint3Dxyz = (point: Vector3, pivot: Vector3, wave: Wave3): Vector3 => {
3036
let tmp = 0
31-
const cosX = Math.cos(angle.x), sinX = Math.sin(angle.x);
32-
const cosY = Math.cos(angle.y), sinY = Math.sin(angle.y);
33-
const cosZ = Math.cos(angle.z), sinZ = Math.sin(angle.z);
3437
// move point with pivot to 1st place
3538
let dx = point.x - pivot.x;
3639
let dy = point.y - pivot.y;
3740
let dz = point.z - pivot.z;
3841

39-
tmp = dy * cosX - dz * sinX; dz = dy * sinX + dz * cosX; dy = tmp; // --- rotate around x ---
40-
tmp = dx * cosY + dz * sinY; dz = -dx * sinY + dz * cosY; dx = tmp; // --- rotate around y ---
41-
tmp = dx * cosZ - dy * sinZ; dy = dx * sinZ + dy * cosZ; dx = tmp; // --- rotate around z ---
42+
tmp = dy * wave.cosX - dz * wave.sinX; dz = dy * wave.sinX + dz * wave.cosX; dy = tmp; // --- rotate around x ---
43+
tmp = dx * wave.cosY + dz * wave.sinY; dz = -dx * wave.sinY + dz * wave.cosY; dx = tmp; // --- rotate around y ---
44+
tmp = dx * wave.cosZ - dy * wave.sinZ; dy = dx * wave.sinZ + dy * wave.cosZ; dx = tmp; // --- rotate around z ---
4245

4346
// move back to real position
4447
return {
@@ -48,19 +51,16 @@ namespace Polymesh {
4851
};
4952
};
5053

51-
export const rotatePoint3Dyxz = (point: Vector3, pivot: Vector3, angle: Vector3) => {
54+
export const rotatePoint3Dyxz = (point: Vector3, pivot: Vector3, wave: Wave3) => {
5255
let tmp = 0
53-
const cosX = Math.cos(angle.x), sinX = Math.sin(angle.x);
54-
const cosY = Math.cos(angle.y), sinY = Math.sin(angle.y);
55-
const cosZ = Math.cos(angle.z), sinZ = Math.sin(angle.z);
5656

5757
// Transform vertices
5858
let dx = point.x - pivot.x;
5959
let dy = point.y - pivot.y;
6060
let dz = point.z - pivot.z;
61-
tmp = dx * cosY + dz * sinY, dz = -dx * sinY + dz * cosY, dx = tmp; // --- rotate around y ---
62-
tmp = dy * cosX - dz * sinX, dz = dy * sinX + dz * cosX, dy = tmp; // --- rotate around x ---
63-
tmp = dx * cosZ - dy * sinZ, dy = dx * sinZ + dy * cosZ, dx = tmp; // --- rotate around z ---
61+
tmp = dx * wave.cosY + dz * wave.sinY, dz = -dx * wave.sinY + dz * wave.cosY, dx = tmp; // --- rotate around y ---
62+
tmp = dy * wave.cosX - dz * wave.sinX, dz = dy * wave.sinX + dz * wave.cosX, dy = tmp; // --- rotate around x ---
63+
tmp = dx * wave.cosZ - dy * wave.sinZ, dy = dx * wave.sinZ + dy * wave.cosZ, dx = tmp; // --- rotate around z ---
6464

6565
return {
6666
x: dx + pivot.x,
@@ -71,9 +71,6 @@ namespace Polymesh {
7171

7272
const normalLen3 = (n: number) => Math.sqrt((n * n) + (n * n) + (n * n))
7373

74-
export const rotatePointLen3D = (len: number, pivot: Vector3, angle: Vector3, code: Buffer): Vector3 =>
75-
rotatePoint3Dxyz({ x: pivot.x + (code[0] ? normalLen3(len) : 0), y: pivot.y + (code[1] ? -normalLen3(len) : 0), z: pivot.z + (code[2] ? normalLen3(len) : 0)}, pivot, angle);
76-
7774
const computeNormal = (v0: Vector3_, v1: Vector3_, v2: Vector3_): Vector3 => {
7875
// make vector from triangle
7976
const u = {
@@ -257,7 +254,7 @@ namespace Polymesh {
257254

258255
export const meshDepthZ = (msh: polymesh) => {
259256
if (msh.isDel()) return NaN;
260-
return rotatePoint3Dyxz(msh.pos, Polymesh.camview.pos, Polymesh.camview.rot).z;
257+
return rotatePoint3Dyxz(msh.pos, Polymesh.camview.pos, Polymesh.camview.wave).z;
261258
}
262259

263260
export const meshDistZ = (msh: polymesh) => (Math.abs(dist) / (Math.abs(dist) + meshDepthZ(msh)))

me.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ namespace Polymesh {
88
export interface Motion3 { x: number, y: number, z: number, vx: number, vy: number, vz: number, ax: number, ay: number, az: number, fx: number, fy: number, fz: number }
99
export interface Vector3 { x: number, y: number, z: number }
1010
export interface Vector3_ { x: number, y: number, z: number, x_: number, y_: number, z_: number }
11+
export interface Wave3 { sinX: number, sinY: number, sinZ: number, cosX: number, cosY: number, cosZ: number }
1112

1213
const __meshes: polymesh[] = [];
1314
const __meshes_refs: {[id: number]: number[]} = {};
1415
const __meshes_null_refs: number[] = [];
1516
const __meshes_null_refh: {[id: number]: boolean} = {};
1617
const __meshes_kinds: {[kind: number]: polymesh[]} = {};
17-
export const PHI = 1.6180339887, NORMAL_DIST = 1.665, LOD_DIST = 1.2
18+
export const PHI = 1.6180339887, NORMAL_DIST = 1.665, LOD_DIST = 1.2, THETA2RADIAN = ((PHI - 1) * Math.PI)
1819

1920
export const camview = new polyview(true);
2021
export let zoom = 1, sort = 0x0, dist = 150, fardist = 0;

render.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ namespace Polymesh {
3838

3939
const centerX = Math.idiv(output.width, 2), centerY = Math.idiv(output.height, 2);
4040

41+
const cosX = camview.wave.cosY, sinX = camview.wave.sinY;
42+
const cosY = camview.wave.cosX, sinY = camview.wave.sinX;
43+
const cosZ = camview.wave.cosZ, sinZ = camview.wave.sinZ;
44+
4145
let tmp = 0
42-
const cosX = Math.cos(camview.rot.x), sinX = Math.sin(camview.rot.x);
43-
const cosY = Math.cos(camview.rot.y), sinY = Math.sin(camview.rot.y);
44-
const cosZ = Math.cos(camview.rot.z), sinZ = Math.sin(camview.rot.z);
4546

4647
// Transform vertices
4748
const rotated = msh.pointCam((v) => {

0 commit comments

Comments
 (0)