RGB Cube rotate with RGB Values help needed
in
Programming Questions
•
1 year ago
Hello together...
May you know the RGB 3D Cube from the Examples.. I want to rotate the cube with the values from my color sensor.
in that way if my sensor is black -> the black edge of the RGB Cube is poping in the front...If the sensor is blue-> the blue edge of the cube is int the fornt.
I try to transform the 3D Color Vecor to a 2D Vektor to rotate the cube
Well I try with that kind of code... but Iam stucking
// X= Red Y=green Z = Blue
// RGB Value Scale 0-1024
// I try to transform the 3D Color Vecor to a 2D Vektor to rotate the cube
v1 = new PVector(x,0,0);
v2 = new PVector(sin (30)*-y,sin (60)*y);
v3= new PVector(cos(60)*-z,sin(60)*-z);
v4 =new PVector(0,0,0);
cx= new PVector(0,0,0);
cy= new PVector(0,0,0);
v4.add(v1);
v4.add(v2);
v4.add(v3);
//Rotating Cube
pushMatrix();
translate(width/2+300, height/2, -30);
// Divide trough 1024 to scale down...
rotateX(((-v4.x)/2024)+1.2);
rotateY(((-v4.y)/1024)+2.2);
scale(80);
beginShape(QUADS);
fill(0, 1024, 1024); vertex(-1, 1, 1);
fill(1024, 1024, 1024); vertex( 1, 1, 1);
fill(1024, 0, 1024); vertex( 1, -1, 1);
fill(0, 0, 1024); vertex(-1, -1, 1);
fill(1024, 1024, 1024); vertex( 1, 1, 1);
fill(1024, 1024, 0); vertex( 1, 1, -1);
fill(1024, 0, 0); vertex( 1, -1, -1);
fill(1024, 0, 1024); vertex( 1, -1, 1);
fill(1024, 1024, 0); vertex( 1, 1, -1);
fill(0, 1024, 0); vertex(-1, 1, -1);
fill(0, 0, 0); vertex(-1, -1, -1);
fill(1024, 0, 0); vertex( 1, -1, -1);
fill(0, 1024, 0); vertex(-1, 1, -1);
fill(0, 1024, 1024); vertex(-1, 1, 1);
fill(0, 0, 1024); vertex(-1, -1, 1);
fill(0, 0, 0); vertex(-1, -1, -1);
fill(0, 1024, 0); vertex(-1, 1, -1);
fill(1024, 1024, 0); vertex( 1, 1, -1);
fill(1024, 1024, 1024); vertex( 1, 1, 1);
fill(0, 1024, 1024); vertex(-1, 1, 1);
fill(0, 0, 0); vertex(-1, -1, -1);
fill(1024, 0, 0); vertex( 1, -1, -1);
fill(1024, 0, 1024); vertex( 1, -1, 1);
fill(0, 0, 1024); vertex(-1, -1, 1);
endShape();
popMatrix();
May you know the RGB 3D Cube from the Examples.. I want to rotate the cube with the values from my color sensor.
in that way if my sensor is black -> the black edge of the RGB Cube is poping in the front...If the sensor is blue-> the blue edge of the cube is int the fornt.
I try to transform the 3D Color Vecor to a 2D Vektor to rotate the cube
Well I try with that kind of code... but Iam stucking
// X= Red Y=green Z = Blue
// RGB Value Scale 0-1024
// I try to transform the 3D Color Vecor to a 2D Vektor to rotate the cube
v1 = new PVector(x,0,0);
v2 = new PVector(sin (30)*-y,sin (60)*y);
v3= new PVector(cos(60)*-z,sin(60)*-z);
v4 =new PVector(0,0,0);
cx= new PVector(0,0,0);
cy= new PVector(0,0,0);
v4.add(v1);
v4.add(v2);
v4.add(v3);
//Rotating Cube
pushMatrix();
translate(width/2+300, height/2, -30);
// Divide trough 1024 to scale down...
rotateX(((-v4.x)/2024)+1.2);
rotateY(((-v4.y)/1024)+2.2);
scale(80);
beginShape(QUADS);
fill(0, 1024, 1024); vertex(-1, 1, 1);
fill(1024, 1024, 1024); vertex( 1, 1, 1);
fill(1024, 0, 1024); vertex( 1, -1, 1);
fill(0, 0, 1024); vertex(-1, -1, 1);
fill(1024, 1024, 1024); vertex( 1, 1, 1);
fill(1024, 1024, 0); vertex( 1, 1, -1);
fill(1024, 0, 0); vertex( 1, -1, -1);
fill(1024, 0, 1024); vertex( 1, -1, 1);
fill(1024, 1024, 0); vertex( 1, 1, -1);
fill(0, 1024, 0); vertex(-1, 1, -1);
fill(0, 0, 0); vertex(-1, -1, -1);
fill(1024, 0, 0); vertex( 1, -1, -1);
fill(0, 1024, 0); vertex(-1, 1, -1);
fill(0, 1024, 1024); vertex(-1, 1, 1);
fill(0, 0, 1024); vertex(-1, -1, 1);
fill(0, 0, 0); vertex(-1, -1, -1);
fill(0, 1024, 0); vertex(-1, 1, -1);
fill(1024, 1024, 0); vertex( 1, 1, -1);
fill(1024, 1024, 1024); vertex( 1, 1, 1);
fill(0, 1024, 1024); vertex(-1, 1, 1);
fill(0, 0, 0); vertex(-1, -1, -1);
fill(1024, 0, 0); vertex( 1, -1, -1);
fill(1024, 0, 1024); vertex( 1, -1, 1);
fill(0, 0, 1024); vertex(-1, -1, 1);
endShape();
popMatrix();
1