Advertisement
maha_kaal

mouse moved

Nov 4th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1.     public void mouseMoved(MouseEvent e) {
  2.         double thetaSx, thetaDx;
  3.         int dx, dy, newx, newy;
  4.        
  5.         dx = e.getX() - (xEyeSx + pupilDiameter/2);
  6.         dy = e.getY() - (yEye + pupilDiameter/2);
  7.         thetaSx = Math.atan2(dy, dx);
  8.         newx = (int) ((widthEye/2 - pupilDiameter/2) * Math.cos(thetaSx)) + xEyeSx; //raggio orbita - raggio pupilla * cos(teta) <- nuova x
  9.         newy = (int) ((widthEye/2 - pupilDiameter/2) * Math.sin(thetaSx)) + yEye; // raggio orbita - raggio pupilla * sin(teta) <- nuova y
  10.        
  11.         int distanza = (int) Math.sqrt(Math.pow(e.getX() - xEyeSx, 2) + Math.pow(e.getY() - yEye, 2)); // distanza puntatote centro orbita
  12.         int distanzaPupilla = (int) Math.sqrt(Math.pow(xEyeSx - newx, 2)+ Math.pow(yEye - newy, 2));
  13.         if(distanza <= distanzaPupilla){
  14.             newx = e.getX();
  15.             newy = e.getY();
  16.         }
  17.         leftPupil.move(newx, newy);
  18.        
  19.         dx = e.getX() - (xEyeDx + pupilDiameter/2);
  20.         dy = e.getY() - (yEye + pupilDiameter/2);
  21.         thetaDx = Math.atan2(dy,dx);
  22.         newx = (int) ((widthEye/2 - pupilDiameter/2) * Math.cos(thetaDx)) + xEyeDx; //raggio orbita - raggio pupilla * cos(teta) <- nuova x
  23.         newy = (int) ((widthEye/2 - pupilDiameter/2) * Math.sin(thetaDx)) + yEye; // raggio orbita - raggio pupilla * sin(teta) <- nuova y
  24.         distanza = (int) Math.sqrt(Math.pow(e.getX() - xEyeDx, 2) + Math.pow(e.getY() - yEye, 2)); // distanza puntatote centro orbita
  25.         //distanzaPupilla = (int) Math.sqrt(Math.pow(xEyeDx - newx, 2)+ Math.pow(yEye - newy, 2));
  26.         if(newx < distanza){
  27.             newx = e.getX();
  28.             newy = e.getY();
  29.         }
  30.         rightPupil.move(newx, newy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement