We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey, I'm new at processing code and I'm doing a little code for the mouvement of a finger (the index). I'm doing it with the rotation of phalanges, remplaced by cube.
But I have a big problem, the third box 's rotation isn't what I want, I don't know how to explain it but here is my code. How to fix this and have a good mouvement of index ? Thanks for the help.
int a = 80;
int z = 0;
int e =50;
int r = 60;
float rot1;//rotation of cube_1
float rot2;//rotation of cube_2
float rot3;//rotation of cube_3
void setup() {
size(400, 400, P3D);
smooth();
}
void draw() {
background(20, 50, 80);
//base
translate(width/4, height/4);
box(80, 50, 50);
pushMatrix();
// 1/2/3
translate(a, z);//1
rotateZ(rot1);
box(r, e, e);
translate(a, z);//2
rotateZ(rot2);
box(r, e, e);
translate(a, z);//3
rotateZ(rot3);
box(r, e, e);
popMatrix();
if (keyPressed == true)
{
if (key =='a') { //Rot1
rot1 = rot1 + 0.01;
} else if (key == 'z') {
rot1 = rot1 - 0.01;
}
if (key =='a') { //rot2
rot2 = rot2 + 0.01;
} else if (key == 'z') {
rot2 = rot2 - 0.01;
}
if (key =='a') { //rot3
rot3 = rot3 + 0.01;
} else if (key == 'z') {
rot3 = rot3 - 0.01;
}
}
if (rot1 > 1.5) {
rot1 = 1.5;
} else if (rot1 < -0.5) {
rot1 = -0.5;
}
if (rot2 > 1.0) {
rot2 =60;
} else if (rot2 < 0.0) {
rot2 = 0.0;
}
if (rot3 > 1.5) {
rot3 = 1.5;
} else
if (rot3 < 0) {
rot3 = 0;
}
println(rot3);
}
Answers
On line 64, you have a value of 60. This seems wrong. Shouldn't it be a 1?
Yeah ! Thanks a lot, I read over this code a few time and never seen this mistake. Now I can do the rest of the hand. What's better ? : pushMatrix()/popmatrix() functions or there is an other way more optimized than push/pop matrix functions ? Thanks for the help !
pushMatrix()/popMatrix() are optimised already, so I doubt if there is a more efficient way.
They both just push and pop the Transformation matrix to and from a stack of it.