Mouse Point Rotation
              in 
             Programming Questions 
              •  
              1 year ago    
            
 
           
             Hello everybody 
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
             
            
            
 
            
           
            
             I am new to processing but have done a bit of programming in the past. I was making a 2d game and I need a picture to face where the mouse is pointing. So for example the picture is the top down view of a man's head and his head should rotate depending on where the mouse is located (i.e. his eyes face the mouse). 
            
            
             I tried using tan to calculate the angle, but I got a weird result.
            
            
             Here is my code (NOTE: only top right quarter of the screen can calculate the angle): 
            
            - PImage muha;
 - float rot;
 - float a;
 - float b;
 - void setup(){
 - size(500, 500);
 - muha = loadImage ("muha.png");
 - }
 - void draw(){
 - background(200, 200, 200);
 - if (mouseX > 250 && mouseY < 250){
 - rot = radians(90-atan((250 - mouseY)/(mouseX - 250)));
 - }
 - pushMatrix();
 - translate(250,250);
 - rotate(rot);
 - image(muha, 0, 0);
 - popMatrix();
 - }
 
             Thanks,
            
            
             Muhasaresa
            
 
            
              
              1  
            
 
            