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 › Moving the camera around
Page Index Toggle Pages: 1
Moving the camera around (Read 757 times)
Moving the camera around
Jan 22nd, 2010, 9:58am
 
Hello guys!
I hope this will be the right place for this post. I have a question regarding the use of camera(); I tried to set it up so that it revolves around an object that was placed in the middle of a scene. That is; no z-depth. I then used sin and cos to make coords for the camera to follow, making it a big circle, always pointing towards the middle of the scene. This worked pretty well, but it looked to me as the camera was running an elliptic path rather than a perfect circle path.

Here's an example code:
Code:

float camrot;
void setup(){
 size(600,600, P3D);
 stroke(0);
}
void draw(){  
 background(200,100,140);
 translate(width/2, height/2, 0);
 box(140);
 // camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)
 camera(sin(camrot)*1600, height/2 ,cos(camrot)*1600, width/2, height/2, 0, 0, 1, 0);
 camrot += .025;
 camrot %= TWO_PI;
}


Any ideas/hints?
Re: Moving the camera around
Reply #1 - Jan 22nd, 2010, 10:26am
 
Not sure about this specific code but I use the PeasyCam library.. then just use cam.rotateY(.008);
Re: Moving the camera around
Reply #2 - Jan 22nd, 2010, 10:27am
 
it's the translate, i think, affecting the lookat. you don't really need it - the camera is defining the middle of the screen now.

remove it and change the camera line like this:

camera(sin(camrot)*1600, 0 ,cos(camrot)*1600, 0, 0, 0, 0, 1, 0);

and it looks like it should.
Re: Moving the camera around
Reply #3 - Jan 22nd, 2010, 10:33am
 
your box is centered at 300,300,0 but your camera eye is centered-on/rotates-about 0,y,0 so the circle travelled by the camera is 300 units off-axis (along x).  your camera "at" coords also look suspicious, tho i haven't actually run it, might be worth double-checking.  hth
Re: Moving the camera around
Reply #4 - Jan 22nd, 2010, 12:13pm
 
Thank you all for quick replies Smiley I still feel sort of confused, but thanks to the hints I now have the camera rotating around an axis. I guess it was that in the first place as well, but my object was not centered in the middle. I didn't think that the translate had any effect on the camera in this test code, but it seems it did. But, now, why is it that the box is not in the middle, i.e. on the y-axis, when I place it in the middle of the canvas? (ah, re-reading what I wrote, I think I understand better now. There are no axis in the middle of the canvas, they are at x=0 and Y=0 of course! Smiley )

I can see the effect now. By just placing the object on coords (0,0,0) it appears as though they are in the middle of the canvas (and with my new level of understanding, it now _looks_ like it is the middle of the canvas, because I told the camera to point that way, i.e. on the y-axis, right?) ... Well, interesting and cool Smiley Thanks again!
Re: Moving the camera around
Reply #5 - Jan 22nd, 2010, 1:14pm
 
i was wrong about the translate and dave's right about the centre of rotation being different from the position of your box

you can keep the rotate and the lookat coords but you need to shift the centre of the rotation width / 2 in the x direction by adding it to your camera x:

 camera(width / 2 + sin(camrot)*1600, height/2 ,cos(camrot)*1600, width/2, height/2, 0, 0, 1, 0);

but i'd recommend against it. just use 0,0,0 as the centre of everything, it's all easier that way.
Re: Moving the camera around
Reply #6 - Jan 23rd, 2010, 12:03am
 
koogy wrote on Jan 22nd, 2010, 1:14pm:
i was wrong about the translate and dave's right about the centre of rotation being different from the position of your box
[ ... ]
just use 0,0,0 as the centre of everything, it's all easier that way.

Well, you were right about translate having something to do with it, but yes, I agree, using the 0,0,0, as a reference seems the easiest now Thanks! Cheesy
Page Index Toggle Pages: 1