Invert Camera Mouse Control

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
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

Invert Camera Mouse Control

Post by [ds] Swift »

how would i go about inverting the mouse that controls a camera. it would be and usually is a great option for fps games!

thanx.. josh
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

It could be easily implemented in the source I guess. But it's not atm. I'll take a look at it.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

I just succesfully implemented it in the source. I'll edit this post with the changes soon: then you can change them too and recompile the dll and lib file :).

Changes:

in ISceneManager.h:
change

Code: Select all

virtual ICameraSceneNode* addCameraSceneNodeFPS(ISceneNode* parent = 0,
			f32 rotateSpeed = 100.0f, f32 moveSpeed = 500.0f, s32 id=-1,
			SKeyMap* keyMapArray=0, s32 keyMapSize=0) = 0;
to

Code: Select all

virtual ICameraSceneNode* addCameraSceneNodeFPS(ISceneNode* parent = 0,
			f32 rotateSpeed = 100.0f, f32 moveSpeed = 500.0f, s32 id=-1,
			SKeyMap* keyMapArray=0, s32 keyMapSize=0, bool invert=false) = 0;
in CSceneManager.h
change

Code: Select all

//! Adds a camera scene node which is able to be controled with the mouse and keys
		//! like in most first person shooters (FPS): 
		virtual ICameraSceneNode* addCameraSceneNodeFPS(ISceneNode* parent = 0,
			f32 rotateSpeed = 1500.0f, f32 moveSpeed = 200.0f, s32 id=-1,
			SKeyMap* keyMapArray=0, s32 keyMapSize=0);
to

Code: Select all

//! Adds a camera scene node which is able to be controled with the mouse and keys
		//! like in most first person shooters (FPS): 
		virtual ICameraSceneNode* addCameraSceneNodeFPS(ISceneNode* parent = 0,
			f32 rotateSpeed = 1500.0f, f32 moveSpeed = 200.0f, s32 id=-1,
			SKeyMap* keyMapArray=0, s32 keyMapSize=0, bool invert=false);
in CSceneManager.cpp:
change

Code: Select all

//! Adds a camera scene node which is able to be controled with the mouse and keys
//! like in most first person shooters (FPS): 
ICameraSceneNode* CSceneManager::addCameraSceneNodeFPS(ISceneNode* parent,
	f32 rotateSpeed, f32 moveSpeed, s32 id,
	SKeyMap* keyMapArray, s32 keyMapSize)
{
	if (!parent)
		parent = this;

	ICameraSceneNode* node = new CCameraFPSSceneNode(parent, this, CursorControl, 
		id, rotateSpeed, moveSpeed, keyMapArray, keyMapSize);
	node->drop();

	setActiveCamera(node);

	return node;
}
to

Code: Select all

//! Adds a camera scene node which is able to be controled with the mouse and keys
//! like in most first person shooters (FPS): 
ICameraSceneNode* CSceneManager::addCameraSceneNodeFPS(ISceneNode* parent,
	f32 rotateSpeed, f32 moveSpeed, s32 id,
	SKeyMap* keyMapArray, s32 keyMapSize, bool invert)
{
	if (!parent)
		parent = this;

	ICameraSceneNode* node = new CCameraFPSSceneNode(parent, this, CursorControl, 
		id, rotateSpeed, moveSpeed, keyMapArray, keyMapSize, invert);
	node->drop();

	setActiveCamera(node);

	return node;
}
in CCameraSceneNodeFPS.h
change

Code: Select all

//! constructor
		CCameraFPSSceneNode(ISceneNode* parent, ISceneManager* mgr, 
			gui::ICursorControl* cursorControl, s32 id,
			f32 rotateSpeed, f32 moveSpeed,
			SKeyMap* keyMapArray, s32 keyMapSize);
to

Code: Select all

//! constructor
		CCameraFPSSceneNode(ISceneNode* parent, ISceneManager* mgr, 
			gui::ICursorControl* cursorControl, s32 id,
			f32 rotateSpeed, f32 moveSpeed,
			SKeyMap* keyMapArray, s32 keyMapSize, bool invert);
and add this in the private variables (you could add it under bool CursorKeys[4], because it's also a boolean variable)

Code: Select all

bool Invert;
in CCameraSceneNodeFPS.cpp:
Change the constructor to:

Code: Select all

//! constructor
CCameraFPSSceneNode::CCameraFPSSceneNode(ISceneNode* parent, ISceneManager* mgr,
		gui::ICursorControl* cursorControl, s32 id, f32 rotateSpeed , f32 moveSpeed,
		SKeyMap* keyMapArray, s32 keyMapSize, bool invert)
: CCameraSceneNode(parent, mgr, id), CursorControl(cursorControl),
	MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), Invert(invert), firstUpdate(true)
In the CCameraFPSSceneNode::animate() function, add this under the line mat.transformVect(Target);

Code: Select all

if (Invert)
        Target.invert();
Use:

addCameraSceneNodeFPS() function: the last variable is now a boolean variable called "invert", set this to true to invert the mouse (default is false).

I think those were the small things I changed. If it doesn't work properly (it could be I've forgotten posting a change) or you cannot compile the source, please post it here :).
Last edited by bal on Sun Nov 14, 2004 9:31 am, edited 3 times in total.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Yokom
Posts: 30
Joined: Sat Oct 09, 2004 10:50 pm

Post by Yokom »

should ask what platform you running on unless we are to assume windows using directinput.
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Yokom wrote:should ask what platform you running on unless we are to assume windows using directinput.
There's no need for that, Irrlicht's "high-level" input is already platform-independant... Inverting a matrix did the job (don't know if this is mathematically correct but it works like a charm).
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

Post by [ds] Swift »

i cant get the source to compile on my pc, so modifying it would be pretty pointless :( . if you could tell me how to fix the build problem that would be great.
i get 68 errors about unresolved external symbols :!: .

you can see the log here:

http://www.dialogdesigns.com/BuildLog.htm

i am using windows xp pro w/ latest sp and using visual studio .NET 2005 Source Build ( just a little newer than 2005 beta, but is pretty much the same )
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Are you sure your libraries etc are set up correctly (DirectX 9.0c library etc.)? You should not include your old library file as a library! The include directories should be eventually DX9.0c's and Irrlicht's. That's all.

Link errors are quite weird, but mostly caused by wrong/missing libraries.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

Post by [ds] Swift »

i should. i have it set in the global progrct settings under vc++ directories. my irllicht programs compile, just not the source. so maybe there is some library files besides the ones needed to make programs in order to buildsource? i hate link errors, there the only things that really p* me off when i program :evil:
Post Reply