hello, i want to simulate the movement of 2 accelerometers in one drawing. the 2 boxes that i draw should move differently from each other. i managed to get my first box moving but i can not include another moving box.
the code i used for the first box is:
<
void draw() {
translate(width/2, height/2, 0);
background(100);
textSize(22);
fill(#FFFFFF);
text("Roll: " + int(roll1) + " Pitch: " + int(pitch1), -100, 265);
// Rotate the object
rotateX(radians(roll1));
rotateZ(radians(-pitch1));
the roll1 and pitch1 are coming from my serial port which i read.
So my question is can i include my seccond movement in this drawing and if so, how can i do this
underneath u will find full code:
<
import processing.serial.*;
import java.awt.event.KeyEvent;
import java.io.IOException;
Serial myPort;
String data=“”;
float roll1, pitch1;
float roll2, pitch2;
void setup() {
size (960, 640, P3D);
myPort = new Serial(this, “COM7”, 9600); // starts the serial communication
myPort.bufferUntil(‘\n’);
}
void draw() {
translate(width/2, height/2, 0);
background(100);
textSize(22);
fill(#FFFFFF);
text("Roll: " + int(roll1) + " Pitch: " + int(pitch1), -100, 265);
// Rotate the object
rotateX(radians(roll1));
rotateZ(radians(-pitch1));
// 3D 0bject
fill(#F70707);
box(4,1,2);
}
// Read data from the Serial Port
void serialEvent (Serial myPort) {
// reads the data from the Serial Port up to the character ‘.’ and puts it into the String variable “data”.
data = myPort.readStringUntil(‘\n’);
// if you got any bytes other than the linefeed:
if (data != null) {
data = trim(data);
// split the string at “/”
String items = split(data, ‘/’);
if (items.length > 1) {
//— Roll,Pitch in degrees
roll1 = float(items[0]);
pitch1 = float(items[1]);
roll2 = float(items[2]);
pitch2 = float(items[3]);
}
}
}
the com port gives me this information:
62.46/-7.55/62.46/-7.55
62.45/-7.54/62.45/-7.54
62.46/-7.54/62.46/-7.54
62.47/-7.55/62.47/-7.55
62.46/-7.54/62.46/-7.54
62.44/-7.55/62.44/-7.55
62.44/-7.54/62.44/-7.54
62.43/-7.56/62.43/-7.56
62.45/-7.57/62.45/-7.57
62.45/-7.58/62.45/-7.58
62.45/-7.56/62.45/-7.56
62.44/-7.57/62.44/-7.57
62.44/-7.56/62.44/-7.56
62.46/-7.55/62.46/-7.55