Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: mouselook camera

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    mouselook camera

    Hi,
    I'm trying to implement a mouse-controlled camera(sort of Q3A-style).I know this question has been asked tons of times before but a search in the archives didn't bring up anyting really usefull.Anyway I tried out the following:

    Code :
    glLoadIdentity();        glRotatef((float)(mx-x0)/c,0,1,0);
    glRotatef((float)(my-y0)/c,1,0,0);
    glTranslatef(p[0],p[1],p[2]);
    ,where mx,my are mouse coords,(x0,y0) is the screen center and p is the camera pos.
    Apart from the fact that this way I can rotate up to a certain amount,which can be fixed by warping the pointer to (x0,y0) every time and accumulate the rotation angles,this isn't very smooth.Yet if I do this for every frame like I do now, I don't see how it can be done better(smoother).Maybe if I poll the mouse every n frames/ms and interpolate the camera inbetween I can get better results?How is this usually done?

    [This message has been edited by zen (edited 04-25-2002).]

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    23

    Re: mouselook camera

    Do you use gluLookAt in your code?

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    Re: mouselook camera

    No,why do I need to use gluLookAt?I don't need to look at a specific spot in space,I just want to rotate my camera smoothly using the mouse.Is there something I'm missing?Maybe I should take a look at the Quake I/II sources.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    23

    Re: mouselook camera

    Just curious...

    Your code looks pretty neat. The only thing might be to take the calculation of angles out of the glRotate function, that might help a bit. Still I don't see any glaring problem.

    What's the difference in the framerate before and after you use the mouse rotation?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Pori, Finland
    Posts
    191

    Re: mouselook camera

    I have the same thing. I'm doing the camera rotation just like that and the rotating is very 'jumping'. I use allegro's mouse routines and update the mouse every millisecond. Still it's 'blocky'.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    Re: mouselook camera

    Just to make this clear.I can't say that movement is very blocky.It looks fairly acceptable at 28fps and at 50-60 it looks better but it still isn't as smooth as seen in games like quake.That's why I'm curious wether there's more to it than just a couple of glRotatefs and a glTranslatef.
    Zuraffo:fps drop from 29.5 to 28.7 on average but I assume this happens because of the 2 glRotatefs which can be optimized away since we just need rotation about the x and y axii.
    blender:the only possible reason I can think of for getting *very* jumpy rotation is getting too low fps.What kind of fps do you get?Updating the mouse every millisecond would only pay off for framerates close to 1000fps(for the camera at least).BTW what are these allegro routines you're reffering to?

  7. #7
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: mouselook camera

    you may want to store your camera's look, up and right vectors. for my camera, i get the change in mouse coordinates from previous frame and create pitch and yaw angles. i use the pitch angle and the right vector to generate a rotation matrix. the look and up vectors get transformed by this matrix. i create another rotation matrix using the yaw angle and the vector <0,1,0>. then i transform the look, right and up by this matrix. then, using look, right and up, i create a matrix and use glLoadMatrixf. no rotates or translates, and it works great!

    also, this makes moving around easy. to move forward, just alter your position like this:
    Code :
    position += look * 5.0
    and strafing:
    Code :
    position += right * 5.0
    the only complicated part is creating the rotation matrices, but you can find out how to do that here

    good luck
    b

    [This message has been edited by coredump (edited 04-26-2002).]

  8. #8
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    Re: mouselook camera

    I agree that a camera model,such as the RUV model you describe is neccesary but I don't think this will make things any smoother since you'll eventually end up with the same rot. matrices.IMO since I poll the mouse position every frame,smootheness is framerate-dependant.Maybe if I poll every say 4 frames and then interpolate betwwen them...but polling every frame would essentially take care of the interpolation anyway.
    Nevertheless I should implement a camera model anyway,so I'll try that first.

  9. #9
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: mouselook camera

    Use quaternians and a map the mouse movement onto a unit sphere, well any sphere actually and get your rotations from that...

  10. #10
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    23

    Re: mouselook camera

    The framerate drop is not significant, so it's not the rotation that is causing the problem, you'd have to look else where.

    Anyway just curious, is there any reason you are not using a camera model? I always thought that's intuitive...

Page 1 of 2 12 LastLast

Similar Threads

  1. [Camera] Can't make the camera move appropriately
    By onion_bread in forum OpenGL ES
    Replies: 0
    Last Post: 12-01-2011, 07:36 PM
  2. [glut] mouselook
    By rsp91 in forum OpenGL: General
    Replies: 10
    Last Post: 07-17-2008, 11:21 AM
  3. Camera Position / Camera Angle / Camera Target Position
    By bobGL in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-02-2007, 09:28 AM
  4. glut-only mouselook
    By rhmazza in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-14-2002, 06:04 AM
  5. Using XWarpPointer in a 'mouselook' interface
    By zen in forum OpenGL: Linux
    Replies: 3
    Last Post: 05-30-2002, 07:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean