We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › mousefollow
Page Index Toggle Pages: 1
mousefollow (Read 536 times)
mousefollow
Apr 27th, 2010, 12:43pm
 
hey, i tried to make an advanced mousefollow in which an object flys from a position (vertex) to the mouseposition...
but it doesnt work... whats wrong ?

int posX;
int posY;
int zielX;
int zielY;
float speed = .05;

void setup() {
 size(350, 505);

}

void draw(){
   background(50, 100, 95);
   
zielX = mouseX;
zielY = mouseY;
 
posX += (zielX - posX) * speed;
posY += (zielY - posY) * speed;

pushMatrix();
translate(posX, posY);
fill(150, 137, 76);
beginShape();
vertex(101, 382);
vertex(165, 335);
vertex(165, 458);
vertex(101, 458);
vertex(101, 382);
endShape();
popMatrix();
}


void mousePressed(){
zielX =mouseX;
zielY=mouseY;

}

Re: mousefollow
Reply #1 - Apr 27th, 2010, 12:59pm
 
There is an offset between your shape and posX/posY.
Subtract minimal X value and minimal Y value from the coordinates of the shape:
Code:
pushMatrix();
translate(posX, posY);
fill(150, 137, 76);
beginShape();
vertex(0, 47);
vertex(54, 0);
vertex(54, 123);
vertex(0, 123);
vertex(0, 47);
endShape();
popMatrix();
Page Index Toggle Pages: 1