diff --git a/src/app/ar-fan-cam/ar-fan-cam.page.ts b/src/app/ar-fan-cam/ar-fan-cam.page.ts index 26f66cf..798e90a 100644 --- a/src/app/ar-fan-cam/ar-fan-cam.page.ts +++ b/src/app/ar-fan-cam/ar-fan-cam.page.ts @@ -19,12 +19,6 @@ export class ArFanCamPage implements OnInit { areNeuralNetsLoaded = false; isDetecting = false; - leftEyeX = 0; - leftEyeY = 0; - - rightEyeX = 0; - rightEyeY = 0; - width = 360; height = 270; @@ -71,20 +65,14 @@ export class ArFanCamPage implements OnInit { const leftEye = detectionWithLandmarks.landmarks.getLeftEye(); const rightEye = detectionWithLandmarks.landmarks.getRightEye(); - this.leftEyeX = leftEye[0].x; - this.leftEyeY = leftEye[0].y; - - this.rightEyeX = rightEye[0].x; - this.rightEyeY = rightEye[0].y; - - const distanceBetweenEyes = Math.sqrt(Math.pow(this.rightEyeX - this.leftEyeX, 2) + Math.pow(this.rightEyeY - this.leftEyeY, 2)); - const angleOfRotation = (Math.atan2(this.rightEyeY - this.leftEyeY, this.rightEyeX - this.leftEyeX) * 180) / Math.PI; + const distanceBetweenEyes = Math.sqrt(Math.pow(rightEye[0].x - leftEye[0].x, 2) + Math.pow(rightEye[0].y - leftEye[0].y, 2)); + const angleOfGlassesRotation = (Math.atan2(rightEye[0].y - leftEye[0].y, rightEye[0].x - leftEye[0].x) * 180) / Math.PI; - const scaleMultiplier = distanceBetweenEyes / 130; + const scaleGlassesMultiplier = distanceBetweenEyes / 130; this.glassProperties = { - transform: `translate(calc(-14.5% + ${this.leftEyeX}px), calc(-45% + ${this.leftEyeY}px)) scale(${scaleMultiplier}) rotate(${angleOfRotation}deg)`, - } + transform: `translate(calc(-14.5% + ${leftEye[0].x}px), calc(-45% + ${leftEye[0].y}px)) scale(${scaleGlassesMultiplier}) rotate(${angleOfGlassesRotation}deg)`, + }; } requestAnimationFrame(this.detectAndDrawFace);