irrlicht's hacky fps camera

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

irrlicht's hacky fps camera

Post by Jacky_J »

Code: Select all

if (CursorControl && InputReceiverEnabled && camIsMe )
		{
			core::position2d<f32> cursorpos = CursorControl->getRelativePosition();

			if (!core::equals(cursorpos.X, CenterCursor.X) ||
				!core::equals(cursorpos.Y, CenterCursor.Y))
			{
				RelativeRotation.X *= -1.0f;
				RelativeRotation.Y *= -1.0f;

				RelativeRotation.Y += (0.5f - cursorpos.X) * RotateSpeed;
				RelativeRotation.X = core::clamp (	RelativeRotation.X + (0.5f - cursorpos.Y) * RotateSpeed,
													-MAX_VERTICAL_ANGLE,
													+MAX_VERTICAL_ANGLE
												);

				RelativeRotation.X *= -1.0f;
				RelativeRotation.Y *= -1.0f;

				CursorControl->setPosition(0.5f, 0.5f);
				CenterCursor = CursorControl->getRelativePosition();
			}
		}
Doesn't this seem like a huge hack in irrlicht? Seemingly, the only way to get a delta mouse position is to reset the mouse position to the center of the screen. What if i want to display the mouse cursor and get mouse deltas at the same time? In SDL for example, their event system comes with a mouse delta that is unbounded by the window. Can't irrlicht do something like that?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Seems like a rather intuitive steering way, because others use this as well. You can render other "cursors", controlled by e.g. joysticks, as you wish.
Moreover, mouse deltas just use the old value and check the distance to the current one, this does not require a reset. Just use it :P
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

Post by Jacky_J »

hybrid wrote:Seems like a rather intuitive steering way, because others use this as well. You can render other "cursors", controlled by e.g. joysticks, as you wish.
Moreover, mouse deltas just use the old value and check the distance to the current one, this does not require a reset. Just use it :P
Yes, the only solution in irrlicht is to have a separate cursor.

As far as deltas, the X and Y variables inside SMouseInput are bounded by the screen, so this method doesn't work. Irrlicht just needs to add DeltaX and DeltaY to SMouseInput, much like SDL.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Eagerly awaiting your patch and sample app.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Jacky_J
Posts: 55
Joined: Fri Apr 27, 2007 5:01 am

Post by Jacky_J »

rogerborg wrote:Eagerly awaiting your patch and sample app.
Me too.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

New rule: feature requests including the word "just" need to come with a patch. :P
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
xtayxkjy
Posts: 13
Joined: Sun Nov 16, 2008 8:41 am
Location: China

Post by xtayxkjy »

Post Reply