Skip to content

Commit 4c78740

Browse files
committed
Update help.ts, me.ts, render.ts, class.ts
1 parent 595691c commit 4c78740

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

class.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
namespace Fx {
3+
4+
export const RADIANTOTHETA = 40 as any as Fx8;
35

46
export function isin(theta: Fx8) {
5-
return (Math.isin((theta as any as number * 0.2) & 0xff) - 128) as any as Fx8;
7+
const sin = Math.isin((theta as any as number * 0.2) & 0xff);
8+
return (sin - 0x80) as any as Fx8;
69
}
710

811
export function icos(theta: Fx8) {
9-
return (Math.isin((theta as any as number * 0.2 + 64) & 0xff) - 128) as any as Fx8;
12+
const cos = Math.isin((theta as any as number * 0.2 + 0x40) & 0xff);
13+
return (cos - 0x80) as any as Fx8;
1014
}
1115

1216
export function sqrt(x: Fx8): Fx8 {
@@ -25,7 +29,7 @@ class polyview {
2529
public loop() {
2630
this.__prop_upd = control.eventContext().registerFrameHandler(scene.PRE_RENDER_UPDATE_PRIORITY, () => {
2731
const delta = Fx8(control.eventContext().deltaTime)
28-
this.motionUpdateRot(delta), this.motionUpdatePos(delta), this.motionUpdateWave();
32+
this.motionUpdateRot(delta); this.motionUpdatePos(delta); this.motionUpdateWave();
2933
this.__onLoop();
3034
});
3135
}
@@ -54,19 +58,22 @@ class polyview {
5458

5559
protected wave_sinX: Fx8; protected wave_sinY: Fx8; protected wave_sinZ: Fx8;
5660
protected wave_cosX: Fx8; protected wave_cosY: Fx8; protected wave_cosZ: Fx8;
61+
//protected wave_sqrtX: Fx8; protected wave_sqrtY: Fx8; protected wave_sqrtZ: Fx8;
5762
set wave(v: Polymesh.Wave3) {
5863
if (!v || v == null) {
5964
this.wave_sinX = null; this.wave_sinY = null; this.wave_sinZ = null;
6065
this.wave_cosX = null; this.wave_cosY = null; this.wave_cosZ = null;
66+
//this.wave_sqrtX = null; this.wave_sqrtY = null; this.wave_sqrtZ = null;
6167
return
6268
}
63-
this.wave_sinX = Fx8(v.sinX); this.wave_sinY = Fx8(v.sinY); this.wave_sinZ = Fx8(v.sinZ);
64-
this.wave_cosX = Fx8(v.cosX); this.wave_cosY = Fx8(v.cosY); this.wave_cosZ = Fx8(v.cosZ);
69+
this.wave_sinX = Fx.mul(Fx8(v.sinX), Fx.RADIANTOTHETA); this.wave_sinY = Fx.mul(Fx8(v.sinY), Fx.RADIANTOTHETA); this.wave_sinZ = Fx.mul(Fx8(v.sinZ), Fx.RADIANTOTHETA);
70+
this.wave_cosX = Fx.mul(Fx8(v.cosX), Fx.RADIANTOTHETA); this.wave_cosY = Fx.mul(Fx8(v.cosY), Fx.RADIANTOTHETA); this.wave_cosZ = Fx.mul(Fx8(v.cosZ), Fx.RADIANTOTHETA);
71+
//this.wave_sqrtX = Fx8(v.sqrtX); this.wave_sqrtY = Fx8(v.sqrtY); this.wave_sqrtZ = Fx8(v.sqrtZ);
6572
}
6673
get wave(): Polymesh.Wave3 {
6774
return {
68-
sinX: Fx.toFloat(this.wave_sinX) * Polymesh.REDUSPOWER, sinY: Fx.toFloat(this.wave_sinY) * Polymesh.REDUSPOWER, sinZ: Fx.toFloat(this.wave_sinZ) * Polymesh.REDUSPOWER,
69-
cosX: Fx.toFloat(this.wave_cosX) * Polymesh.REDUSPOWER, cosY: Fx.toFloat(this.wave_cosY) * Polymesh.REDUSPOWER, cosZ: Fx.toFloat(this.wave_cosZ) * Polymesh.REDUSPOWER,
75+
sinX: (Fx.toFloat(this.wave_sinX) /* * Fx.toFloat(this.wave_sqrtX) */) * Polymesh.REDUSPOWER, sinY: (Fx.toFloat(this.wave_sinY) /* * Fx.toFloat(this.wave_sqrtY) */) * Polymesh.REDUSPOWER, sinZ: (Fx.toFloat(this.wave_sinZ) /* * Fx.toFloat(this.wave_sqrtZ) */) * Polymesh.REDUSPOWER,
76+
cosX: (Fx.toFloat(this.wave_cosX) /* * Fx.toFloat(this.wave_sqrtX) */) * Polymesh.REDUSPOWER, cosY: (Fx.toFloat(this.wave_cosY) /* * Fx.toFloat(this.wave_sqrtY) */) * Polymesh.REDUSPOWER, cosZ: (Fx.toFloat(this.wave_cosZ) /* * Fx.toFloat(this.wave_sqrtZ) */) * Polymesh.REDUSPOWER,
7077
}
7178
}
7279

help.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ namespace Polymesh {
4343
tmp = dx * wave.cosY + dz * wave.sinY; dz = -dx * wave.sinY + dz * wave.cosY; dx = tmp; // --- rotate around y ---
4444
tmp = dx * wave.cosZ - dy * wave.sinZ; dy = dx * wave.sinZ + dy * wave.cosZ; dx = tmp; // --- rotate around z ---
4545

46+
const normalv = 0.1 / Math.sqrt((dx * dx) + (dy * dy) + (dz * dz))
47+
// normal vector
48+
dx += (dx === 0 ? 0 : normalv);
49+
dy += (dy === 0 ? 0 : normalv);
50+
dz += (dz === 0 ? 0 : normalv);
51+
4652
// move back to real position
4753
return {
4854
x: dx + pivot.x,
@@ -61,6 +67,12 @@ namespace Polymesh {
6167
tmp = dx * wave.cosY + dz * wave.sinY, dz = -dx * wave.sinY + dz * wave.cosY, dx = tmp; // --- rotate around y ---
6268
tmp = dy * wave.cosX - dz * wave.sinX, dz = dy * wave.sinX + dz * wave.cosX, dy = tmp; // --- rotate around x ---
6369
tmp = dx * wave.cosZ - dy * wave.sinZ, dy = dx * wave.sinZ + dy * wave.cosZ, dx = tmp; // --- rotate around z ---
70+
71+
const normalv = 0.1 / Math.sqrt((dx * dx) + (dy * dy) + (dz * dz))
72+
// normal vector
73+
dx += (dx === 0 ? 0 : normalv);
74+
dy += (dy === 0 ? 0 : normalv);
75+
dz += (dz === 0 ? 0 : normalv);
6476

6577
return {
6678
x: dx + pivot.x,
@@ -254,7 +266,7 @@ namespace Polymesh {
254266

255267
export const meshDepthZ = (msh: polymesh) => {
256268
if (msh.isDel()) return NaN;
257-
return rotatePoint3Dyxz(msh.pos, Polymesh.camview.pos, Polymesh.camview.wave).z;
269+
return rotatePoint3Dyxz(msh.pos, camview.pos, camview.wave).z;
258270
}
259271

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

me.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace Polymesh {
1616
export interface Wave3 {
1717
sinX: number, sinY: number, sinZ: number,
1818
cosX: number, cosY: number, cosZ: number,
19-
//sqrtX?: number, sqrtY?: number, sqrtZ?: number,
19+
sqrtX?: number, sqrtY?: number, sqrtZ?: number,
2020
}
2121

2222
const __meshes: polymesh[] = [];
2323
const __meshes_refs: {[id: number]: number[]} = {};
2424
const __meshes_null_refs: number[] = [];
2525
const __meshes_null_refh: {[id: number]: boolean} = {};
2626
const __meshes_kinds: {[kind: number]: polymesh[]} = {};
27-
export const PHI = 1.6180339887, NORMAL_DIST = 1.665, LOD_DIST = 1.2, REDUSPOWER = ((PHI - 1) * Math.PI)
27+
export const PHI = 1.6180339887, NORMAL_DIST = 1.665, LOD_DIST = 1.2, REDUSPOWER = (PHI - 1) * Math.PI
2828

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

render.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ namespace Polymesh {
5353
tmp = y * cosX - z * sinX, z = y * sinX + z * cosX, y = tmp; // --- rotate around x ---
5454
tmp = x * cosZ - y * sinZ, y = x * sinZ + y * cosZ, x = tmp; // --- rotate around z ---
5555

56-
const vsum = 0.1 / Math.sqrt((x * x) + (y * y) + (z * z))
56+
const normalv = 0.1 / Math.sqrt((x * x) + (y * y) + (z * z))
5757
// camera offset
58-
x += (x === 0 ? 0 : vsum);
59-
y += (y === 0 ? 0 : vsum);
60-
z += (z === 0 ? 0 : vsum);
58+
x += (x === 0 ? 0 : normalv);
59+
y += (y === 0 ? 0 : normalv);
60+
z += (z === 0 ? 0 : normalv);
6161
// Perspective
6262
const scale = Math.abs(dist) / (Math.abs(dist) + z);
6363
return {

0 commit comments

Comments
 (0)