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 › rotate and scale in 3D
Page Index Toggle Pages: 1
rotate and scale in 3D (Read 497 times)
rotate and scale in 3D
Feb 4th, 2006, 7:30pm
 
Hi,

I have been staring at the rotate and scale examples, but still I did not find a way to scale a vertexShape and rotate it around itself in x, y, z (where all these parameters are available).

Has anyone done that before? Maybe I don't quite understand the concept of atan2 and radians ...

thanks for your help - knowing these things can help me a lot with my coding.

am
Re: rotate and scale in 3D
Reply #1 - Feb 5th, 2006, 7:29am
 
annemarie,

I'm assuming you want to use the arctangent (atan2) to base orientation around some known vector (i.e. mouse postion).
Here's some code that might help.

Code:

float ang = 0;
void setup(){
size(600, 400, P3D);
framerate(30);
}
void draw(){
background(0);
ambientLight(140, 140, 140);
translate(width/2, height/2, 0);

//rotate 90 degs and then find
//theta(angle of rotation in radians)
//based on mouse position
rotateZ(PI/2+atan2(mouseY-height/2, mouseX-width/2));

//this second rotation just
//keeps pyramid spinnning
rotateY(radians(ang-=PI/2.0));
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();
}

Page Index Toggle Pages: 1