Page 1 of 1

direct input for irrlicht?

Posted: Sat May 24, 2008 9:41 pm
by Mel
I hope this is the right place to ask... Well considering that direct input is a Direct X feature, i don't hope to see support for future irrlicht releases but i0m wondering if there is already out there any extension to support direct input (to use a controller) as the controls i'm thinking to add into my project would be a bit difficult to use if the only input device is the keyboard.

thanks in advance! :)

Posted: Sat May 24, 2008 10:37 pm
by MasterGod
Sorry I have no other solution for you but I just want to mention that I believe that as long as OpenGL doesn't have this DirectX's input system won't be used.

P.S
And because it has nothing to do with rendering.

Posted: Sat May 24, 2008 11:11 pm
by hybrid
Well, Irrlicht does support input handling, so we might also include Direct Input. But onyl via some proper abstraction, which would also be implementable by other systems (and actually is).

Posted: Sun May 25, 2008 12:49 am
by Halifax
Yeah, I personally think it would be pretty cool to implement some abstractions, and then implement the input handling specifics under that. One reason being that I would like to use XInput just for some fun purposes.

Posted: Sun May 25, 2008 7:39 am
by r2d2
DirectX Input isn't that hard to handle, instead it's quite easy. Implementing it into your own Eventhandler/Inputhandler shouldn't be much of a Problem. I also once used it for an OpenGL app without problems, cause the GLFW InputHandling had some very nasty bugs in C#

Code: Select all

        private Microsoft.DirectX.DirectInput.Device mKeyboard;
        private Microsoft.DirectX.DirectInput.Device mMouse;

...

            mKeyboard = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            mMouse = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);

            mKeyboard.Acquire();
            mMouse.Acquire();

...

        public void update()
        {
            Microsoft.DirectX.DirectInput.MouseState state = mMouse.CurrentMouseState; // this is important cause everytime you call CurrentMouseState the distance the mouse travelled will be queried again and i don't think you will move your mouse very far during two function calls ;) so save the whole state in a variable and get the values from that one
            int mousex = state.X;
            int mousey = state.Y;

            if (mousex != 0)
            {
                float turny = (float)mousex / 5.0f;
                mMouseX = mousex;
                mOr.Z -= turny;
            }
            if (mousey != 0)
            {
                float turnx = (float)mousey / 5.0f;
                mMouseY = mousey;
                mOr.X += turnx;
            }

            if (mKeyboard.GetPressedKeys().Length > 0)
            {
                Microsoft.DirectX.DirectInput.Key[] Keys = mKeyboard.GetPressedKeys();
                for (int i = 0; i < Keys.Length; i++)
                {
                    if (Keys[i] == Microsoft.DirectX.DirectInput.Key.W)
                    {
// there is an error here somwhere, this is mathematically not completely right, but i have been too lazy to iron it out ;)
                        mPos.X += (float)System.Math.Sin(((mOr.Z % 360) / 180.0f) * System.Math.PI) * 0.4f;
                        mPos.Y += (float)System.Math.Cos(((mOr.Z % 360) / 180.0f) * System.Math.PI) * 0.4f;
                        mPos.Z += (float)System.Math.Cos(((mOr.X % 360) / 180.0f) * System.Math.PI) * 0.4f;
                    }

Posted: Sun May 25, 2008 9:22 am
by Nadro
Of course, You can use Direct Input with OpenGL renderer, but only on Windows... but Linux, MacOSX? If You need more advanced input system than currently from Irrlicht You should use: Object Oriented Input System: http://sourceforge.net/projects/wgois Project is cross-platform and it's on the zlib style license:)

Posted: Sat Jun 07, 2008 7:00 am
by kburkhart84
I currently use DInput8 for my projects instead of the Irrlicht's event manager, though I aquire all devices in nonexclusive mode so that Irrlichtr will still recieve input as well. I can freely give out the classes I use if anybody were to want them, though they aren't anything special, they do work.

Posted: Sat Jun 07, 2008 8:36 pm
by d3jake
I'm using SDL to handle joystick input. I got the main code from a member here named "CuteAlien" and it works like a champ. Alien also told me that the code extends to keyboard and mouse (I think so anyway..). The best part is that it is cross platform.