Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void mouseMoved(MouseEvent e) {
- double thetaSx, thetaDx;
- int dx, dy, newx, newy;
- dx = e.getX() - (xEyeSx + pupilDiameter/2);
- dy = e.getY() - (yEye + pupilDiameter/2);
- thetaSx = Math.atan2(dy, dx);
- newx = (int) ((widthEye/2 - pupilDiameter/2) * Math.cos(thetaSx)) + xEyeSx; //raggio orbita - raggio pupilla * cos(teta) <- nuova x
- newy = (int) ((widthEye/2 - pupilDiameter/2) * Math.sin(thetaSx)) + yEye; // raggio orbita - raggio pupilla * sin(teta) <- nuova y
- int distanza = (int) Math.sqrt(Math.pow(e.getX() - xEyeSx, 2) + Math.pow(e.getY() - yEye, 2)); // distanza puntatote centro orbita
- int distanzaPupilla = (int) Math.sqrt(Math.pow(xEyeSx - newx, 2)+ Math.pow(yEye - newy, 2));
- if(distanza <= distanzaPupilla){
- newx = e.getX();
- newy = e.getY();
- }
- leftPupil.move(newx, newy);
- dx = e.getX() - (xEyeDx + pupilDiameter/2);
- dy = e.getY() - (yEye + pupilDiameter/2);
- thetaDx = Math.atan2(dy,dx);
- newx = (int) ((widthEye/2 - pupilDiameter/2) * Math.cos(thetaDx)) + xEyeDx; //raggio orbita - raggio pupilla * cos(teta) <- nuova x
- newy = (int) ((widthEye/2 - pupilDiameter/2) * Math.sin(thetaDx)) + yEye; // raggio orbita - raggio pupilla * sin(teta) <- nuova y
- distanza = (int) Math.sqrt(Math.pow(e.getX() - xEyeDx, 2) + Math.pow(e.getY() - yEye, 2)); // distanza puntatote centro orbita
- //distanzaPupilla = (int) Math.sqrt(Math.pow(xEyeDx - newx, 2)+ Math.pow(yEye - newy, 2));
- if(newx < distanza){
- newx = e.getX();
- newy = e.getY();
- }
- rightPupil.move(newx, newy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement