Processing for Android

calculate()

The draw() function in a VR app is called twice per frame, one for each eye. This means that code in draw() that only needs to be run once, will be run two times instead. We can put this code inside the calculate() function, which is called once per frame, right before draw().


import processing.vr.*;

float x, y, z;
void setup() {
  fullScreen(STEREO);
}    

void calculate() {
  // update position variables, e.g.:
  x += 0.1; 
  y += 0.1;   
  z += 0.1;     
}

void draw() {
  translate(x, y, z);
  // ...
}