Irrlicht in a WinForm!

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Ros
Posts: 30
Joined: Thu Jul 13, 2006 11:30 am
Contact:

Post by Ros »

Which proect should i make console or windows?
and what exactly should i write in Form.cs?
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

I build a WindowApplication1 with C#, and then make irr draw in a picturebox in the center of the form.
But when I add the FPS camera, I can never get the key&mouse control anymore. then where should I set that "InputReceiverEnabled" property?! I can't! I can't do that unless I modify the Irrlicht's source code in WndProc in CIrrDeviceWin32.cpp file. But I haven't tried that yet.

What I want is:
I can have the control of the key & mouse, and when I press a hot key, I will enter the FPS camera mode, and when I press another hot key, I will exit the FPS camera mode, and the form regain the control and could receive event from key and mouse again.

I am making the level editor and this problem really bother me a lot!
I wonder if anyone succeeded without modifying Irr's src?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

michael520,

If any control on the WinForm has focus, then *ALL* events are sent to the WinForm and not Irrlicht Device. Odds are, all of your events are being handled by the WinForm event handler and never passed to IrrlichtDevice. Add a On KeyPress event to your form to see if your WinForm is capturing your events instead of the IrrlichtDevice.

Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

Also, even when I use common AddCameraSceneNode(), the form can't receive KeyPress event:

Code: Select all

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
	switch(e.KeyCode) {
	case Keys.F9:
			MessageBox.Show("F9 pressed");
		break;
	default:
		break;
	}
}
So I found in Irrlicht's source, in WndProc() in CIrrDeviceWin32.cpp:

Code: Select all

case WM_KEYDOWN:
	{
		event.EventType = irr::EET_KEY_INPUT_EVENT;
		event.KeyInput.Key = (irr::EKEY_CODE)wParam;
		event.KeyInput.PressedDown = true;
		dev = getDeviceFromHWnd(hWnd);

		BYTE allKeys[256];
		WORD KeyAsc=0;
		GetKeyboardState(allKeys);
		ToAscii(wParam,lParam,allKeys,&KeyAsc,0);

		event.KeyInput.Shift = ((allKeys[VK_SHIFT] & 0x80)!=0);
		event.KeyInput.Control = ((allKeys[VK_CONTROL] & 0x80)!=0);
		event.KeyInput.Char = KeyAsc; //KeyAsc >= 0 ? KeyAsc : 0;

		if (dev)
			dev->postEventFromUser(event);

		return 0;
	}
//other event has familiar processing.
So, we can see that irr will send all event to those scenenode(cameras), and then return zero, not return DefWindowProc()!@!!

I think this is a big imperfect of Irrlicht.
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

Shurijo, in some applications, we do need to put Irr draw in only a part of a form, and some button/controls in other part. And most of time, putting irr in a picturebox or panel is very convenient for application such as level editor, not games.

Have you ever used IrrEdit? you may understand what I am describing through that.
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

If there's no way :? , I think I have to modify Irrlicht's source code to fit my needs. :wink:

Anyway, I would like to know if anyone solved the problem without modifying irr. :P
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

I've used IrrEdit (Niko is using C++ now instead of C#, maybe you can ask for his C# source code??), but I don't use it right now (I need it to support TerrainSceneNodes for my app).

I understand what you are trying to do and I hope you figure it out (because I'd like to eventually get things working that way, too). I'm using the full IrrlichtDevice window as my main game window and IrrlichtDevice in a PictureBox on my main menu WinForm (for character selection - allows user to select model/texture, etc.). For interacting with the device in the picturebox, I'm only capturing events from the WinForm (such as rotate character, etc.).

In one of my much eariler attempts, I made a map editor (just like your level editor) and got frustrated with having to manage the events on both WinForm and IrrlichtDevice. So I just went to a IrrlichtWindow for that with a separate WinForm with my tool bar (think how Photoshop or GIMP has multiple floating menu/dialogs that you can drag away from the main window). That way, I didn't have to mess with sending the right event to the right eventhandler (all events on that window were recieved by IrrlichtDevice) and all WinForms.UIControl events were handled by my other dialogs and sent to my map irrlichtWindow.
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

I am thinking about how to modify Irr's message processing routines, and make it more friendly for applications such as level editor etc with other window gui elements in the same form...
In fact, this problem exist both in C++ and C# because they both have the same WndProc() in Irrlicht.dll.

It may be a hard job... :arrow:
Ros
Posts: 30
Joined: Thu Jul 13, 2006 11:30 am
Contact:

Post by Ros »

shurijo

say:
Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
How? where i can look example of code? :?: :?: :?:
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

Post by TOP-Proto »

is their a way to use an irrdevice and make that replace a picturebox on a winform so it can get events?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

michael520 wrote:I am thinking about how to modify Irr's message processing routines, and make it more friendly for applications such as level editor etc with other window gui elements in the same form...
In fact, this problem exist both in C++ and C# because they both have the same WndProc() in Irrlicht.dll.

It may be a hard job... :arrow:
I think thats a good idea. I'd love an OverrideKeyPress=true property of the IrrlichtDevice that would ignore it's handle's events (if handle != null).
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

Ros wrote:shurijo

say:
Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).
How? where i can look example of code? :?: :?: :?:
All of the tutorials (with the exception of the WinForm tutorial) use an IrrlichtDevice without placing it on a .NET WinForm.
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

TOP-Proto wrote:is their a way to use an irrdevice and make that replace a picturebox on a winform so it can get events?
That is what you do when you pass the handle of the picturebox into the IrrlichtDevice constructor.
michael520
Posts: 230
Joined: Mon Oct 10, 2005 2:24 am

Post by michael520 »

Maybe I would make it as a mask. Through controling of the mask, we may set which ever events or keycodes to pass to Irr, or not.

I am thinking of the best method of reaching that target.
Ros
Posts: 30
Joined: Thu Jul 13, 2006 11:30 am
Contact:

Post by Ros »

Ros wrote:
shurijo

say:
Quote:
Its much easier to handle events using Irrlicht without putting it in a picturebox (using the IrrlichtDevice window instead of a WinForm).


How? where i can look example of code?


All of the tutorials (with the exception of the WinForm tutorial) use an IrrlichtDevice without placing it on a .NET WinForm.
I don't need console start :(

I need WinForm start without console.
Locked