Torque 3D Now Supports the Razer Hydra Controller
by Dave Wyand · 02/22/2013 (1:39 pm) · 15 comments

Torque 3D Now Supports the Razer Hydra Controller
Back on September 20, 2012, we launched the MIT licensed version of Torque 3D on GitHub. Next on December 19, 2012, we launched the first new release under open source, version 2.0. Then on January 10, 2013, the T3D Steering Committee announced the roadmap for version 3.0. Within this roadmap was improved support for various input devices to take advantage of current and future controllers that are entering the PC market.The first new input device was the Leap Motion with support added to the development branch as announced in my blog on January 24, 2013. Today we announce support for another input device, the Razer Hydra controller in Torque 3D’s development branch on GitHub.
The Razer Hydra Controller and Torque 3D
The Razer Hydra controller combines the standard buttons and thumb sticks of a gamepad with motion sensing technology by Sixense to determine the absolute position and rotation of each hand with respect to a base station. If you are not familiar with the Razer Hydra controller you should head over to their site where you may read more about it and watch some videos of the controller in action.
Through the Sixense SDK, Torque 3D is able to receive the gamepad and physical input and interpret it as input events that are sent to your game. Most of the game support you will come across for the Razer Hydra does not take full advantage of the controller’s capabilities. Most often the controller is used in an emulation mode to replace some mouse or thumb stick input. However, with Torque 3D, you will be able to take full advantage of the Razer Hydra controller’s unique capabilities.
The following types of input events are currently supported:
Standard Gamepad Input Events
These are all of the thumb stick, trigger and button input events you would expect from a Xbox 360 compatible gamepad controller. Each Razer Hydra handheld controller has a thumb stick, trigger, shoulder button, thumb stick button, start button, and four numbered buttons. Between the two handheld controllers, this is actually more controls than are available on a Xbox 360 controller.
Controller Absolute Position and Rotation Input Events
This is what makes the Razer Hydra unique. Each handheld controller reports its absolute position (in millimeters) and rotation with respect to the Hydra’s base unit. Torque 3D receives this information and passes it onto your application.

The backpack’s position above the cube, as well as its local rotation, are being controlled by the right hand Razer Hydra controller.
Because the position input events are all relative to the base station, you will often need to come up with a scheme to determine where the user’s neutral, or starting position is. You could assume that the base station is always front and center of the user at a required distance, but from my experience this is often not the case. For example, I usually have the base station sit to the left of my keyboard because of how my desk is arranged.
Controller as Thumb Stick Input Events
Based on the values returned by the Leap Sixense SDK, Torque 3D can interpret the rotation of a handheld controller as if it were a gamepad thumb stick. Imagine that a stick is coming out of the top of the handheld controller and as you tilt your hand, you are moving this stick. This also takes advantage of Torque 3D’s action mapping system including being able to define dead zones. This adds another level of control over your application without needing to worry about dealing with the absolute position and rotation values. You could, for example, move the player around in one of Torque 3D’s standard templates by using these events.
Whole Frame Input Events
With your application it is possible that the above input events don’t fit in with how you would like to use the Razer Hydra controller. In this case, Torque 3D provides a single input event each time it reads a frame from the Razer Hydra. This frame is presented as a special SimObject (the RazerHydraFrame class) with the frame’s properties accessible using TorqueScript methods. These frames are automatically stored on the RazerHydraFrameGroup SimGroup so a short history may be accessed at any time (and old frames are recycled to become new frames).
Razer Hydra Controller Wiki Page
All of this information and more in now available on the Razer Hydra Wiki Page on GitHub. This includes a more thorough description of these input events, how to best use them, as well as how to add Razer Hydra support to your own Torque 3D project.Razer Hydra and Torque 3D Demo Game: Hydra Ryder
To help demonstrate using the Razer Hydra controller and Torque 3D, I have created a small, example game called Hydra Ryder. In this game you dual wield Ryder pistols to fire at various targets on a gun range.
When you first start a game session you are asked to calibrate your Razer Hydra controllers. This is so Torque 3D knows where your shoulders are, and can therefore correctly calculate your arm and hand positions within the game. I tried a number of different schemes and found it best to just ask the player to hold their controllers up to their shoulders and press a trigger.

With the calibration complete, you are taken to the firing range and may use either or both pistols to try and hit the various targets. The demo makes use of the Bullet physics engine for some of the interactions.

Using the right Ryder pistol to fire on a target that is 5m away

With complete control over a Ryder pistol’s position and rotation, you may accurately use the pistol's iron sights to hit targets.

