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.
These are just the first steps at supporting the Razer Hydra controller. Any community input would be much appreciated.