Loading...
Logo
Processing Forum

Detecting change in a variable.

in General Discussion  •  Other  •  7 months ago  
Hey there,

What I'm trying to accomplish I think is fairly simple I just can't seem to wrap my head around how exactly...

I'm using a Kinect to track the center point of a person's body (x,y,z coordinates) and I need to write a function that knows when they are moving vs when they stop moving. So anytime there is change to the x,y,z coordinates.

What would be the most straightforward way to achieve this?

Thanks so much.

Replies(1)



well, I suppose you could store the
xyz in a var oldX, oldY, oldZ (at the very end of draw()) and compare them (at the beginning of draw(); for the first time skip the comparison using a variable firstTime that you set to false then)).

comparison : when the difference is bigger than a threshhold do something

Copy code
  1. if ( abs ( x-oldX ) > threshholdX ||  abs ( y-oldY ) > threshholdY || abs ( z-oldZ ) > threshholdZ) 
  2.      isMoving = true ;
  3. else
  4.      isMoving = false ;


maybe you need a threshholdX and threshholdY and threshholdZ, maybe one threshhold with the same value for all 3 directions is enough, I don't know

with millis() you could also perform this check only twice a second or so

Greetings, Chrisir