PVector dir; void setup() { size(500, 500); rectMode(CENTER);}void draw() { background(100); dir = new PVector(mouseX, mouseY).sub(new PVector(pmouseX,pmouseY)); translate(mouseX,mouseY); rotate(dir.heading()); //rotate(atan2(dir.y,dir.x)); rect(0, 0, 100,50);}
*注:在processing中,物体默认朝向为X轴正方向,即右边。