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

View File

@@ -157,21 +157,22 @@ export default {
currentTime *= 0.001;
const deltaTime = currentTime - previousTime;
previousTime = currentTime;
requestAnimationFrame(animate);
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);
}
function handleMouseEnter() {
if (phone) { phone.animation = 'lookAt'; }
if (phone) { phone.animation = phone.lookAtAnim; }
}
function handleMouseLeave() {
if (phone) { phone.animation = 'home'; }
if (phone) { phone.animation = phone.homeAnim; }
}
function handleMouseMove(event) {

View File

@@ -4,7 +4,7 @@ export default class MockupModel extends Group {
constructor(home) {
super();
this.animation = 'float';
this.animation = this.floatAnim;
this.goingHome = false;
this.home = home;
@@ -70,7 +70,7 @@ export default class MockupModel extends Group {
startFloat() {
this.acceleration.y = -0.01;
this.animation = 'float';
this.animation = this.floatAnim;
}
floatAnim() {
@@ -93,30 +93,11 @@ export default class MockupModel extends Group {
this.rotation.y += 0.02;
}
lookAtAnim(x, y, cameraZ) {
lookAtAnim(dt, { x, y, z }) {
const target = new Vector3();
target.x = x;
target.y = y;
target.z = cameraZ;
target.z = z;
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();
}
}
}