I’m new to the forum, I wonder if anyone can help me to use data from accelerometer to control camera and perspective in processing? I’m making a 3D model of a galaxy and wish to use accelerometer to control the perspective (zoom in or out, etc.) Here is my codes right now. The 3D model and serial part is done but I don’t know how to use the acceleration value
import processing.serial.*;
Serial myPort;
String inString ;
int[] data = new int [3];
int xA = int(data[0]);
int yA = int(data[1]);
int zA = int(data[2]);
Planet sun;
//PImage starfield;
PImage sunTexture;
PImage[] textures = new PImage[10];
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
void setup() {
size(600, 375, P3D);
//fullScreen(P3D);
myPort = new Serial(this, Serial.list()[1], 9600);
println(Serial.list()[1]);
myPort.bufferUntil(’\n’);
//perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0);
//translate(width/2, height/2, 0);
//rotateX(-PI/6);
//rotateY(PI/3);
sunTexture = loadImage(“sun.jpg”);
textures[0] = loadImage(“dirt.jpg”);
textures[1] = loadImage(“eris.jpg”);
textures[2] = loadImage(“golden.jpg”);
textures[3] = loadImage(“green.jpg”);
textures[4] = loadImage(“ice.jpg”);
textures[5] = loadImage(“lava.jpg”);
textures[6] = loadImage(“north.jpg”);
textures[7] = loadImage(“ocean.jpg”);
textures[8] = loadImage(“pink.jpg”);
textures[9] = loadImage(“purple.jpg”);
//starfield = loadImage(“starfield.jpeg”);
sun = new Planet(50, 0, 0, sunTexture);
sun.spawnMoons(10, 1);
}
void draw() {
//background(starfield);
//translate(width/2, height/2, -width);
background(0);
sun.show();
sun.orbit();
perspective(fov, float(width)/float(height), cameraZ/10.0, cameraZ*10.0);
translate(width/2, height/2,-width);
//translate(xA,yA,zA);
//rotateX(-PI/6);
//rotateY(PI/3);
camera(width/2.0, height/2.0, (height/2.0) / tan(PI30.0 / 180.0), (width/2.0)-300, (height/2.0)-187, 0, 0, 1, 0);
//camera(xA/100, yA/100, zA/100, (width/2.0)-800, (height/2.0)-500, 0, 0, 1, 0);
//camera(0, 0, (height/2) / tan(PI30.0 / 180.0), width/2.0, height/2.0, cameraZ, 0, 1, 0);
//translate(width/2,height/2,mouseX);
//lights();
//pointLight(255,255,255,0,0,0);
}
void serialEvent(Serial myPort) {
String inString = myPort.readStringUntil(’\n’);
if (inString != null) {
inString = trim(inString);
println(inString);
data = int (split(inString, ','));
//println(data[0]);
}
}