Each hit on the metal sheet provides a satisfying ping sound
The Hydra Ryder demo is available for anyone to try out, although you will need a Razer Hydra controller to take advantage of it. Download the demo here:
Just unzip the package and launch the executable. Be sure to have your Razer Hydra controller plugged into your machine before starting the demo game.
How It Works
The Hydra Ryder demo game makes use of the new ScriptTickObject class that is available in the development branch. This class was first introduced with the Marble Motion demo game for the Leap Motion as talked about here. In this case, the ScriptTickObject class is used to handle the game’s state machine from startup, to calibration, to when actually in the game.
To allow for complete control over the player’s hand position and rotation I created a new Player derived class called HydraPlayer. This new class serves a couple of purposes. The first is to work with the ExtendedMove class that is available in the development branch and was first discussed on my Leap Motion blog (although it was never actually used there). The ExtendedMove class allows us to process absolute position and rotation changes on both the client and server, and is processed in HydraPlayer::updateMove(). There I store the given position and rotation values as player wrist position and rotation.
The second purpose of the HydraPlayer class is to take a special skeleton model that includes shoulder and wrist nodes (along with an eye node and mount points) and manually take control of the wrist nodes to transform them to match the user’s movements. The Player class automatically adjusts a weapon’s targeting when in first person to fire where the player is looking, so I also needed to decouple this so that wherever the user points their hands is where the mounted pistol would fire.

