class Engine02 {
constructor(row, col, iter) {
this._row = row;
this._col = col;
this._iter = iter;
}
row = () => this._row;
col = () => this._col;
iter = () => this._iter;
alpha = () => alpha;
beta = () => beta;
fov = () => fov;
dist = () => dist;
rows = () => rows;
cols = () => cols;
cosAlpha = () => Math.cos(this.alpha() * Math.PI / 180);
sinAlpha = () => Math.sin(this.alpha() * Math.PI / 180);
cosBeta = () => Math.cos(this.beta() * Math.PI / 180);
sinBeta = () => Math.sin(this.beta() * Math.PI / 180);
camX = m(this, 'camX', () => this.dist() * this.cosAlpha() * this.cosBeta());
camY = m(this, 'camY', () => this.dist() * this.sinBeta());
camZ = m(this, 'camZ', () => this.dist() * this.sinAlpha() * this.cosBeta());
pixelSize = m(this, 'pixelSize', () => Math.tan(this.fov() * Math.PI / 180 / 2) / ((this.rows() - 1) / 2));
ux = () => -this.pixelSize() * this.sinAlpha();
uz = () => +this.pixelSize() * this.cosAlpha();
vx = () => +this.pixelSize() * this.cosAlpha() * this.sinBeta();
vy = () => -this.pixelSize() * this.cosBeta();
vz = () => +this.pixelSize() * this.sinAlpha() * this.sinBeta();
x0 = () => -this.cosAlpha() * this.cosBeta();
y0 = () => -this.sinBeta();
z0 = () => -this.sinAlpha() * this.cosBeta();
matX0 = m(this, 'matX0', () => this.x0() - this.cols() / 2 * this.ux() - this.rows() / 2 * this.vx() + 0.02);
matX1 = m(this, 'matX1', () => this.ux() * this.rows());
matX2 = m(this, 'matX2', () => this.vx() * this.cols());
matY0 = m(this, 'matY0', () => this.y0() - this.rows() / 2 * this.vy() + 0.05);
matY1 = m(this, 'matY1', () => 0);
matY2 = m(this, 'matY2', () => this.vy() * this.cols());
matZ0 = m(this, 'matZ0', () => this.z0() - this.cols() / 2 * this.uz() - this.rows() / 2 * this.vz());
matZ1 = m(this, 'matZ1', () => this.uz() * this.rows());
matZ2 = m(this, 'matZ2', () => this.vz() * this.cols());
nx = m(this, 'nx', () => {
return this.matX0() + this.col() * this.matX1() + this.row() * this.matX2();
});
ny = m(this, 'ny', () => {
return this.matY0() + this.row() * this.matY2();
});
nz = m(this, 'nz', () => {
return this.matZ0() + this.col() * this.matZ1() + this.row() * this.matZ2();
});
n = m(this, 'n', () => {
return Math.sqrt(this.nx() ** 2 + this.ny() ** 2 + this.nz() ** 2) * 1.6;
});
v = () => {
let res = 0;
for (let i=0; i<100; i++) {
const x = this.camX() + res * this.nx() / this.n();
const y = this.camY() + res * this.ny() / this.n();
const z = this.camZ() + res * this.nz() / this.n();
const sdf = Math.max(Math.abs(x), Math.abs(y), Math.abs(z)) - 0.3;
res += sdf;
}
return res;
}
brightness = () => {
return (this.v() - 1.75) / 1.70;
}
}