irrXbox360Controller

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki

irrXbox360Controller

Postby lug » Tue Dec 26, 2006 6:33 pm

Image

I've spent like a day on this. The picture above is from the simple test program based on the DirectX December SDK example of the same name. Of course, it's running inside irrlicht. :)

Here's what the example code looks like:

Code: Select all
#include <iostream>
#include "CIrrXbox360Controller.h"

// hide the console window
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")

int main()
{
    // create xbox 360 controller class
    irr::xb360controller::CIrrXbox360Controller xb360Controller;

    // create device
    IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600));

    if (device == 0)
        return 1; // could not create selected driver.

    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    gui::IGUIEnvironment* env = device->getGUIEnvironment();

    driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

    // add irrlicht logo
    env->addImage(driver->getTexture("media/irrlichtlogoalpha.tga"),
        core::position2d<s32>(10,10));

    // add explanation text
    gui::IGUIStaticText* textExplanation = env->addStaticText(
        L"This sample displays the state of all 4 XInput controllers\nPress 'D' to toggle dead zone clamping.",
        core::rect<s32>(130,10,500,70), false, true, 0, -1, false);

    // add test value text
    gui::IGUIStaticText* textTestValues = env->addStaticText(
        L"Buttons: ",
        core::rect<s32>(130,90,550,800), false, true, 0, -1, false);

    video::SColor textColor(255,255,255,255);
    textExplanation->setOverrideColor(textColor);
    textTestValues->setOverrideColor(textColor);

    // disable mouse cursor
    device->getCursorControl()->setVisible(false);

    int lastFPS = -1;
    u32 dwResult = 0;
    wchar_t sz[1024];

    video::SColor background(0,85,153,240);

    while(device->run())
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, background );

            smgr->drawAll();
            env->drawAll();

            // Simply get the state of the controller from XInput.
            dwResult = xb360Controller.getXInputState(0);

            if(dwResult == ERROR_SUCCESS)
                xb360Controller.setConnected(true);
            else
                xb360Controller.setConnected(false);

            if(xb360Controller.isConnected())
            {
                WORD wButtons = xb360Controller.getButtons();

                swprintf(sz,1024,
                    L"Controller %d: Connected\n"
                    L"  Buttons: %s%s%s%s%s%s%s%s%s%s%s%s%s%s\n"
                    L"  Left Trigger: %d\n"
                    L"  Right Trigger: %d\n"
                    L"  Left Thumbstick: %d/%d\n"
                    L"  Right Thumbstick: %d/%d", 0,
                    (wButtons & XINPUT_GAMEPAD_DPAD_UP) ? L"DPAD_UP " : L"",
                    (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) ? L"DPAD_DOWN " : L"",
                    (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) ? L"DPAD_LEFT " : L"",
                    (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) ? L"DPAD_RIGHT " : L"",
                    (wButtons & XINPUT_GAMEPAD_START) ? L"START " : L"",
                    (wButtons & XINPUT_GAMEPAD_BACK) ? L"BACK " : L"",
                    (wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? L"LEFT_THUMB " : L"",
                    (wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? L"RIGHT_THUMB " : L"",
                    (wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? L"LEFT_SHOULDER " : L"",
                    (wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? L"RIGHT_SHOULDER " : L"",
                    (wButtons & XINPUT_GAMEPAD_A) ? L"A " : L"",
                    (wButtons & XINPUT_GAMEPAD_B) ? L"B " : L"",
                    (wButtons & XINPUT_GAMEPAD_X) ? L"X " : L"",
                    (wButtons & XINPUT_GAMEPAD_Y) ? L"Y " : L"",
                    xb360Controller.getLeftTrigger(),
                    xb360Controller.getRightTrigger(),
                    xb360Controller.getThumbLX(),
                    xb360Controller.getThumbLY(),
                    xb360Controller.getThumbRX(),
                    xb360Controller.getThumbRY() );

                textTestValues->setText(sz);
            }
            else
            {
                swprintf(sz, 1024,                 
                    L"Controller %d: Not connected", 0 );

                textTestValues->setText(sz);
            }

            driver->endScene();

            // display frames per second in window title
            int fps = driver->getFPS();
            if (lastFPS != fps)
            {
                core::stringw str = L"XBOX 360 Controller: SimpleController Test [";
                str += driver->getName();
                str += "] FPS:";
                str += fps;

                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }

        device->drop();

        return 0;
}



The goal is to be able to support the XInput API (XBOX 360 Controller) from the DirectX SDK inside irrlicht (yes, I know about SDL and OSI). Right now, it doesn't do much (detect button presses and analog stick movements). :)

TODO:

- rumble support (shouldn't be that hard to add)
- camera that uses the analog sticks for mouse movement
- bind the buttons to irrlicht keys without changing the irrlicht inner code

:D

Update:

Image

Rumble support is in! :)

Here's a win32 binary to try it out:

http://www.megaupload.com/?d=YDNXCUA0

Update 2:

Image

Analog controlled camera and character rotation working! Camera code based on the "Dead Easy 3rd Person Camera" from here:

http://irrlicht.sourceforge.net/phpBB2/ ... php?t=7977

The left thumb stick controls the character rotation. The right thumb stick controls the camera rotation. Right now, everything is too fast. I need to fine tune the math a bit.

Anyway, give it a whirl:

http://www.megaupload.com/?d=IBP2UZI0

Update 3:

Yay! :D Now I have mapped the different animation of the model to the various xbox 360 buttons:

"A" button for attack:
Image

Left thumb button for crouch:
Image

Left shoulder button for flip:
Image

"B" button for jump:
Image

Right shoulder button for run:
Image

Update 4:

Start button to show window/Back button to close window:
Image

Download:

http://www.megaupload.com/?d=XOCEF9PI

Update 5:

Image

The thumb stick behaves a little bit now (try holding down in one direction for a smooth spin). Tapping the thumb stick makes it rotate like crazy.

Anyway, I've added control mappings to the instruction and some debug information. I've made the DPAD change the window color. :)

Download:

http://www.megaupload.com/?d=7JHKDL0A

Update 6:

Image

Thumb sticks "crazy fast" movement has been fixed! Also added a skydome as a reference point for orientation purposes.

Download (you know, megaupload is going to start charging me for uploading so frequently):

http://www.megaupload.com/?d=OGHXGQ6P

Update 7:

Image

Now the mesh can move using the left thumb stick (disabled rotation of mesh though). Also added a terrain, bitplane's grass node with klasker's wind generator, and bitplane's cloud node to help with orientation.

Download:

http://www.megaupload.com/?d=EJNR8Q91
lug
 
Posts: 79
Joined: Tue May 02, 2006 5:15 am

Postby BlindSide » Thu Jan 04, 2007 6:40 pm

Wow this is amazing, great work!...now if only I had an XBOX 360... :lol:
BlindSide
Admin
 
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Postby MolokoTheMole » Tue Jan 09, 2007 1:27 pm

Wow this the it! I even have a controller to test it but I can't download it :(. Can you ulpoad it somewhere else (maybe http://www.mediafire.com/)?
Also is the source available?
MolokoTheMole
 
Posts: 104
Joined: Tue Jan 09, 2007 1:18 pm

Postby Zenix » Wed Jan 31, 2007 5:09 am

Wow this the it! I even have a controller to test it but I can't download it Sad. Can you ulpoad it somewhere else (maybe http://www.mediafire.com/)?
Also is the source available?


Can I second that?
Zenix
 
Posts: 1
Joined: Sat Nov 11, 2006 9:44 am
Location: New Zealand

Postby lug » Thu Feb 01, 2007 1:38 am

NO! :)

Actually, I was going to update the camera to make the movement smoother. Also, I ran into some serious clipping/collision issue with the dead easy camera.

So, I plan to switch over to another camera system before posting another release.

We'll see. I'm busy with irrGUIEditor at the moment (and two other projects not announced yet on this board -- incidently, they're taking up a huge chunk of time). :(

I get too many ideas after starting a new project. Then before I know it, I'm coding/designing like 15 different things. :)

Coding is an addiction for me. :)

Sorry for the late reply MolokoTheMole and Zenix. :cry:
lug
 
Posts: 79
Joined: Tue May 02, 2006 5:15 am

Postby Rambus » Thu Feb 01, 2007 6:21 am

lug - Project looks good,
if you need free and ad free, web hosting check out my offering. Two emails and you could be up and running...
http://www.g0dsoft.com/index.php?topic=17.0

P.S. Guess its time to buy that xbox pc controller!
Rambus
 
Posts: 96
Joined: Thu Nov 24, 2005 4:56 pm
Location: Canada

Postby lug » Fri Feb 02, 2007 3:12 am

Rambus wrote:lug - Project looks good,
if you need free and ad free, web hosting check out my offering. Two emails and you could be up and running...
http://www.g0dsoft.com/index.php?topic=17.0

P.S. Guess its time to buy that xbox pc controller!


Thanks, Rambus for the webspace offer. But I'm going to stick with atspace.com for now. If they don't work out, I'll give you a holler. :)
lug
 
Posts: 79
Joined: Tue May 02, 2006 5:15 am

Postby BlindSide » Fri Feb 02, 2007 4:45 am

Wow its another New Zealander I almost missed it. Howdy neighbour! :D
BlindSide
Admin
 
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Postby fullforce » Wed Feb 14, 2007 9:02 pm

That looks great!
Is it vista only?
fullforce
 
Posts: 55
Joined: Sat Jun 03, 2006 5:23 pm

Postby lug » Sat Feb 17, 2007 12:57 am

fullforce wrote:That looks great!
Is it vista only?


Thanks. No, it's not vista only. It was developed on Vista x64 machine. The program runs on Windows XP/x64 (haven't tried Windows 2000 so can't say one way or another).
lug
 
Posts: 79
Joined: Tue May 02, 2006 5:15 am

Postby Gianni » Fri Apr 11, 2008 5:03 pm

Uauuuu and for xbox 1 You can do this as well?
Gianni
 
Posts: 48
Joined: Sat Mar 22, 2008 9:24 am

Postby franklin » Wed Feb 18, 2009 11:31 am

lug wrote:NO! :)

