Jump to content
  • Advertisement
Sign in to follow this  
tomneo2004

help window cursor problem

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

I have a problem about windows cursor position. I am trying to simulate first person shooter camera. i keep the cursor on the center of window always and cursor never outside of window, every time the mouse move will turn the camera. below is my code, however, when i run it, come up a black screen and it is not working. if it is successful there is a box with color in front and background color is gray, so i think something wrong with my code can anyone help me? the code here is doing the mouse movement and camera rotation if i change SetCursorPos(cursorpos.x, cursorpos.y) to SetCursorPos(cursorpos.x, 0) it can work but only for x axis why but it come up a black screen with both x and y together.

POINT cursorpos;

	GetCursorPos(&cursorpos);
	ScreenToClient(myframework->GetHWND(), &cursorpos);
	
	if(cursorpos.x>800/2)
	{
	  mycamera->Yaw((float)(cursorpos.x-800/2)*myframework->GetMainTimer()->GetTimeElapsed()*cursorspeed);
	}

	if(cursorpos.x<800/2)
	{
		mycamera->Yaw(-(float)(800/2-cursorpos.x)*myframework->GetMainTimer()->GetTimeElapsed()*cursorspeed);
	}

	if(cursorpos.y>600/2)
	{
		mycamera->Pitch((float)(cursorpos.y-600/2)*myframework->GetMainTimer()->GetTimeElapsed()*cursorspeed);
	}

	if(cursorpos.y<600/2)
	{
		mycamera->Pitch(-(float)(600/2-cursorpos.y)*myframework->GetMainTimer()->GetTimeElapsed()*cursorspeed);
	}

	cursorpos.x=800/2;
	cursorpos.y=600/2;
	ClientToScreen(myframework->GetHWND(), &cursorpos);
	SetCursorPos(cursorpos.x, cursorpos.y);


Share this post


Link to post
Share on other sites
Advertisement
I'm not a getTime guru, but I think that should be called only once per frame, because you get correct result from the first getTimeEllapsed, than just zeros, since no time (or just few CPU cycles) have passed between the other getTimeEllapsed's.

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
I'm not a getTime guru, but I think that should be called only once per frame, because you get correct result from the first getTimeEllapsed, than just zeros, since no time (or just few CPU cycles) have passed between the other getTimeEllapsed's.


well this code is in the member function call MouseMoveEvent trigger when mouse move i do this way because i don't want it to be checked every time.

ok is there anyway to limit mouse cursor in a windows area, also keep it on the center of the window so every time my mouse move then it will check how much my mouse cursor move on x and y and then rotate camera?

Share this post


Link to post
Share on other sites
Just in case GetTimeElapsed() returns zero, why not make a local variable? It'll save (a very small amount of) time and both the x & y functions will use the same value.

float delta = myframework->GetMainTimer()->GetTimeElapsed()*cursorspeed;
if(cursorpos.x>800/2)
{
mycamera->Yaw((float)(cursorpos.x-800/2)*delta);
}
// etc.

Also, why not forget the "if" statements and just use:

mycamera->Yaw((float)(cursorpos.x-800/2)*delta);
mycamera->Pitch((float)(cursorpos.y-600/2)*delta);

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.

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!