Loading...
Logo
Processing Forum
Hello,

I have been trying to figure this out with different methods (array, easing, etc) but have not been able to get it to work.
Basically what I need to do is something very similar to the pmouse function.
From an osc message, I need the current value to be stored, then a second later compare the old value to the brand new one to calculate the distance between. Then the old value is replaced and the cycle begins.
Basically, I am just looking to compare the value from a second ago to the new value.
Anyone got any ideas?

Thanks

Replies(8)

Just have a variable holding the old value, to update at the end of draw() with the new value. Like pmouse, precisely.
I am not sure I understand exactly what you mean. 
Could you explain a little further or show an example code?

Something like this:

Copy code
  1.   float longitude1 = longitude;
  2.   println("old: "+longitude1);
  3.   delay(500);
  4.   println("New: "+longitude);
delay() is rarely useful...
The idea is more like:
Copy code
  1. float oldLongitude;
  2. void draw()
  3. {
  4.   // I suppose longitude is updated somewhere
  5.   // [...]
  6.   float d = dist(oldLongiture, longitude);
  7.   // [...]
  8.   oldLongitude = longitude; // Might check time to update only after some time is spent
  9. }

hey PhiLho,

I've come across this forum post, and am a bit confused on your implementation since "dist()" takes 4 variables. 
The processing dist() method takes in 4 variables. However, if you had your own method called dist() you could define how many variables you want. I think in the example above it was more about showing how to store a previous value, than about the what is happening in the dist() method. Are you trying to do something similar with storing a variable or with the dist() method?
I am; I have a line I am trying to draw with incoming OSC variable coordinates.

the original (working ) line was, 


Copy code
    Copy code
    1.     line(pmouseX, pmouseY, mouseX, mouseY);


    I now have to apply the same system to a line with said coordinates:


    Copy code
    1.            line(start_point.getScreenX(width),start_point.getScreenY(height),end_point.getScreenX(width),end_point.getScreenY(height));

    Copy code
      Just unsure how to apply this, really. I'm not following 100% this thread in comprehension. 

      here is what I want:




      here is what I have:


      It is exactly the same idea, except you store the point (whatever its type) instead of a float.
      Copy code
      1. SomePointClass previousPoint;

      2. void draw()
      3. {
      4.   // ... (get newPoint from OSC)
      5.  
      6.   if (previousPoint != null)
      7.   {
      8.     line(previousPoint.getScreenX(width), previousPoint.getScreenY(height), newPoint.getScreenX(width), newPoint.getScreenY(height));
      9.   }
      10.   previousPoint = newPoint;
      11. }
      woah, nevermind. I just needed to rearrange a couple of methods. all is well.

      Cheers!