Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Smooth OpenGL mouse look


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 BlueSpud   Members   -  Reputation: 495

Like
0Likes
Like

Posted 30 July 2013 - 08:27 AM

So I want to make the mouse looking smooth for my game. I have the mouselook working, but in comparison to games like hl2 or battlefield, its terribly choppy. I'm coding it natively on a mac, and I want to make it cross platform, so help in that regard would be appreciated. This is my current code with the choppiness:

if (giveMouse == false)
    {
    int speed = 1;
    glutWarpPointer(640, 400);
    
    int diffy = y - oldy;
    int diff = x - oldx;
    oldx =  x;
    oldy = y;
    if (y != 400)
        {
        pitch += (diffy/4)*speed;
        if (pitch < -180)
            pitch = -180;
        if (pitch > 180)
            pitch = 180;
        }
    if (x != 640)
        {
        yaw += (diff/8)*speed;
        if (yaw > 360)
            yaw = 0;
        if (yaw < 0)
            yaw = 360;
        }
        Projectile.yaw = yaw;
        Projectile.pitch = pitch;
        Client.dir = yaw;
    }

And thats being called in the glutPassiveMotionFunc. Any help would be appreciated, thanks.



Sponsor:

#2 OandO   Members   -  Reputation: 962

Like
0Likes
Like

Posted 01 August 2013 - 11:08 AM

I don't remember how GLUT deals with mouse cursor coordinates going outside of the window, but I never warp the mouse back to the middle at the end of a frame. Instead I just grab the change in mouse position after a frame (Or average it over two or three frames if you want mouse smoothing) and use that to change the view angle. I don't know what the reason is particularly, but whenever I've warped the mouse back afterwards it's made the movement jittery.



#3 BlueSpud   Members   -  Reputation: 495

Like
0Likes
Like

Posted 01 August 2013 - 05:19 PM

I don't remember how GLUT deals with mouse cursor coordinates going outside of the window, but I never warp the mouse back to the middle at the end of a frame. Instead I just grab the change in mouse position after a frame (Or average it over two or three frames if you want mouse smoothing) and use that to change the view angle. I don't know what the reason is particularly, but whenever I've warped the mouse back afterwards it's made the movement jittery.


But that would eventually lead to the user moving the mode out of the window.

#4 dpadam450   Members   -  Reputation: 1193

Like
1Likes
Like

Posted 02 August 2013 - 12:38 AM

yaw += (diff/8)*speed;
if (yaw > 360)
yaw = 0;

 

yaw = yaw - 360;

if yaw is 380, the end result would be 20 degrees past 360 or 20 degrees. (380 - 360).

Not a solution but a bug in your code.

 



#5 WiredCat   Members   -  Reputation: 524

Like
0Likes
Like

Posted 02 August 2013 - 06:46 PM

i sue this code for moving my mouse:

void __fastcall  TFCOpenGL::move_mouse()
{

if (FCOpenGL->Visible == false) usem = false;

if (usem == true) {
GetCursorPos(&P);
P.x = P.x;// - FAboutGL->Left;
P.y = P.y;// - FAboutGL->Top;
TPoint LastPoint;
LastPoint.x = P.x - cx;
LastPoint.y = P.y - cy;
cx = RoundTo(Left+Width / 2.0,0);
cy = RoundTo(Top+Height / 2.0,0);
SetCursorPos( cx,cy);

MouseSpeed = MouseSpeed + 0.0f;

glop = glop - (cx - P.x)/100.0f * MouseSpeed;
heading = heading - (cy - P.y)/100.0f * MouseSpeed;

 // if (abs(heading) > 90.0 ) mouse_GIMBL = -1.0f; else mouse_GIMBL = 1.0f;
//  if (abs(360.0 - heading) > 90.0 ) mouse_GIMBL = -1.0f; else mouse_GIMBL = 1.0f;

//	if (abs(heading) > 90.0 ) mouse_GIMBL = -1.0f; else mouse_GIMBL = 1.0f;

if (heading > 90.0   ) { heading = 90.0;}
if (heading < -90.0  ) { heading = -90.0; }

if (glop    > 360  )    glop = 0;
if (glop    < -360 )    glop = 0;


}
}

Its something like that see what is the position of the cursor calculate difference (actual mouse cursor, center of the drawing window) then move cursor to the center of the drawing window

 

 

 

but you could use time in your move routine



#6 BlueSpud   Members   -  Reputation: 495

Like
0Likes
Like

Posted 03 August 2013 - 06:42 AM

yaw += (diff/8)*speed;
if (yaw > 360)
yaw = 0;

 

yaw = yaw - 360;

if yaw is 380, the end result would be 20 degrees past 360 or 20 degrees. (380 - 360).

Not a solution but a bug in your code.
 

You're right, that is a problem. Thanks for pointing that out.



#7 BlueSpud   Members   -  Reputation: 495

Like
0Likes
Like

Posted 03 August 2013 - 06:43 AM

i sue this code for moving my mouse:

void __fastcall  TFCOpenGL::move_mouse()
{

if (FCOpenGL->Visible == false) usem = false;

if (usem == true) {
GetCursorPos(&P);
P.x = P.x;// - FAboutGL->Left;
P.y = P.y;// - FAboutGL->Top;
TPoint LastPoint;
LastPoint.x = P.x - cx;
LastPoint.y = P.y - cy;
cx = RoundTo(Left+Width / 2.0,0);
cy = RoundTo(Top+Height / 2.0,0);
SetCursorPos( cx,cy);

MouseSpeed = MouseSpeed + 0.0f;

glop = glop - (cx - P.x)/100.0f * MouseSpeed;
heading = heading - (cy - P.y)/100.0f * MouseSpeed;

 // if (abs(heading) > 90.0 ) mouse_GIMBL = -1.0f; else mouse_GIMBL = 1.0f;
//  if (abs(360.0 - heading) > 90.0 ) mouse_GIMBL = -1.0f; else mouse_GIMBL = 1.0f;

//	if (abs(heading) > 90.0 ) mouse_GIMBL = -1.0f; else mouse_GIMBL = 1.0f;

if (heading > 90.0   ) { heading = 90.0;}
if (heading < -90.0  ) { heading = -90.0; }

if (glop    > 360  )    glop = 0;
if (glop    < -360 )    glop = 0;


}
}

Its something like that see what is the position of the cursor calculate difference (actual mouse cursor, center of the drawing window) then move cursor to the center of the drawing window

 

 

 

but you could use time in your move routine

So I assume you're calling this in you're idle function?



#8 WiredCat   Members   -  Reputation: 524

Like
0Likes
Like

Posted 03 August 2013 - 10:28 AM

yep



#9 BlueSpud   Members   -  Reputation: 495

Like
0Likes
Like

Posted 03 August 2013 - 03:14 PM

yep

Unfortunately, OSX doesn't have a GetCursorPos, but I can look into an alternative, but if anyone did know it, that would be great.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS