Removed switch statement

This commit is contained in:
2022-01-29 23:58:13 +03:00
parent 08417278e9
commit d497bfca8d
3 changed files with 16 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@@ -157,21 +157,22 @@ export default {
currentTime *= 0.001; currentTime *= 0.001;
const deltaTime = currentTime - previousTime; const deltaTime = currentTime - previousTime;
previousTime = currentTime; previousTime = currentTime;
requestAnimationFrame(animate); requestAnimationFrame(animate);
if (phone) { if (phone) {
phone.anim(deltaTime, { mouseX, mouseY, cameraZ: camera.position.z }); phone.animation(deltaTime, { x: mouseX, y: mouseY, z: camera.position.z });
} }
renderer.render(scene, camera); renderer.render(scene, camera);
} }
function handleMouseEnter() { function handleMouseEnter() {
if (phone) { phone.animation = 'lookAt'; } if (phone) { phone.animation = phone.lookAtAnim; }
} }
function handleMouseLeave() { function handleMouseLeave() {
if (phone) { phone.animation = 'home'; } if (phone) { phone.animation = phone.homeAnim; }
} }
function handleMouseMove(event) { function handleMouseMove(event) {

View File

@@ -4,7 +4,7 @@ export default class MockupModel extends Group {
constructor(home) { constructor(home) {
super(); super();
this.animation = 'float'; this.animation = this.floatAnim;
this.goingHome = false; this.goingHome = false;
this.home = home; this.home = home;
@@ -70,7 +70,7 @@ export default class MockupModel extends Group {
startFloat() { startFloat() {
this.acceleration.y = -0.01; this.acceleration.y = -0.01;
this.animation = 'float'; this.animation = this.floatAnim;
} }
floatAnim() { floatAnim() {
@@ -93,30 +93,11 @@ export default class MockupModel extends Group {
this.rotation.y += 0.02; this.rotation.y += 0.02;
} }
lookAtAnim(x, y, cameraZ) { lookAtAnim(dt, { x, y, z }) {
const target = new Vector3(); const target = new Vector3();
target.x = x; target.x = x;
target.y = y; target.y = y;
target.z = cameraZ; target.z = z;
this.lookAt(target); this.lookAt(target);
} }
anim(dt, { mouseX, mouseY, cameraZ }) {
switch (this.animation) {
case 'rotate':
this.rotateAnim();
break;
case 'lookAt':
this.lookAtAnim(mouseX / 3, mouseY / 3, cameraZ);
break;
case 'home':
this.homeAnim(dt);
break;
default:
this.floatAnim();
}
}
} }