#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Display 3d position using acceleration

edited January 2018

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:

• hello,

yeah, here is an example.

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;
}
}
``````