Archived

This topic is now archived and is closed to further replies.

Using the Mouse to Move the Camera

This topic is 5398 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a move_camera() function that will move the camera and a rotate_camera() function that will rotate the camera. You supply it with an angle and the vector on which to rotate the camera, and it will rotate the camera. I can control the rotation with the keyboard, but how can I control it with a mouse? I guess what I am trying to ask is how I can use the mouse coordinates to translate them into an angle so that the center of the camera will be on the cursor. Thanks for your patience! YannL: "There are none, the GeForce2 has no programmable pipeline. It has only limited combiner capabilities, ie. a fixed set of equations with a fixed set of parameters, that you can attribute to the equation variables. The exact procedure depends on wether you use Direct3D or OpenGL." 63616C68h: "NO. You lie! Look! Three threads down in the Beginners Forum."

Share this post


Link to post
Share on other sites
Move the mouse cursor to the center of the screen at the end of every frame. At the beginning of each frame, check to see the difference in the mouse''s position from the center of the screen. That''ll let you know how much the mouse has moved every frame.

Share this post


Link to post
Share on other sites
Hmm. Thanks for your help. I just can''t get it to work for some reason. Here''s the code (note I''m using OpenGL and SDL):

  
// the mouse was moved

case SDL_MOUSEMOTION:
{
// get the mouse state and store it

SDL_GetMouseState(&mouse_x, &mouse_y);

// rotate the camera based on the mouse movement

RotateView(mouse_x << 3, vertex(1.0f, 0.0f, 0.0f));
RotateView(mouse_y << 3, vertex(0.0f, 1.0f, 0.0f));

// move the cursor to the center of the screen

SDL_WarpMouse(width/2, height/2);

} break;

I think I''m doing everything right here, but I''m not sure. The camera seems to be locked, and I can occasionally see the cursor move if I really yank it, but then it returns to the center, and the camera doesn''t rotate. If I don''t call the SDL_WarpMouse() function, the camera rotates, only it goes into this mad frenzy and the triangle goes flashing all over the screen and you can''t control it, no matter how many times you divide mouse_x and mouse_y. Does anyone know what I''m doing wrong here?

Thanks for your patience.

Share this post


Link to post
Share on other sites
There is a tutorial over at GameTutorials which explains quite well how to handle it. It's in the OpenGL section. They have a few tutorials about Camera movement.
It is the same idea of what Ronin Magus explained.


[edited by - rizman on March 3, 2003 5:51:05 AM]

Share this post


Link to post
Share on other sites
This is the problem I had with my camera, where it would get locked. I haven''t solved it yet (haven''t had time) but I think it has to do with the fact I was using Eular angles, and it can be fixed by using quaternions or gametutorials code mentioned above.

Share this post


Link to post
Share on other sites