How to implement a WASD interface and invert the mouse?

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
anon

How to implement a WASD interface and invert the mouse?

Post by anon »

What's the easiest way to make a WASD camera; and also make it so pointing up with the mouse makes you look down, not up?

I tried to extend CCameraFPSSceneNode and override the OnEvent function, but things are set up so that you can't get to the CCameraFPSSceneNode class without recompiling the entire library which is a pain.

I also tried building up my own camera class from ICameraSceneNode but I got strange runtime errors from C++ about the EPS register when the ICameraSceneNode constructor is called. I think that's because of an inconstency between the way the irrlicht DLL is built and what my compiler thinks is the way things should work.

:?:
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

There are two ways to do this WITHOUT the need of modifying or recompiling the engine:

1) Get the key events in your event receiver and sent them modified to your camera.
2) Set a keymap when creating the camera. This works since 0.4.1
anon

Post by anon »

Grabbing the events works for WASD, but to invert the mouse the source has to be recompiled.
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Re: How to implement a WASD interface and invert the mouse?

Post by rt »

anon wrote:I also tried building up my own camera class from ICameraSceneNode but I got strange runtime errors from C++ about the EPS register when the ICameraSceneNode constructor is called. I think that's because of an inconstency between the way the irrlicht DLL is built and what my compiler thinks is the way things should work.
i derived my own camera class and i initally got the same "esp register" error message when the contstuctor was called... however, after changing one of the parameters in the contstructor the class now works perfectly! it's much easier to send events directly to the active camera now and makes the code much cleaner. this is what my class looks like:

Code: Select all

// in the .h file..
class HouseCam : public irr::scene::CCameraSceneNode {
public:
	HouseCam();
	virtual bool OnEvent(irr::SEvent event);

	void UpdateCameraPos();

	bool down,up,left,right;
};

// in .cpp file...
HouseCam::HouseCam() : CCameraSceneNode(g_irr.smgr->getRootSceneNode(),g_irr.smgr,-1){
	down = up = left = right = false; //nice syntax :)
}

void HouseCam::UpdateCameraPos() {
	if (down) {
		this->setPosition( this->getPosition() + irr::core::vector3df(-3,0,0) );
		this->setTarget( this->getTarget() + irr::core::vector3df(-3,0,0) );
	}
	if (up) {
		this->setPosition( this->getPosition() + irr::core::vector3df(3,0,0) );
		this->setTarget( this->getTarget() + irr::core::vector3df(3,0,0) );
	}
	if (left) {
		this->setPosition( this->getPosition() + irr::core::vector3df(0,0,3) );
		this->setTarget( this->getTarget() + irr::core::vector3df(0,0,3) );
	}
	if (right) {
		this->setPosition( this->getPosition() + irr::core::vector3df(0,0,-3) );
		this->setTarget( this->getTarget() + irr::core::vector3df(0,0,-3) );
	}
	this->updateAbsolutePosition();
}

bool HouseCam::OnEvent( irr::SEvent event ) {
	if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
		if (event.KeyInput.PressedDown) { //key pressed
			if (event.KeyInput.Key == irr::KEY_UP) up = true;
			else if (event.KeyInput.Key == irr::KEY_DOWN) down = true;
			else if (event.KeyInput.Key == irr::KEY_LEFT) left = true;
			else if (event.KeyInput.Key == irr::KEY_RIGHT) right = true;
		} else { //key released
			if (event.KeyInput.Key == irr::KEY_UP) up = false;
			else if (event.KeyInput.Key == irr::KEY_DOWN) down = false;
			else if (event.KeyInput.Key == irr::KEY_LEFT) left = false;
			else if (event.KeyInput.Key == irr::KEY_RIGHT) right = false;
		}
	}
	return true;
}
the global pointer g_irr points to the irrlicht engine

i copied the files CCameraSceneNode.h and .cpp to my project folder and added them to the project, then derived a class from them.

let me know if this helps! also let me know if you found a better way to do this!
Post Reply