0 Replies - 529 Views - Last Post: 19 May 2019 - 01:10 PM Rate Topic: -----

#1 DB9323   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 17

Processing, use the mouse to rotate an object

Posted 19 May 2019 - 01:10 PM

Hi,

I am using the processing java language. I would like to rotate and image in place using the mouse.

However, using the following code, my image doesn't rotate in place. Instead it only moves down and to the left offscreen.

Here is my code:

ArrowImage arrow= new ArrowImage();

void setup(){
 size(1900, 1200);
 arrow.arrow = loadImage("arrow.png");
}

void draw() {
  background(0);
  //translate(width/2, height /2);
  float dx = mouseX - arrow.x;
  float dy = mouseY - arrow.y;
  double rotation = Math.atan2(dy, dx);
  
  rotate((float)rotation);
  arrow.draw();
  
}




class ArrowImage {
  
  int x = 0;
  int y = 0;
 PImage arrow;
  
  public ArrowImage() {
   
  }
  
  void draw() {
   image(arrow, width/2, height/2);
  }
}



Any help would be much appreciated.
Thanks :)
Marc

Is This A Good Question/Topic? 0
  • +

Page 1 of 1