Irrlicht.NET EventReceivers
Irrlicht.NET EventReceivers
Hi all.
I am trying to implement the .NET functionality in some classes, and have hit a stumbling block (-well edit: <strike>two</strike>three /edit actually )
1) GUI entities in .NET . I am assuming that these haven't been implemented yet, so short of coding them myself (not feasible in given timespan) I am resorting to creating a windowed instance of the device, and then implementing some chat screens as separate windows that the user can swap between. I know this is not ideal, but it was the best idea I could come up with at short notice. Does anyone have any ideas of alternatives (ideally i would have liked a GUI text window to overlay on the main display)?
2) Event handling. I can see from the .NET documentation from Niko (thanks for making the .NET wrapper! ) that there is some event receiver code present in the latest version of irrlicht, but I can't find any tutorials or guides on this site or in the sdk on how to use them in .NET. Has anyone got any tips or guides they could pass onto me?
edit: 3) Also in the .NET docs is a note about triangles, and how they have been included for collision detection as a direct port from the normal irrlicht code. Again, any tips or help on how to implement these would be appreciated
/edit
Once my project is finished I will make it available for others to use (it should provide a level of abstraction for beginner programmers to use Irrlicht with even less hassle than it currently takes...simple things like a player class and an application class, etc... purpose built collection classes etc...but obviously getting event handling is quite important.
Many thanks in advance.
Gezmo
I am trying to implement the .NET functionality in some classes, and have hit a stumbling block (-well edit: <strike>two</strike>three /edit actually )
1) GUI entities in .NET . I am assuming that these haven't been implemented yet, so short of coding them myself (not feasible in given timespan) I am resorting to creating a windowed instance of the device, and then implementing some chat screens as separate windows that the user can swap between. I know this is not ideal, but it was the best idea I could come up with at short notice. Does anyone have any ideas of alternatives (ideally i would have liked a GUI text window to overlay on the main display)?
2) Event handling. I can see from the .NET documentation from Niko (thanks for making the .NET wrapper! ) that there is some event receiver code present in the latest version of irrlicht, but I can't find any tutorials or guides on this site or in the sdk on how to use them in .NET. Has anyone got any tips or guides they could pass onto me?
edit: 3) Also in the .NET docs is a note about triangles, and how they have been included for collision detection as a direct port from the normal irrlicht code. Again, any tips or help on how to implement these would be appreciated
/edit
Once my project is finished I will make it available for others to use (it should provide a level of abstraction for beginner programmers to use Irrlicht with even less hassle than it currently takes...simple things like a player class and an application class, etc... purpose built collection classes etc...but obviously getting event handling is quite important.
Many thanks in advance.
Gezmo
"DIIIIIIIIIIIIVVVVVVVVVVVVEEEEEEEEEEEEEEE"
A few Answers :
1) GUI entities are not implemented yet, here is a code snippet ( Not the most Brilliant) however it does get some text onthe screen...
Crude I Know, but it gets the job done for my purposes ...
2) For Events I've put some code here http://irrlicht.sourceforge.net/phpBB2/ ... php?t=4850 Somebody else also had this problem.
3) I Haven't tried yet .....
Hope this helps a bit ...
1) GUI entities are not implemented yet, here is a code snippet ( Not the most Brilliant) however it does get some text onthe screen...
Code: Select all
// device is your created device
// font is the texture which comes with irrlicht called fontcourie.bmp
// then you have your x,y Position followed by the text you want displayed
public class DrawFont {
public static void ToScreen( Irrlicht.IrrlichtDevice device, Irrlicht.Video.ITexture font, float x, float y, string Text ){
if( Text.Trim() == "" )
return;
char[] CharList = Text.ToCharArray();
int Char, CharX, CharY;
for( int i=0;i<CharList.Length;i++ ) {
Char = (int) CharList[i] - 32;
CharY = (int)( Char / 28 );
CharX = (int)( Char - ( CharY * 28 ) );
device.VideoDriver.Draw2DImage( font, new Irrlicht.Core.Position2D( (int)(x + (9*i)), (int)y ), new Irrlicht.Core.Rect( new Irrlicht.Core.Position2D( CharX * 9, (CharY * 17) + 1 ), new Irrlicht.Core.Dimension2D( 9, 15 ) ), new Irrlicht.Video.Color( 0, 255, 255, 255 ), true );
}
}
}
2) For Events I've put some code here http://irrlicht.sourceforge.net/phpBB2/ ... php?t=4850 Somebody else also had this problem.
3) I Haven't tried yet .....
Hope this helps a bit ...
Thanks!
Fingers,
Thanks for the reply. Once I get home I will give the two suggestions a try, and post back on the forum with how it went. Thanks also for the post link for event handling...I did do a search, but did not come across that page.
Regards,
Gezmo
Thanks for the reply. Once I get home I will give the two suggestions a try, and post back on the forum with how it went. Thanks also for the post link for event handling...I did do a search, but did not come across that page.
Regards,
Gezmo
"DIIIIIIIIIIIIVVVVVVVVVVVVEEEEEEEEEEEEEEE"
OOps ... !!!!!!
Hi Gezmo
I Forgot to post this yesturday
When loading the Texture for the font
If you don't make colorkey, the background of the font is not transparent ..
Cheers
I Forgot to post this yesturday
When loading the Texture for the font
Code: Select all
fontTexture = device.VideoDriver.GetTexture(@"fontcourier.bmp");
device.VideoDriver.MakeColorKeyTexture( fontTexture, new Irrlicht.Video.Color(0,0,0,0) );
Cheers
projet
hello all
me also I work has on a irrlicht project for vb.net
for the moment I have to add some procedures like
"addwallscenenode, addfloorscenenode" directly in the procedure "iscenenode"
now I work on the collision "boundingbox" between two objects,
if have meter our knowledge in comun can
me also I work has on a irrlicht project for vb.net
for the moment I have to add some procedures like
"addwallscenenode, addfloorscenenode" directly in the procedure "iscenenode"
now I work on the collision "boundingbox" between two objects,
if have meter our knowledge in comun can
Hi,
here's an example of event receivers. I am doing a project in C#.
Wouldn't it be great to start a .NET Forum topic for all .NET related issues?
By the way does anyone know how to create just a normal mesh object using the .NET library? I mean not an animated Mesh but a static mesh from a .X file? Is it possible?
Thanks, and hope this is useful!
//this is an inner class in your main class
public class MyEventReceiver : IEventReceiver {
public virtual bool OnEvent(Irrlicht.Event event1) {
/*
If the key 'W' is pressed and released, we get the position of the scene node,
and modify the Y coordinate a little bit. So if you press 'W', the node
moves up, and if you press 'S' it moves down.
*/
const int A = 65;
const int G = 71;
const int H = 72;
const int D = 68;
const int K = 75;
const int L = 76;
const int S = 83;
const int W = 87;
const int LEFT_ARROW = 37;
const int RIGHT_ARROw = 39;
const int UP_ARROW = 38;
const int DOWN_ARROW = 40;
const int ESC = 27;
if(node != null && event1.Type == Irrlicht.EventType.MouseInput) {
//switch(event1.MouseWheelDeltaCa e
switch(event1.MouseInputType) {
case MouseInputEvent.MouseWheel: {
Vector3D camPos = cam.Position;
camPos.RotateYZBy(event1.MouseWheelDelta * 2, node.Position);
cam.Position = camPos;
break;
}
}
return true;
}
if (node != null && event1.Type == Irrlicht.EventType.KeyInput && event1.KeyPressedDown) {
Vector3D v;
switch(event1.Key) {
case A:
v = node.Position;
v.X -= 5.0f;
node.Position = v;
break;
case D:
v = node.Position;
v.X += 5.0f;
node.Position = v;
break;
case W:
v = node.Position;
v.Y += 5.0f;
node.Position = v;
break;
case S:
v = node.Position;
v.Y -= 5.0f;
node.Position = v;
break;
case L: //Move towards the screen
v = node.Position;
v.Z -= 5.0f;
node.Position = v;
break;
case K: //Move away from the screen
v = node.Position;
v.Z += 5.0f;
node.Position = v;
break;
case G: {
Vector3D rot = new Vector3D(0, node.Rotation.Y + 5.0f, 0);
node.Rotation = rot;
break;
}
case H: {
Vector3D rot = new Vector3D(0, node.Rotation.Y - 5.0f, 0);
node.Rotation = rot;
break;
}
//rotates above the scene
case UP_ARROW: {
Vector3D camPos = cam.Position;
camPos.Z += 10;
//camPos.RotateYZBy(15, node.Position);
cam.Position = camPos;
break;
}
//rotates below the scene
case DOWN_ARROW: {
Vector3D camPos = cam.Position;
camPos.Z -= 10;
//camPos.RotateYZBy(-15, node.Position);
cam.Position = camPos;
break;
}
case ESC:
device.CloseDevice();
break;
}
return true;
}
return false;
}
//return false;
}
//add this in your main code
device = new IrrlichtDevice(DriverType.OPENGL, new Irrlicht.Core.Dimension2D(640, 480), 16, false, false, false);
device.EventReceiver = new MyEventReceiver();
here's an example of event receivers. I am doing a project in C#.
Wouldn't it be great to start a .NET Forum topic for all .NET related issues?
By the way does anyone know how to create just a normal mesh object using the .NET library? I mean not an animated Mesh but a static mesh from a .X file? Is it possible?
Thanks, and hope this is useful!
//this is an inner class in your main class
public class MyEventReceiver : IEventReceiver {
public virtual bool OnEvent(Irrlicht.Event event1) {
/*
If the key 'W' is pressed and released, we get the position of the scene node,
and modify the Y coordinate a little bit. So if you press 'W', the node
moves up, and if you press 'S' it moves down.
*/
const int A = 65;
const int G = 71;
const int H = 72;
const int D = 68;
const int K = 75;
const int L = 76;
const int S = 83;
const int W = 87;
const int LEFT_ARROW = 37;
const int RIGHT_ARROw = 39;
const int UP_ARROW = 38;
const int DOWN_ARROW = 40;
const int ESC = 27;
if(node != null && event1.Type == Irrlicht.EventType.MouseInput) {
//switch(event1.MouseWheelDeltaCa e
switch(event1.MouseInputType) {
case MouseInputEvent.MouseWheel: {
Vector3D camPos = cam.Position;
camPos.RotateYZBy(event1.MouseWheelDelta * 2, node.Position);
cam.Position = camPos;
break;
}
}
return true;
}
if (node != null && event1.Type == Irrlicht.EventType.KeyInput && event1.KeyPressedDown) {
Vector3D v;
switch(event1.Key) {
case A:
v = node.Position;
v.X -= 5.0f;
node.Position = v;
break;
case D:
v = node.Position;
v.X += 5.0f;
node.Position = v;
break;
case W:
v = node.Position;
v.Y += 5.0f;
node.Position = v;
break;
case S:
v = node.Position;
v.Y -= 5.0f;
node.Position = v;
break;
case L: //Move towards the screen
v = node.Position;
v.Z -= 5.0f;
node.Position = v;
break;
case K: //Move away from the screen
v = node.Position;
v.Z += 5.0f;
node.Position = v;
break;
case G: {
Vector3D rot = new Vector3D(0, node.Rotation.Y + 5.0f, 0);
node.Rotation = rot;
break;
}
case H: {
Vector3D rot = new Vector3D(0, node.Rotation.Y - 5.0f, 0);
node.Rotation = rot;
break;
}
//rotates above the scene
case UP_ARROW: {
Vector3D camPos = cam.Position;
camPos.Z += 10;
//camPos.RotateYZBy(15, node.Position);
cam.Position = camPos;
break;
}
//rotates below the scene
case DOWN_ARROW: {
Vector3D camPos = cam.Position;
camPos.Z -= 10;
//camPos.RotateYZBy(-15, node.Position);
cam.Position = camPos;
break;
}
case ESC:
device.CloseDevice();
break;
}
return true;
}
return false;
}
//return false;
}
//add this in your main code
device = new IrrlichtDevice(DriverType.OPENGL, new Irrlicht.Core.Dimension2D(640, 480), 16, false, false, false);
device.EventReceiver = new MyEventReceiver();
Pete
Life is wonderful
Life is wonderful
Tried CursorControl
Code: Select all
Irrlicht.Core.Position2Df p = device.CursorControl.Positionf;
p.Y++;
device.CursorControl.Positionf = p;
Code: Select all
Irrlicht.Core.Position2D p = device.CursorControl.Position;
p.Y++;
device.CursorControl.Position = p;
Rather use the Position, instead of Positionf ..... (2d screen works in units anyways, no point in using float values [ Just My Opinion ] )
Re: Tried CursorControl
float saves a lot of trouble... now, in order to get the mouse position relative to the middle of the screen, i have to divide it with the screen size by hand...Fingers wrote: Rather use the Position, instead of Positionf ..... (2d screen works in units anyways, no point in using float values [ Just My Opinion ] )
Re: Tried CursorControl
both stops my rendering... if i comment out "device.CursorControl.Position = p;", everything works fine, if not, no rendering takes place.Fingers wrote:^^ That code does not stop my rendering, but has a undesirable effect on my cursor ....Code: Select all
Irrlicht.Core.Position2Df p = device.CursorControl.Positionf; p.Y++; device.CursorControl.Positionf = p;
^^ This code however does work and the cursor does exactly what it's supposed to ....Code: Select all
Irrlicht.Core.Position2D p = device.CursorControl.Position; p.Y++; device.CursorControl.Position = p;
Rather use the Position, instead of Positionf ..... (2d screen works in units anyways, no point in using float values [ Just My Opinion ] )
Hi, ive rewritten the code to put text into an irrlicht-device with VB.NET..
Cuz the C-Code isnt compatible ofcourse.. but now it wont work LOL
Anyone has a suggestion why it wont work?
Cuz the C-Code isnt compatible ofcourse.. but now it wont work LOL
Anyone has a suggestion why it wont work?
Code: Select all
Public Sub DrawFont(ByVal device As IrrlichtDevice, ByVal font As Video.ITexture, ByVal x As Integer, ByVal y As Integer, ByVal Text As String)
Dim CharList As Char() = Text.ToCharArray()
Dim CharT, CharX, CharY As Integer
Dim I As Integer = 0
For I = 0 To CharList.Length
CharT = Int(CharList(I)) - 32
CharY = CharT / 28
CharX = CharT - (CharY * 28)
device.VideoDriver.Draw2DImage(font, New Irrlicht.Core.Position2D((x + (9 * I)), y), New Irrlicht.Core.Rect(New Irrlicht.Core.Position2D(CharX * 9, (CharY * 17) + 1), New Irrlicht.Core.Dimension2D(9, 15)), New Irrlicht.Video.Color(0, 255, 255, 255), True)
Next
End Sub