Jump to content
  • Advertisement

Archived

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

adymlincoln

Windows Mouse Messages and Y-axis rotation...

This topic is 5666 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

Hi all, I am busting my brains trying to figure out a simple way to rotate my 3D world in the x-axis...I''m trying to use the built in Windows mouse messages ( WM_MOUSEMOVE ) to determine which way to rotate my world on the Y-Axis...basically to turn either right of left on the screen. First Attempt : Grab the mouse x,y during a WM_MOUSEMOVE event and compare it to the previous x coordinate...If new-x > prev-x then move one way, otherwise move the other...Annnnn! It only works part of the time... Second Attempt : When the window gets created, calculate the half-way point, screen-width / 2. Then during a WM_MOUSEMOVE event, compare new-x to half-way x, if greater move one way, otherwise move the other...Results : Better, but extremly choppy... Question : how can I get a smooth turn (like Quake) without using DirectInput...Can this even be accomplished using standard Windows messaging/functions? thx in advance... adym

Share this post


Link to post
Share on other sites
Advertisement
You could try calling GetCursorPos() each frame and calculating the delta motion. It should be much smoother than using the message handler.

Share this post


Link to post
Share on other sites
Hi,

I''m doing it a bit differently (my leftbutton has to be down to rotate)but it works fine. I found that the actual function to do the rotations needs to be called from winmain or glDrawscene- ie not winproc- its very slow from there.

in winproc:

case WM_LBUTTONDOWN: { //you could use mousemove or whatever
mbuttons = (int)wParam;
return 0;
}

in winmain:

if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) done=TRUE;
else {
SwapBuffers(hDC);
ProcessKeyboard();
if (mbuttons & MK_LBUTTON) processMouse2();//you could have a mouse switch
}


and then the function (basically from gametutorial #5)

void processMouse2(){
POINT mousePos;
int middleX = SCREEN_WIDTH/2;
int middleY = SCREEN_HEIGHT/2;
GetCursorPos(&mousePos);
SetCursorPos(middleX, middleY); if( (mousePos.x == middleX) && (mousePos.y == middleY) ) return;
roty+= (float)( middleX - mousePos.x )/250.0f;
rotx-= (float)( middleY - mousePos.y )/250.0f;
}


I haven''t figured out how to hide the cursor yet- its very distracting! Also, those 250.0f numbers- I bet they will vary from system to ssytem....he used 1000 in the tutorial.

Anyway, that how I''m doing it for now.


Share this post


Link to post
Share on other sites
To hide the cursor, use the ShowCursor function. It takes a BOOL show - TRUE to make the cursor visible and FALSE to hide it. (Actually, passing TRUE increments a counter and FALSE decrements the counter, and when its >= 0 the cursor is visible. That means if you pass FALSE to it twice, you will have to give it TRUE twice to make it show the cursor.)

Edit: The function returns an int that is the value of the counter, so you could do something like while(ShowCursor(TRUE) < 0); to force the cursor to be displayed, and while(ShowCursor(FALSE) >= 0); to make sure its not displayed.

[edited by - Extrarius on February 8, 2003 1:36:23 AM]

Share this post


Link to post
Share on other sites
Dave Hunt & Cat_B...Thx,

I think I see what I''m missing...One is the GetCursorPos(), but the real important one is the SetCursorPos()...By setting the cursor back to the middle of the screen, it always starts from the same spot...

adym

Share this post


Link to post
Share on other sites
Thx everyone...This is working great. I was content with a simple rotation around the Y-axis, but looking at the code supplied I expanded it to include the X-axis as well...

Next stop collisions...

adym

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!