We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am trying to rotate a box with the angular velocity set in array. The data is
(Time) (X-axis) (Y-axis) (Z-axis)
0 -0.00478796 -0.017262705 -0.002968556
1.7 -0.006942641 -0.020502579 -0.004041603
...
Now, the box is rotating with the data in the first row, but I want to add each data like this.
step1 X += -0.00478796
step2 X += -0.006942641
...
Could you give me an advice? And thank you!
int tsvWidth = 0;
int LENGTH;
String [][] tsv;
float t, rotX, rotY, rotZ, X, Y, Z;
void setup() {
size(800, 800, P3D);
frameRate(20);
smooth();
String lines [] = loadStrings("Satelite_time_Axis_1_Axis_2_Axis_3.txt");
//calculate max width of tsv file
for (int i=0; i < lines.length; i++) {
String [] chars = split(lines[i], TAB); //split by TAB, not comma
if (chars.length > tsvWidth) {
tsvWidth = chars.length;
}
}
//create tsv array based on # of rows and columns in csv file
tsv = new String [lines.length][tsvWidth];
LENGTH = lines.length;
println(LENGTH);
//parse values into 2d array
for (int i = 0; i < lines.length; i++) {
String [] temp = new String [lines.length];
temp = split(lines[i], TAB);
for (int j = 0; j < temp.length; j++) {
tsv[i][j] = temp[j];
}
}
}
void draw() {
background(0);
println(X, Y, Z);
renderBox();
X += Float.parseFloat(tsv[0][1]);
Y += Float.parseFloat(tsv[0][2]);
Z += Float.parseFloat(tsv[0][3]);
}
void renderBox() {
pushMatrix();
translate(width/2, height/2, 0.0);
rotateX(X);
rotateY(Y);
rotateZ(Z);
fill(128);
box(400);
popMatrix();
}
Answers
You'll get a better response if you format your code. Here's how:
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Thank you, I will format it soon.
Ah, I'm sorry, bilmor, but I set Best Answer by mistake. My bad.