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 & HelpOpenGL and 3D Libraries › Basic 3D manipulation
Page Index Toggle Pages: 1
Basic 3D manipulation (Read 896 times)
Basic 3D manipulation
Jan 30th, 2010, 3:34pm
 
I am trying to get my head around rotating points in a 3D space and I am not having much luck. I have this code...

Code:
float a = 0;
float x=0;
float y= 0;
float z = -100;

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

stroke(255);
fill(255, 255);
}

void draw() {
background(0);

translate(width/2, height/2);

rotateY(radians(a));
point (x, y, z);

a=a+1;
if (a>360) {a=0;}
}


Which, as far as I can work out should put a point at 0, 0, -100 or 100 points away from the camera. I presumed that rotating the Z axis would make the point spin around the cameras location but it seems Y is the closest to do this.

But, when it rotates, instead of doing what I expected it to do, i.e. to rotate around the cameras position (going behind the camera and then re-appearing on the opposite side) it seems to rotate around a point off in the distance, almost as if the camera has been moved backwards by some distance from thr 0, 0, 0 position.

I am sure I am just doing something wrong but can someone help please.
Re: Basic 3D manipulation
Reply #1 - Jan 30th, 2010, 4:09pm
 
i am not sure if i unerstand,
Are you saying (0,0,0) is the position of the camera?
cause thats not.

this is what camera() says :

The default values are camera(width/2.0, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0).

You can change the position if you want to. http://processing.org/reference/camera_.html
Re: Basic 3D manipulation
Reply #2 - Jan 31st, 2010, 2:23am
 
Thanks, that fixed it :-

Code:
float a = 0;
float x=0;
float y= 0;
float z = -100;

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

stroke(255);
fill(255, 255);
camera(0, 0, 0, 0, 0, -100, 0, 1, 0);

}

void draw() {
background(0);

translate(width/2, height/2);

rotateY(radians(a));
point (x, y, z);

a=a+1;
if (a>360) {a=0;}
}
Page Index Toggle Pages: 1