Actually, I was going to update the camera to make the movement smoother. Also, I ran into some serious clipping/collision issue with viagra the dead easy camera.

So, I plan to switch over to another camera system before posting another release.

We'll see. I'm busy with irrGUIEditor at the moment (and two other projects not announced yet on this board -- incidently, they're taking up a huge chunk of time). :(

I get too many ideas after starting a new project. Then before I know it, I'm coding/designing like 15 different things. :)

Coding is an addiction for me. :)

Sorry for the late reply MolokoTheMole and Zenix. :cry:

Wow, lug! It's beautiful work! Can I use it with linux or solaris?
Last edited by franklin on Thu Apr 08, 2010 11:43 am, edited 1 time in total.
franklin
 
Posts: 1
Joined: Wed Feb 18, 2009 11:17 am

Postby devsh » Wed Feb 18, 2009 1:57 pm

Well done, I did the same kind of thing with my controller, but have the keys and axis left to map, so that will be a bit of work.

I have started with rumble thou....

can I call mine irrXboxControllerLinux???
We chose to stream mesh data from Multiple OpenGL Contexts in many threads and do the other things, not because they are easy, but because they are hard! - JFK
User avatar
devsh
Competition winner
 
Posts: 1740
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK


Return to Project Announcements

Who is online

Users browsing this forum: No registered users and 1 guest