pmouseX, pmouseY

Hi!
I’m new to openFrameworks, coming from Processing. So, hello to everyone since this is my first post, and congratulations to the developers.
Maybe someone can help me with this: I’m doing a test on dragging an image around using the mouse position. In Processing, I would use PmouseX and PmouseY (functions that retrieve the X and Y position of the mouse in the previous frame) to detect the direction towards I try to move the image. Is there any similar function in openFrameworks? what would you recommend to do in this case?

Thanks!

Hi.
You don’t have pMouseX nor pMouseY, you only have mouseX and mouseY.
but you can create those variables to store the previous mouse position.

declare the variables in you testApp.h file

  
  
int pMouseX;  
int pMouseY;  
  

in your testApp::setup function don’t forget to initialize.

  
  
testApp::setup(){  
//your other code...  
pMouseX = 0;  
pMouseY = 0;  
}  
  

and add this at the end of your testApp::update function

  
  
testApp::update(){  
//do whatever code you would normally put here...  
//and at the end of this function add this:  
pMouseX = mouseX;  
pMouseY = mouseY;  
}  
  

:slight_smile:

Thanks a lot, it works nicely!

Hi.

I’m also working with a processing project which i’m trying to convert it into iphone application using ofxIphone. The thing is, i can’t find the mouseX variable in update(). What i do is put the pmouseX = touch.x in touchMoved(), touchDown() and touchUp(). But it seems the movement doesn’t work very smooth.

Any ideas? :frowning:

Thank you.

mouseX and mouseY are variables that are part of the ofBaseApp (which your app extends) so you wont see them, but they are there and accessible in update and draw.

Can you try them and see if they work?

take care,
zach

Thank you zach for the reply,

Yeah, it works. I’m working on a project which using “Ball” objects. I need to use pmouseX and pmouseY to grab and move the ball nicely. I came out with an idea:

variables:

bool click = false;
float pmouseX[2], pmouseY[2];

setup():

pmouseX[0] = 0;
pmouseY[0] = 0;
pmouseX[1] = 0;
pmouseY[1] = 0;

touchMoved():

if(!click)
{
pmouseX[0] = touch.x;
pmouseY[0] = touch.y;
click = !click;
}
else
{
pmouseX[1] = touch.x;
pmouseY[1] = touch.y;
click = !click;
}

it’s like saving the position of the touch for the last 2 frames. As u see i don’t write any code for position in the update(). This initial idea is working fine. And when i tried the one u gave me, it seems like there’s something wrong with memory. The balls’ movement are slow everytime i touch the surface even when im not touching the balls.

Do u know why is this happening? And which idea do u think i should use? The initial one which work okay but using arrays and boolean, or the one u gave me which quite straight-forward but slow when i touch? >.<