Using an Xbox 360 Controller to Navigate the Quick Render

Started by LeeReynolds, June 01, 2008, 04:18:27 PM

Previous topic - Next topic

LeeReynolds

    I wrote this script to help navigate the quick render feature in Terragen 2. I use a touchpad with my lappy, which makes the navigation system a little awkward (Alt-Click and Shift-Alt-Click), and I don't even have a middle mouse button! So, I thought this was a great opportunity to incorporate a nifty little script I picked up. I've got a wired Xbox 360 controller that I've been using as a mouse via an Autohotkey script. I'm hoping to set a trend. I think that having your most commonly used functions mapped on to such an ergonomic device as an Xbox controller is much better and more efficient than using a keyboard mouse combination in many situations.
    Most of the code comes from a sample on the autohotkey web site, designed for use with any joystick, but I've tweaked it a bit to take advantage of the button layout on the controller. It also holds down the Alt key when holding down any of the "mouse" buttons (A: Left, B:Right, and Left analog click: Middle) so that flying around the quick render is very easy. I would much rather Terragen 2's quick render navigate more like a first person shooter or flight simulation, but this will do for now.
    I'm a huge advocate for Autohotkey. For those who don't know, Autohotkey is a completely free tool used for writing scripts and hotkeys. Its really easy to use for simple things, but it is also incredibly robust, I have used it at work on many occasions. Sometimes its easier to write an autohotkey script than an all-out program. As a programmer with many large projects in multiple languages, its nice to create all of my small "one-offs" in such a well written language as AHK, but i've also used it to perform large and complex tasks, and nice looking GUI's The recorder doesn't hurt either for quick macros. </SHAMELESS PLUG>
    I have included both an AHK file and a compiled version. The compiled version should run on any Windows based machine (haven't tried it on Vista yet though), Please take a look at the code in the AHK and leave some comments/suggestions. I'm sure that there is a lot more i could do to make this more useful. The original script can be found in the documentation for autohotkey or at http://www.autohotkey.com/docs/scripts/JoystickMouse.htm

  -Lee Reynolds



Keymap:
Left analog        -  Move Mouse
Left analog click  -  Zoom*
Left Bumper        -  Backspace
Right Bumper      - Delete
Left Trigger        - Page Up
Right Trigger      - Page Down
POV                 - Up, Down, Left, Right
A                    - Orbit*
B                    - Translate*
X                    - Copy
Y                    - Paste

* denotes specific to TG2

 

jo

Hi Lee,

It's cool that you've done this, being able to support gamepads and such is something I've wanted to do since the TG v0.9 3D Preview but never had a chance to. I thought I would mention a couple of things though. First off, there are different presets available for different numbers of mouse buttons. See the Mouse Settings preference panel documentation. In TP3 you can now use a navigation panel to navigate the 3D Previews, which some people may find easier than using current mouse interaction, I know I do :-). The system behind the navigation panel also lends itself to being controlled by keys in the manner of a first person shooter ( or in fact the TG v0.9 3D Preview ) and that's something I'd like to do if I can find time before the final release.

All that's not to be negative about what you've done, if I had an Xbox 360 controller I'd be giving it a whirl :-).

Regards,

Jo


Blonderator

Would this script work on a universal controller (one that is nearly identical to an Xbox controller) or would using one require re-mapping of all the keys in the script?

LeeReynolds

This script "should" work on any Windows compatable joystick or gamepad. The number and location of the buttons may require some modifications to the script to make it most efficient. The script isn't too hard to change, I tried to be a good programmer and comment things that I changed, but the AHK language is so simple that its pretty much self-documenting-- kinda like VB (I've always thought that using VB was like programming with cheat codes on... no thinking required). If anybody can figure out a way to make it even better by replacing the "click and drag" style navigation with something a little smoother (like a flight sim) to use in a script like this (or even some kind of API progam) that would be awesome! I'm actually working on a VB app to do just that, but I think that it will end up in my projects folder unfinished for all eternity like so many other good ideas.