matrix math fixes
This commit is contained in:
parent
e4d28b3e41
commit
460686eb61
1 changed files with 7 additions and 6 deletions
|
@ -17,15 +17,16 @@ document.querySelector('canvas').addEventListener('click', (e) => {
|
||||||
let p1 = MDN.perspectiveMatrix(Math.PI * 100 / 180, ratio, 0.01, 1000);
|
let p1 = MDN.perspectiveMatrix(Math.PI * 100 / 180, ratio, 0.01, 1000);
|
||||||
for (let cubieI in cubePos) {
|
for (let cubieI in cubePos) {
|
||||||
let cubie = cubePos[cubieI];
|
let cubie = cubePos[cubieI];
|
||||||
let p2 = MDN.multiplyPoint(p1, [cubie[0], cubie[1], cubie[2], 1]);
|
let p2 = MDN.multiplyPoint(p1, [cubie[0], cubie[1], cubie[2], 0]);
|
||||||
|
|
||||||
p2[0] /= width;
|
p2[0] /= p2[3];
|
||||||
p2[1] /= height;
|
p2[1] /= p2[3];
|
||||||
|
|
||||||
p2[0] += (mx - width / 2) / width * 2;
|
p2[0] -= (mx - width / 2) / width * 2;
|
||||||
p2[1] -= (my - height / 2) / height * 2;
|
p2[1] += (my - height / 2) / height * 2;
|
||||||
|
|
||||||
let b = 0.001 / (Math.sqrt(p2[0] ** 2 + p2[1] ** 2) + .003);
|
let b = 1 / (Math.sqrt(p2[0] ** 2 + p2[1] ** 2) + .003);
|
||||||
|
b = (b * b) * 0.001;
|
||||||
|
|
||||||
getBonus += b;
|
getBonus += b;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue