Archived

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

Spanky

Mouse Movement

Recommended Posts

Spanky    138
I was wondering how people have implemented mouse movement in their games. I am working on a 3d engine (isn''t everyone) and I tried this method. Set the cursor to the middle of the screen. Than, every frame, get the new coords for the mouse. If they are different from the middle, apply these to the rotation of the Y and X axis and than reset it back to the middle. The problem with this is that it looks very jerky since every frame it gets moved back. Any ideas on other ways of doing it? Thanks Shawn

Share this post


Link to post
Share on other sites
Spanky    138
Yes I am doing something like that
What I choose to do was to put the mouse cursor back at 320, 240 every frame because if they moved to the edge of the screen, they wouldn''t be able to turn anymore.

But what you had is it though, thats exactly what I did, except for the oldMouse always being at 320, 240 and reseting it back to that position every frame.

The problem is that it looks really jerky for some reason. I get the new mouse coords, apply that to the rotation and than perform that movement based on what keys are down and than display it all. Actually, I display it first and than perform everything. I have my DrawGLScene at the beginning of the WinMain loop just cause thats where I like it

Any ideas?

Share this post


Link to post
Share on other sites
Maximus    124
    
// call this every frame

void Mouse_Accumulate()
{
POINT pos;
GetCursorPos(&pos);

mouse.ax += pos.x - (screen.width/2);
mouse.ay += pos.y - (screen.height/2);
mouse.ax = mouse.ax*(2*mouse.speed);
mouse.ay = mouse.ay*(2*mouse.speed);

SetCursorPos(screen.width/2,screen.height/2);
}

// call on a set timer interval

void Mouse_Update()
{
entity[player_ent].angle+=(float)mouse.ax;
entity[player_ent].yaw+=(float)mouse.ay;
mouse.ax=0;
mouse.ay=0;
// add code here to stop negative angles or 360+ angles

}


Edited by - Maximus on October 31, 2000 6:53:17 AM

Share this post


Link to post
Share on other sites
Sly    128
If you use DirectInput for reading the mouse, then there is no need to reset the mouse position each time the mouse is moved. The mouse movement is always returned since the mouse never really hits the edge of the screen because DirectInput is returning mouse movement. It is important to distinguish between the mouse movement given by the mouse device and the representation of the mouse cursor on screen. It is up to you if you want to limit the mouse to a rectangular section on screen. DirectInput is very easy to use. Try it.



Steve 'Sly' Williams
Tools Developer
Krome Studios

Share this post


Link to post
Share on other sites