We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Cube vertices. (Read 649 times)
Cube vertices.
Nov 7th, 2009, 10:19am
 
I'm usign an example to make a cube that rotates, with a label following each corner. I understand usign mouseX/Y etc as co-ordinates for the text, but Im not sure what I need to do to create somethign tht will 'listen' for the current position of the corner of the cube once it starts rotating? - do I just position the label before I translate & rotate in the code below?

Thankyou!

Code:


fill(100);
noStroke();
pushMatrix();
translate(mouseX+50, mouseY, 0); //CUBE SOLID(PANELS).
rotateY(y);
rotateX(x);
rotateZ(z);
scale(2,2,2);
beginShape(QUADS);

vertex(-10, 10, 10);
vertex( 10, 10, 10);
vertex( 10, -10, 10);
vertex(-10, -10, 10);

vertex( 10, 10, 10);
vertex( 10, 10, -10);
vertex( 10, -10, -10);
vertex( 10, -10, 10);

vertex( 10, 10, -10);
vertex(-10, 10, -10);
vertex(-10, -10, -10);
vertex( 10, -10, -10);

vertex(-10, 10, -10);
vertex(-10, 10, 10);
vertex(-10, -10, 10);
vertex(-10, -10, -10);

vertex(-10, 10, -10);
vertex( 10, 10, -10);
vertex( 10, 10, 10);
vertex(-10, 10, 10);

vertex(-10, -10, -10);
vertex( 10, -10, -10);
vertex( 10, -10, 10);
vertex(-10, -10, 10);

endShape(CLOSE);

popMatrix();

Re: Cube vertices.
Reply #1 - Nov 7th, 2009, 12:25pm
 
-UPDATED-

I have added a piece of text into a new push/pop matrix and it is visible and can be rotated, but it seems to be rotating around a long way from the centre.

Which property can I change to get the text to move around a smaller orbit?

Code:
PFont font;
float y = 6;
float x = 4;
float z = 0;


void setup() {
size(640, 360, P3D);


}


void draw(){
 background(0);

 lights();
stroke(255);
noFill();
pushMatrix();
translate(mouseX-40, mouseY, 0);
rotateY(y);
rotateX(x);
rotateZ(z-5);
box(40);
popMatrix();


pushMatrix();
//translate(mouseX, mouseY);
font = loadFont("ArialMT-12.vlw");
textFont(font);
fill(255);
text("left-click to rotate (x)", width/3, height/2, 0);
text("right-click to rotate (y)", width/3, height/2+13, 0);   //CUBE WIREFRAME.
popMatrix();



if((mousePressed)&& (mouseButton == RIGHT)){
 y = y+0.1;
}else if((mousePressed)&& (mouseButton == LEFT)){
 x = x+0.1;
}



fill(100);
noStroke();
pushMatrix();
translate(width/3, height/2, 0);   //CUBE SOLID(PANELS).
rotateY(y);
rotateX(x);
rotateZ(z);
scale(2,2,2);
beginShape(QUADS);

vertex(-10,  10,  10);
vertex( 10,  10,  10);
vertex( 10, -10,  10);
vertex(-10, -10,  10);

vertex( 10,  10,  10);
vertex( 10,  10, -10);
vertex( 10, -10, -10);
vertex( 10, -10,  10);

vertex( 10,  10, -10);
vertex(-10,  10, -10);
vertex(-10, -10, -10);
vertex( 10, -10, -10);

vertex(-10,  10, -10);
vertex(-10,  10,  10);
vertex(-10, -10,  10);
vertex(-10, -10, -10);

vertex(-10,  10, -10);
vertex( 10,  10, -10);
vertex( 10,  10,  10);
vertex(-10,  10,  10);

vertex(-10, -10, -10);
vertex( 10, -10, -10);
vertex( 10, -10,  10);
vertex(-10, -10,  10);

endShape(CLOSE);

popMatrix();


pushMatrix();
fill(255);
translate(width/3, height/2, 0);
rotateY(y);
rotateX(x);
rotateZ(z);
//scale(2,2,2);
text("hello?",width/3, height/2, 0);
popMatrix();



}
Page Index Toggle Pages: 1