modifying the camera controls

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

modifying the camera controls

Post by [dx/x]=HUNT3R »

Is there a way to override the camera controls and set different keys, like W,S,A,D instead of the arrows?

Is there a way to change the speed of the camera while moving? Such as, increase the speed the longer the up button is held down (to a max) and keep moving forward at that speed after the button is released. Then there could be a way to slow down such as pressing the down button.

Is there a way to make the camera able to flip over instead of stopping the rotation when looking straight up and down. I want it to be able to move freely around in all directions with no restrictions. This would of course cause the camera to end up rotated on it sides, etc. after moving around but that is what I'm looking for. Will this require hacking into the actual engine code for the camera?
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

No need to hack the Irrlicht camera classes, you can override the camera controls in your OnEvent or create your own camera class that implements off of ICameraSceneNode.
Crud, how do I do this again?
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Yeah thats what I was thinking. I just don't see how to do it. Do you?
wornaki
Posts: 54
Joined: Sat Aug 23, 2003 1:18 am
Location: Argentina, South America

Post by wornaki »

I think there was a similar thread somewhere in this forum or in sourceforge where the matter was settled but I'm not sure. Anyway, check!
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

I know there's not anything in this forum, I checked the old one though and the closest thing I could find was a question on disabling mouse camera control. In which Niko said to derive a new camera class and create the input from scratch. So I guess I'm gonna have to do this in order to make my "SpaceCamera" that can rotate and move in all directions and have user-defined controls. So, anyone know how to get the mouse input? Maybe I'll just find the FPSCamera class, copy it, and modify it to do what I want for my camera...

Is there an easier way to just override the FPSCamera :?:
cyberbobjr
Posts: 64
Joined: Mon Sep 08, 2003 8:21 am
Location: Paris, France

Post by cyberbobjr »

Yeah,
I'm interested too for making a "RTS like" camera :)
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Yanking this straight from CCameraFPSSceneNode.c

Code: Select all

s32 now = os::Timer::getTime();
	s32 moved = now - LastKeyTime;
	LastKeyTime = now;

	// Update rotation

	Target.set(0,0,1);

	if (!CursorControl)
		return;

	core::position2d<f32> cursorpos = CursorControl->getRelativePosition();

	if (cursorpos.X < 0.49f || cursorpos.X > 0.51f ||
		cursorpos.Y < 0.49f || cursorpos.Y > 0.51f)
	{
		RotationX += (0.5f - cursorpos.X) * RotateSpeed;
		RotationY += (0.5f - cursorpos.Y) * RotateSpeed;
		CursorControl->setPosition(0.5f, 0.5f);

		if (RotationY > 89.0f)	RotationY = 89.0f;
		if (RotationY < -89.0f)	RotationY = -89.0f;
	}

	// set target

	core::matrix4 mat;
	mat.setRotationDegrees(core::vector3df(-RotationY, -RotationX, 0));
	mat.transformVect(Target);
It basically just says, if the camea isn't at 0.5,0.5 (dead center) then move the camera and move the cursor back to center.

You can override this by adding to your app:

Code: Select all

/*----------------------------------------------------------------------------------------------
Event Handler
----------------------------------------------------------------------------------------------*/
bool MyApp::OnEvent(irr::SEvent event)
{
	if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
	{
		//I'll do my own mouse handling here
		return false;
	} else {
		return device->getSceneManager()->getActiveCamera()->OnEvent(event);
	}
}
Crud, how do I do this again?
cyberbobjr
Posts: 64
Joined: Mon Sep 08, 2003 8:21 am
Location: Paris, France

Post by cyberbobjr »

Here is my bad and ugly code :
With this, i can move camera by stay clicked on the right mouse button and moving the mouse.
Is not optimized, just for the demo.

I just put this in my declaration :

Code: Select all

	bool stayRClicked;
	s32 oldMouseInputX, oldMouseInputY;
And after, in my OnEvent interface, i code this :

Code: Select all

	if (event.EventType==EET_MOUSE_INPUT_EVENT && stayRClicked && event.MouseInput.Event==EMIE_MOUSE_MOVED)
	{
		s32 deltaX=oldMouseInputX-event.MouseInput.X;
		s32 deltaZ=oldMouseInputY-event.MouseInput.Y;
		vector3df deltaXZ(deltaZ,0,deltaX);
		vector3df positionCamera(camera->getPosition());
		vector3df targetCamera(camera->getTarget());
		positionCamera+=deltaXZ;
		targetCamera+=deltaXZ;
		camera->setTarget(targetCamera);
		camera->setPosition(positionCamera);
		oldMouseInputX=event.MouseInput.X;
		oldMouseInputY=event.MouseInput.Y;
	}

	if (event.EventType==EET_MOUSE_INPUT_EVENT && 
			event.MouseInput.Event==EMIE_RMOUSE_PRESSED_DOWN)
	{
		stayRClicked=true;
		oldMouseInputX=event.MouseInput.X;
		oldMouseInputY=event.MouseInput.Y;
	}
	if (event.EventType==EET_MOUSE_INPUT_EVENT && 
			event.MouseInput.Event==EMIE_RMOUSE_LEFT_UP)
	{
		stayRClicked=false;
	}
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

N00b attack

Post by Tyn »

I was thinking, once you have disabled the rotation and movement settings of the FPS camera how hard would it be to implement a simple screen scroll ala the RTS games of today. The below code probably has a few syntax error's coz I am shattered at the moment but you should be able to see what I am getting at:

Code: Select all

core::position2d<s32> mousePos = device->getCursorControl()->getPosition();

bool screenScrollLeft ()
{
return (mousePos.X == 0f)
}

if (screenScrollLeft = true)
{
// Move camera Left
}
And so on for the other 3 movements. Set a small increment in there and it should make the screen scroll as long as the mouse is at the far of the screen.
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Actually I was trying to make the game have realistic space physics. I just got it working last night with a lot of modifications to the CCameraFPSSceneNode class and it works freakin awesome... just like flying in zero-gravity. With v0.4.1 Niko made it possible to define additional control keys so the only problem I have left to solve is the rotations. I plan to add a right vector in the engine code in addition to the upVector and use the cross product of the right and target vector to constantly calculate a new upVector so that the player can fully rotate around 360 deg upside down, etc. I hope it works, has anyone else tried this??? :?:
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Post by Chev »

I'm trying the exact same thing right now. I don't quite understand what the cameras are doing sometimes. I can't seem to turn the event receiver off for the FPS camera since version 0.4.1 (setInputReceiverEnabled' : is not a member of 'ICameraSceneNode) even though the documentation says it is. The other problem I'm having is the standard ICameraSceneNode seems to ignore 'Rotation' changes and only responds to 'Target' changes. Changing this target 100 times a second has wierd results for me thus far. I welcome any advice :).
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Post by Chev »

I think I'm going to try using a standard camera that is at or near a 2nd "player" node (ISceneNode) parent and always "Targets" it. Then I think I can "rotate" the player node and the camera will as well. I'll respond back if it works :P
Post Reply