Skip to content

Commit 5697eca

Browse files
committed
skull resize
1 parent 0339f8a commit 5697eca

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed
-21.5 MB
Binary file not shown.

public/scripts/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const second = new Date().getSeconds();
22
const scriptName = (() => {
33
switch (second % 3) {
4-
case 0:
5-
return 'life';
6-
case 1:
7-
return 'donut';
4+
// case 0:
5+
// return 'life';
6+
// case 1:
7+
// return 'donut';
88
default:
99
return 'skull';
1010
}

public/scripts/skull.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ function initializeSkull(geometry) {
6363
myMesh.position.set(0, 0, 0);
6464
myMesh.rotation.x = 0.2;
6565

66-
camera.position.x = bbox.max.x * 9;
66+
if (window.innerWidth < window.innerHeight) {
67+
myMesh.rotation.x = 0.2 - Math.PI / 2;
68+
}
69+
70+
const screenArea = window.innerWidth * window.innerHeight;
71+
const referenceArea = 1920 * 1080;
72+
const scaleFactor = Math.sqrt(screenArea / referenceArea);
73+
74+
camera.position.x = (bbox.max.x * (window.innerWidth < window.innerHeight ? 4 : 6))/ scaleFactor;
6775
camera.position.y = 0;
6876
camera.position.z = 0;
6977
camera.lookAt(0, 0, 0);
@@ -91,4 +99,18 @@ window.addEventListener('resize', function () {
9199
camera.updateProjectionMatrix();
92100
renderer.setSize(window.innerWidth, window.innerHeight);
93101
effect.setSize(window.innerWidth, window.innerHeight);
102+
103+
if (window.innerWidth < window.innerHeight) {
104+
myMesh.rotation.x = 0.2 - Math.PI / 2;
105+
} else {
106+
myMesh.rotation.x = 0.2;
107+
}
108+
109+
if (myMesh.geometry) {
110+
const bbox = myMesh.geometry.boundingBox;
111+
const screenArea = window.innerWidth * window.innerHeight;
112+
const referenceArea = 1920 * 1080;
113+
const scaleFactor = Math.sqrt(screenArea / referenceArea);
114+
camera.position.x = (bbox.max.x * (window.innerWidth < window.innerHeight ? 4 : 6)) / scaleFactor;
115+
}
94116
});

0 commit comments

Comments
 (0)