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 › How to program a virtual camera
Page Index Toggle Pages: 1
How to program a virtual camera? (Read 662 times)
How to program a virtual camera?
Apr 19th, 2006, 7:18am
 
I'd like to program a virtual camera.

Now before you jump right on it, let me say that I want to avoid using camera(), beginCamera(), or the OCD camera lib. All of which are wonderful, but I can't use them since I have no control of the internal matrix stacking.

So my question is: how does one write a camera routine?

I want what basically is a (6dof?) camera system used in the most basic FPS games (think Quake). I want to do this with good ol push pop matrix, translate, and rotate.

The problem I'm running into is what order to rotate/translate. As of now:

Code:

translate(cameraSourceX, cameraSourceY, cameraSourceZ);
rotateX(cameraRX);
rotateY(cameraRY);


This isn't correct, since the rotation axis will always be at the center of the world (0,0,0) and the scene becomes basically a "model on a turntable". I want the rotation axis on the viewer (from your head).

So I tried:

Code:
 
rotateX(cameraRX);
rotateY(cameraRY);
translate(cameraSourceX, cameraSourceY, cameraSourceZ);


Which is also incorrect. The rotation is now locked onto the viewer's head, but the translate is locked into the world's XYZ axis.

I know there's a particular order in which to do this (and also an additional step to reverse a translation) but I can't, for the life of me, seem to find this through google or NeHe.

Help. Please!


OOPS I just realized this should be in the 3D forum. Please move this, thanks!
Re: How to program a virtual camera?
Reply #1 - Apr 19th, 2006, 7:47am
 
http://seltar.wliia.org/sketch.php?pid=28

the source should give you what you need Smiley

-seltar
Re: How to program a virtual camera?
Reply #2 - Apr 19th, 2006, 9:24am
 
*edit after reading all of source*

Ahh.. alas....

It's using

Code:

beginCamera();
camera(cam.pos.x, cam.pos.y, cam.pos.z,
cam.view.x, cam.view.y, cam.view.z,
cam.up.x, cam.up.y, cam.up.z);
endCamera();


Correct? I want to try doing this without any form of camera(), since I want to maintain my own matrix transform stacks. I see that you're doing some heavy math (quaternions.. no less...) to achieve the billboarding.

I am doing billboarding with screenXYZ (and playing with modelXYZ as well to some success) which works (without additional math) but I still need control of the camera.
Re: How to program a virtual camera?
Reply #3 - Apr 19th, 2006, 11:01am
 
The translate/rotateY/rotateX is probably the order you want, you just have to look at it slightly differently. The player is always going to be the centre of thew world, you just have to move the world around it, which is what the translate does.

However, you pretty much have to invert all your numbers.

So if the player is at (20,0,0) in relation to the world model, you have to do a translate(-20,0,0) to make the player now effectively at (0,0,0). Then the rotateY takes the negative value of the heading, since rotating the head clockwise is the same as rotating the world anti-clockwise. Ditto for the up/down viewing angle.
Page Index Toggle Pages: 1