A 3rd person view showing that a user may move the pistols completely to the side of the invisible player skeleton, and outside of the first person’s field of view.
I have also made the HydraPlayer class fully networkable, so you could, in theory, have multiple players using their Razer Hydra controllers to shoot at targets.
In order to match the user’s movements to that of the player’s skeleton I had to first take the user through a calibration stage. During calibration the user is indicating both the physical position of their shoulders relative to the Hydra base station, as well as the width of their shoulders. I then subtract this known starting position from all future position input events and use this new relative position to move the player skeleton’s wrist nodes with respect to the skeleton’s shoulder nodes. And knowing the user’s shoulder width allows me to scale the user’s movements to match the size of the player’s skeleton. I’ve successfully had my four year old shooting at targets using the Razer Hydra controllers and the pistols always remain within the expected view.
In order to provide you with access to my HydraPlayer class I have set up the Hydra Ryder demo with its own repository: Torque3D-HydraRyder. This only includes the Hydra Ryder project with its source, script and art files, but you could drop it into the My Projects directory of a standard Torque 3D repository clone and recompile it there. Be sure that you are building off of the development branch to gain access to the Razer Hydra input files.
Input Handling Changes in Torque 3D
In order to support the Razer Hydra controller a number of changes were required to how Torque 3D handles its input devices. Fortunately, all of this work was already done to support the Leap Motion. You may read about the various input device and event changes at the bottom of my Leap Motion blog.The Future
These are just the first steps at supporting the Razer Hydra controller. Any community input would be much appreciated.- Dave
About the author
Producer at GarageGames LLC
#3
I am a fanatic for peripherals of all kinds. Implementing fun input devices was my bread & butter at my first job, so I love seeing blogs like this and the one with Leap Motion. We've come a long way since the P5 Glove. Awesome work Dave and team.
02/22/2013 (3:15 pm)
Behold the power of open source T3D, led by Dave and the committee! \o/I am a fanatic for peripherals of all kinds. Implementing fun input devices was my bread & butter at my first job, so I love seeing blogs like this and the one with Leap Motion. We've come a long way since the P5 Glove. Awesome work Dave and team.
#4
@ Michael: The P5 glove remember me at old times. Long time ago I bought a glove to control my light show. I designed and coded a software, where I could control light scanners. That was a lot of fun, if you show with your hand and fingers to a point, and 12 light scanner follow your hand moving, and change color and such, if you use the finger poses.
I wish i could use Hydra and Torque at this old days.
02/23/2013 (4:56 am)
That's just awesome! @ Michael: The P5 glove remember me at old times. Long time ago I bought a glove to control my light show. I designed and coded a software, where I could control light scanners. That was a lot of fun, if you show with your hand and fingers to a point, and 12 light scanner follow your hand moving, and change color and such, if you use the finger poses.
I wish i could use Hydra and Torque at this old days.
#5
02/23/2013 (1:56 pm)
Have been thinking, a Razor Hydra and an Oculus Rift.. Now that would be immersive!
#6
02/23/2013 (5:48 pm)
I agree with David, can't wait till you guys add Rift support!
#7
@D Fasel:
Here is someone that is using the Hydra for an interactive display: www.spontaneousfantasia.com/project/hydra/ and vimeo.com/50235558. It would be great to see Torque 3D used outside of a traditional game environment.
@David:
I completely agree... :)
While waiting for your Rift to arrive, I would recommend reading John Carmack's article on latency mitigation: www.altdevblogaday.com/2013/02/22/latency-mitigation-strategies/. It is great to see that a couple of ideas I had for integrating the Rift with Torque 3D now have names.
- Dave
02/25/2013 (8:50 am)
Thanks everyone. Being an open source project has allowed us to be nimble to trends I noticed last summer. It is great to see these pieces come together.@D Fasel:
Here is someone that is using the Hydra for an interactive display: www.spontaneousfantasia.com/project/hydra/ and vimeo.com/50235558. It would be great to see Torque 3D used outside of a traditional game environment.
@David:
I completely agree... :)
While waiting for your Rift to arrive, I would recommend reading John Carmack's article on latency mitigation: www.altdevblogaday.com/2013/02/22/latency-mitigation-strategies/. It is great to see that a couple of ideas I had for integrating the Rift with Torque 3D now have names.
- Dave
#8
A couple of things I picked up on:
It ships with Portal 2 - you get a redeem code that allows a free downlaod of it.
The instructions you get with the device are pretty minimal - I recommend you pick up the "master guide" from the Razer site as it has additional information with it.
It's plug and play, but I found that the orientation of the weapons etc was better after I'd downloaded and installed latest drivers from the site.
Speaking of orientation - no matter how I hold the two Razer controllers during the calibration screen, the guns always seem to be off centre. Just forces you to make some tricky wrist movements to get a fix on the cans and targets etc.! To be fare, this could just be that I need to spend more time positioning and base station correctly etc.(Either that or I just can't shoot for love 'nor money!).
Overall - Great Demo!!! Impressed with it!
03/02/2013 (10:31 am)
I've been playing around with the Hydra controller and the above demo. It works realy well - surprisingly smooth movement.A couple of things I picked up on:
It ships with Portal 2 - you get a redeem code that allows a free downlaod of it.
The instructions you get with the device are pretty minimal - I recommend you pick up the "master guide" from the Razer site as it has additional information with it.
It's plug and play, but I found that the orientation of the weapons etc was better after I'd downloaded and installed latest drivers from the site.
Speaking of orientation - no matter how I hold the two Razer controllers during the calibration screen, the guns always seem to be off centre. Just forces you to make some tricky wrist movements to get a fix on the cans and targets etc.! To be fare, this could just be that I need to spend more time positioning and base station correctly etc.(Either that or I just can't shoot for love 'nor money!).
Overall - Great Demo!!! Impressed with it!
#9
03/04/2013 (12:26 pm)
Leap motion support would be nice as well.
#11
Thanks for trying out the demo. So far you are the only one to comment on the Razer Hydra support.
Where do you have your base station relative to where you hold your controllers? Maybe I can test things out at my end and make sure there isn't a calculation error somewhere.
- Dave
03/06/2013 (9:02 am)
@Richard:Thanks for trying out the demo. So far you are the only one to comment on the Razer Hydra support.
Where do you have your base station relative to where you hold your controllers? Maybe I can test things out at my end and make sure there isn't a calculation error somewhere.
- Dave
#12
I'm positioning the base station centrally i.e. directly below the screen and using the recommended distance set up which is 20-40 inches between the station and the controllers, so if I'm in a seated position, the station is approximately chest height in front of me.
In game, the shoulders and guns correlate quite well in terms of position (with virtually no lag at all), but the guns themselves always seem to want to point inwards towards the centre of the screen - while I'm holding the controllers in the straightened position if that makes sense.
I've tried holding the controllers at different angles during the calibration stage to see what affect it has. This does alter the starting orientation of the guns, but I find that one of them will always feel more natural than the other.
It's NOT a major thing at all - but the horizontal orientation between the guns and the controllers seems off slightly.
Either way - I'm currently working on a fish-eye lens for T3D which I want to use with a giant immersive dome projection system that we have - the hydra would be a great bonus peripheral!
Cheers!
03/06/2013 (10:11 am)
Hi Dave,I'm positioning the base station centrally i.e. directly below the screen and using the recommended distance set up which is 20-40 inches between the station and the controllers, so if I'm in a seated position, the station is approximately chest height in front of me.
In game, the shoulders and guns correlate quite well in terms of position (with virtually no lag at all), but the guns themselves always seem to want to point inwards towards the centre of the screen - while I'm holding the controllers in the straightened position if that makes sense.
I've tried holding the controllers at different angles during the calibration stage to see what affect it has. This does alter the starting orientation of the guns, but I find that one of them will always feel more natural than the other.
It's NOT a major thing at all - but the horizontal orientation between the guns and the controllers seems off slightly.
Either way - I'm currently working on a fish-eye lens for T3D which I want to use with a giant immersive dome projection system that we have - the hydra would be a great bonus peripheral!
Cheers!
#13
Could I ask how easy it is to mix both the Rift and Hydra in one demo?
Please see this thread:
www.garagegames.com/community/forums/viewthread/134390
Cheers,
Hewster
06/20/2013 (4:46 pm)
Hi David, have tried this out and its great :DCould I ask how easy it is to mix both the Rift and Hydra in one demo?
Please see this thread:
www.garagegames.com/community/forums/viewthread/134390
Cheers,
Hewster
#14
These is a couple of issues... see link in my last post ^^^^
06/29/2013 (10:10 am)
I've done it :)These is a couple of issues... see link in my last post ^^^^
#15
09/23/2013 (8:30 pm)
Just add one more device to the mix, the Virtuix Omni (http://www.virtuix.com/) and there's a Pacific Rim robot fighting game waiting to happen... 
Torque Owner David Robert Pemberton
www.deadlyassets.com