Jump to content
  • Advertisement
Sign in to follow this  

Implementing Mouse Look

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

Hello! I am trying to implement looking on my camera class and was wondering if this is the right way to do it:



SetCursorPos(NXGPU::GPUContext->ViewportWidth / 2, NXGPU::GPUContext->ViewportHeight / 2);
oldMouseState = NXInput::GetMouseState();


float xDifference = NXInput::GetMouseState().lX - oldMouseState.lX;
float yDifference = NXInput::GetMouseState().lY - oldMouseState.lY;
Yaw -= Sensitivity * xDifference * amount;
Pitch -= Sensitivity * yDifference * amount;

"amount" = gameTime->TotalTime / 1000.0f;


Also, should my camera have its own projection matrix? Thanks! smile.png

Edited by KoldGames

Share this post

Link to post
Share on other sites

No, if the cursor hits the screen edge (even if you can't see the cursor) you'll lose rotation. You need to directly poll the mouse deltas. Is this in Windows?

Share this post

Link to post
Share on other sites
Hey! I accidentally left out a line of code in the post. I also set the cursor position in the update method to keep it centered. And yes this is in windows. Thanks! :)

Share this post

Link to post
Share on other sites
I do that:
Vector3 center, current, delta;


center.x = (float)GetSystemMetrics(SM_CXSCREEN) / 2.0f;
center.y = (float)GetSystemMetrics(SM_CYSCREEN) / 2.0f;
current.x = (float)p.x;
current.y = (float)p.y;
delta = current - center;

SetCursorPos(center.x, center.y);

Also, init the variables with zero values just to guarantee that they are correct.


Something like:

if( fPitch != 0.0f || fYaw != 0.0f)
//do stuff

Trick: update values based on delta time.


camera->Rotate( DEGTORAD(fPitch) * (dt * fSensivity) );

Edited by irlanrobson

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!