Display 3d position using acceleration

edited January 2018 in How To...

Hello people,

I want to move an object in P3D using live sensor data. The sensor outputs the current acceleration data (data-type float) for the x,y,z axes in m/s² every 0.1 seconds. Unfortunately I have no idea how to translate this data to work with processing and I haven't found any similar projects online. For any code ideas, pseudo code or tutorials I'd be very happy. Thank you

Tagged:

Answers

  • hello,

    yeah, here is an example.

    Instead of my keys you need to use your sensory data.

    axes in m/s² every 0.1 seconds

    so they can be positive and negative?

    maybe it's enough to say :

    translatex += sensorDataX;
    translatey += sensorDataY;
    translatez += sensorDataZ;
    

    Chrisir

    float rotationX;
    float rotationY;
    float rotationZ;
    
    float translatex=300;
    float translatey=300;
    float translatez=300;
    
    float z = 1.0;
    
    int objectNumber = 0;
    
    
    void setup() {
    
      size(1200, 900, P3D);
      background(0);
    
      sphereDetail(32);
    }
    
    void draw() {
      background(0);
      lights();
    
      pushMatrix();
      fill(255, 0, 0); // red
      translate(width/3, height/2, 0);
      translate(translatex-300, translatey-300, translatez-300);
      rotateZ(rotationZ);
      rotateY(rotationY);
      rotateX(rotationX);
      scale(z);
    
      if (objectNumber==0) {
        stroke(111);
        box(100);
      } else if (objectNumber==1) {
        rect(-33, -33, 66, 66);
      } else if (objectNumber==2) {
        noStroke();
        sphere(90);
      }
    
      popMatrix();
    
      fill(255); // white 
      text ("Use wasd and pl", 19, 19);
      keyPressed_ForContinuusKeyinput();
    }
    
    void keyPressed_ForContinuusKeyinput() {
      // apply sensor data here
    
      float speed = 3.9; 
    
      switch(key) {
    
      case 'a':
        translatex-=speed;
        break; 
    
      case 'd':
        translatex+=speed;
        break;
    
      case 'w':
        translatey-=speed;
        break; 
    
      case 's':
        translatey+=speed;
        break;
    
      case 'p':
        translatez-=speed;
        break; 
    
      case 'l':
        translatez+=speed;
        break;
      }
    }
    
Sign In or Register to comment.