Camera Movement with the mouse

Posted By: Knuckles

Camera Movement with the mouse - 07/04/07 02:57

How would I be able to swivel the camera around with the middle mouse button (by holding down the scroll wheel and dragging the mouse around so that the camera turns around in different directions)
At first I tried using the mickey function, but all this does is zoom in through the z-axis instead of rotating. Would I need the mickey function for this? or is there another function?
Posted By: MrCode

Re: Camera Movement with the mouse - 07/04/07 04:33

Probably use vec_set and vec_rotate.
Posted By: Ascalon

Re: Camera Movement with the mouse - 07/04/07 07:39

you have to use mouse_mode = 0, or mouse_mode = 1; if mouse_mode = 2 mouse_force is not changed by mouse movement.

the function for rotating the cam for example:

if(mouse_middle == 1)
{
camera.pan -= mouse_force.x * 5 * time_step; //turn left and right
camera.tilt += mouse_force.y * 5 * time_step; // turn up and down
}
Posted By: Knuckles

Re: Camera Movement with the mouse - 07/04/07 15:18

Thanks! Now If I want to make it so that the camera swivels smoothly, I would need to adjust the time_step value?
Posted By: Ascalon

Re: Camera Movement with the mouse - 07/04/07 15:35

you have to chance the value before time_step. i took for example a value of "5". if you want it more smooth you have to chance it to a lower value like 3 or 2 or even 0.5. just experiment with different values.
Posted By: tompo

Re: Camera Movement with the mouse - 07/04/07 15:43

or You may try this... speed is depends of mouse distance from center of the screen (if more far from center, the faster turning):

if(mouse_middle == 1)
{
mouse_pos.x = pointer.x; mouse_pos.y = pointer.y;
camera.pan -= (mouse_pos.x - (screen_size.x /2)) * time_step *0.1;
camera.tilt += (mouse_pos.y - (screen_size.y /2)) * time_step *0.1;
}

Play with 0.1 if camera is turning to fast or to slow
Posted By: Knuckles

Re: Camera Movement with the mouse - 07/04/07 17:12

ah ok I see it now. Thanks!
I forgot to mention, I wanted it to be able to rotate around the player. Basically the player is like the pivot for the camera.
Posted By: Knuckles

Re: Camera Movement with the mouse - 07/21/07 09:55

Getting back to this question, I managed to get the camera working, however it won't stay at the spot you drag it to. I've tried everything I can think of to keep the camera in the same place the player moves it to, but it keeps going back to its original location.
At first, I tried on_mouse_middle == 1 but all that happened was that the screen just moved a little when you click the middle mouse button. Then I did the While loop. You can drag the camera around; however, once you let go of the middle mouse button, the camera goes back to its original location rather than stay where the player puts it.
What do I need to do to get this working? it's been bugging me. Thanks in advance.
Posted By: flits

Re: Camera Movement with the mouse - 07/21/07 13:48

var varcamerapan;

while(mouse_middle == 1)
{
mouse_pos.x = pointer.x; mouse_pos.y = pointer.y;
varcamerapan -= (mouse_pos.x - (screen_size.x /2)) * time_step *0.1;
camera.tilt += (mouse_pos.y - (screen_size.y /2)) * time_step *0.1;

}
while(1)
{
varcamerapan = camera.pan
}

i dont know if it worls but it needs to be somthing like this
Posted By: Knuckles

Re: Camera Movement with the mouse - 07/21/07 23:58

It's still doing the same thing (not staying where the player moves it), but I will work with this as a start, thanks again
Posted By: Ahriman

Re: Camera Movement with the mouse - 07/23/07 19:31

Code:
var Cam_Rotate;
var Cam_Tilt;
var Cam_Dist;


camera.x = player.x + (cos(Cam_Rotate) * cos(Cam_Tilt)) * Cam_Dist;
camera.y = player.y + (sin(Cam_Rotate) * cos(Cam_Tilt)) * Cam_Dist;
camera.z = player.z + sin(Cam_Tilt) * Cam_Dist;
if(mouse_middle)
{
Cam_Rotate -= mouse_force.x / time_step * 2;
Cam_Tilt += mouse_force.y / time_step * 2;
}



That should work for what you need...Cam_Dist is the Camera distance away from the player
Posted By: Knuckles

Re: Camera Movement with the mouse - 07/24/07 16:01

What is the difference between Camera_Distance and Camera.pan?
Posted By: frazzle

Re: Camera Movement with the mouse - 07/24/07 17:00

The variable Cam_Dist is used to determ the distance between the potential view which is the predefined view 'camera' in this code snippet and the entity (player). Camera.pan lets you rotate the view around a specific angle, more detailed:

Quote:


pan is the horizontal angle (0..360) about the upright Z axis





Next to pan, you have tilt and roll, those 3 can be described like this:

Quote:


The entities' Euler angles that describe rotations about the Z, Y, and X axis (in degrees, 0..360).





Here's a picture that shows it:


In overall, Cam_Dist is used for a sertain distance and pan is used for rotating

Cheers

Frazzle
Posted By: Ahriman

Re: Camera Movement with the mouse - 07/25/07 04:37

Yeah Im sorry I forgot to add the actual camera.pan and camera.tilt code in there... add this code below what I posted so that the camera always looks at the player.

Code:
vec_set(temp,player.x); 
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);


© 2024 lite-C Forums