mouse look

Problems building or running the engine, queries about how to use features etc.
Post Reply
xmanneke
Gnoblar
Posts: 17
Joined: Fri Jan 15, 2010 8:31 pm
x 1

mouse look

Post by xmanneke »

Ogre Version: : 3.0:
Operating System: : windows 11:
Render System: : any :

Hi,

I'm having an issue with my application.
I am trying to make it so that i can look around with the mouse movement.
On the samples i found the code on how to do this but when i try this it is really twitchy.
So when i move the mouse a small amount it moves the game like crazy.
I checked it with multiple fps but it stays the same

I can slow it down by multiplying the width and height by 10 but then the movement seems to lag behind

Does anybody know how to do this correct or improve this?

Mouse Move code

Code: Select all

void OgreGame::InputHandler::mouseMoved(const SDL_Event& evt)
{
	float width = static_cast<float>(1024);
	float height = static_cast<float>(786);
	
	mCameraYaw += float( -evt.motion.xrel ) / width;
	mCameraPitch += float( -evt.motion.yrel ) / height;
}

Camera Set Orientation code

Code: Select all

void OgreGame::Camera::setOrientation(float _yaw, float _pitch)
{
	m_Camera->yaw(Ogre::Radian(_yaw));
	m_Camera->pitch(Ogre::Radian(_pitch));
}
chilly willy
Halfling
Posts: 86
Joined: Tue Jun 02, 2020 4:11 am
x 34

Re: mouse look

Post by chilly willy »

We don't see the call to OgreGame::Camera::setOrientation() but I assume you pass it mCameraYaw and mCameraPitch. Those two variables, unless you are clearing them each frame, are the accumulated absolute angles (because of the += operator). But the Camera::yaw() and Camera::pitch() functions expect delta angles and apply them to the existing orientation.

xmanneke
Gnoblar
Posts: 17
Joined: Fri Jan 15, 2010 8:31 pm
x 1

Re: mouse look

Post by xmanneke »

Yeah you are right
I was just looking at it again and indeed i was adding them so it accumulated the angles and went crazy
So just removed the + and assigned the direct and it now works

thx for the help

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 403
Joined: Fri May 23, 2025 5:04 pm
x 33

Re: mouse look

Post by slapin »

Also when doing things like that, use delta time to make movement less choppy and more predictable.

rpgplayerrobin
Bugbear
Posts: 809
Joined: Wed Mar 18, 2009 3:03 am
x 471

Re: mouse look

Post by rpgplayerrobin »

slapin wrote: Wed Sep 02, 2026 9:09 am

Also when doing things like that, use delta time to make movement less choppy and more predictable.

Actually, I do not think that is correct.
Since the movement of the mouse is absolute (say for example, 200 pixels to the right), rotating the camera could be instant with just that value in mind.
Multiplying it with delta time would make it incorrect, as your camera movement would then be faster when on a low FPS.

If they are after a first person mouse look (such as in Counter Strike), delta time should not be used.

slapin
Bronze Sponsor
Bronze Sponsor
Posts: 403
Joined: Fri May 23, 2025 5:04 pm
x 33

Re: mouse look

Post by slapin »

rpgplayerrobin wrote: Wed Sep 02, 2026 3:13 pm
slapin wrote: Wed Sep 02, 2026 9:09 am

Also when doing things like that, use delta time to make movement less choppy and more predictable.

Actually, I do not think that is correct.
Since the movement of the mouse is absolute (say for example, 200 pixels to the right), rotating the camera could be instant with just that value in mind.
Multiplying it with delta time would make it incorrect, as your camera movement would then be faster when on a low FPS.

If they are after a first person mouse look (such as in Counter Strike), delta time should not be used.

You are right, I was speaking about motion controller in general, FPS rotation does not need this. Third person rotation needs this only for specific cases. delta time is mostly for other things.

Post Reply