Simple Camera

Posted By: snow4dayz

Simple Camera - 02/22/09 07:33

I hate to start off with such an ignorant question but I am working on a level, I added a camera and I pan and tilt it with this code:

Code:
 if (key_w) camera.tilt += 2 * time_step; 
      if (key_s) camera.tilt -= 2 * time_step; 
      if (key_a) camera.pan += 2 * time_step;
      if (key_d) camera.pan -= 2 * time_step;


Any simple way to make that camera zoom around the map with the W, A, S, D keys? Basically just need to be able to walk-thru the level, however collision would be nice, I am tooling around with c_move as we speak, but still relatively new to the whole process.

-Snow
Posted By: Xarthor

Re: Simple Camera - 02/22/09 09:19

What exactly do you want to alter with this WASD keys?
The rotation of the camera (as in your snippet) or the position of it?
Do you have a player model and action which moves through the level?
Posted By: Jaxas

Re: Simple Camera - 02/22/09 14:03

add your code in main function in while cycle smile
Posted By: cjm

Re: Simple Camera - 02/22/09 19:21

Just add to the code you are using, if you use the WASD keys for movement you will have to use other keys(or the mouse) for tilting and panning:

Add to main:

while(1)
{
// Tilting and panning code here

if (key_w) camera.x += 2 * time_step; // Adjust 2 factor for right speed!
if (key_s) camera.x -= 2 * time_step;
if (key_d) camera.y += 2 * time_step;
if (key_a) camera.y -= 2 * time_step;

wait(1);
}
Posted By: snow4dayz

Re: Simple Camera - 02/22/09 20:07

I am kicking myself for not even thinking about the axis call of the camera.. lol, thanks!
Posted By: snow4dayz

Re: Simple Camera - 02/23/09 09:34

Just FYI, I put the camera code in it's own thread, it's awesome!

Here is a fully functional camera, if anyone ever needs it.

Code:
void camera_move()
{
	while (1)
   {
   	if (key_q) camera.pan += 10 * time_step;
      if (key_e) camera.pan -= 10 * time_step;
      if (key_z) camera.tilt += 10 * time_step;
      if (key_c) camera.tilt -= 10 * time_step;
   	if (key_w) camera.x += 10 * time_step;
		if (key_s) camera.x -= 10 * time_step;
		if (key_d) camera.y += 10 * time_step; 
		if (key_a) camera.y -= 10 * time_step; 
		if (19 == key_lastpressed) // R key will reset the pan and tilt to 0.
      {
         camera.pan = 0;
         camera.tilt = 0;
      }   
   wait (1);
   } 
}


-Snow
© 2024 lite-C Forums