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.
IndexProgramming Questions & HelpSyntax Questions › rotation with one variable
Page Index Toggle Pages: 1
rotation with one variable (Read 536 times)
rotation with one variable
Feb 8th, 2006, 10:25am
 
Hi, (sorry for the stream of questions),

I would like to rotate a 3D shape around its Y axis with only ONE variable:

I have been trying to modify this code that uses mouseX and mouseY to rotate a 3D object:
rotateZ(PI/2+atan2(mouseY-height/2, mouseX-width/2));

I shortened it down to this: rotateY(PI/(mouseY-height/2));
but then you only need to move the mouse a tiny bit when the whole 3D shape flips immediately.

How do I rotate a 3D shape with only mouseY?

thanks for your help,
am
Re: rotation with one variable
Reply #1 - Feb 8th, 2006, 11:26am
 
for me something like rotateY(mouseX*0.01); always worked (and yes I'm using mouseX for the Y axis since it's more intuitive... Wink )
Re: rotation with one variable
Reply #2 - Feb 8th, 2006, 4:36pm
 
also, if you want to avoid the *0.01, you could set a rotation range and do a simple ratio calculation between range and display window width. Here's the earlier example modified, taking into account toxi's suggestion and the controllable rotation range.

Code:

float rotateRange = 360.0; // in degrees

void setup(){
size(600, 400, P3D);
framerate(30);
}
void draw(){
background(0);
ambientLight(140, 140, 140);
translate(width/2, height/2, 0);
rotateY(radians(mouseX*rotateRange/width));
scale(50, 50, 50);

beginShape(TRIANGLES);
//face 1
fill(45, 200, 20);
vertex(-1, 1, -1);
vertex(0, -1, 0);
vertex(1, 1 , -1);

//face 2
fill(255, 30, 30);
vertex(-1, 1, 1);
vertex(0, -1, 0);
vertex(1, 1 , 1);

//face 3
fill(140, 45, 255);
vertex(-1, 1, -1);
vertex(-1, 1, 1);
vertex(0, -1, 0);

//face 4
fill(255, 255, 30);
vertex(1, 1, -1);
vertex(1, 1, 1);
vertex(0, -1, 0);
endShape();
}

Re: rotation with one variable
Reply #3 - Feb 10th, 2006, 8:16am
 
Makes more sense if you do
Code:

rotateY(radians(mouseX));


And then you can use constrain() as well..
Page Index Toggle Pages: 1