• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language
    C
  • License
    ISC License
  • Created about 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An interface that interacts with an XBox One controller via the usb stream. With simple methods for object or camera control (i.e. for OpenGL contexts).

Linux Interface for an XBox One Controller

This is a linux interface, to integrate the Xbox-Controller directly into your favorite project. If you require different mappings or axes, please see the linux programs: jscal and jstest-gtk to change the mapping on the controller.

It is also recommended, to calibrate the controller before using it. This is also done with: jscal or jstest-gtk.

This library possibly works with other joystick devices but is only tested with the XBox controller.

Library Dependencies

Because some vector and quaternion based math is required to calculate the joystick movements, I provide the appropriate libraries needed to use Xbox-Controller here:

Quaternion library: https://github.com/MauriceGit/Quaternion_Library.

Vector library: https://github.com/MauriceGit/Vector_Library.

Just place the .c and .h files in the same directory and compile them with your project.

Functionality

The only interface and functions you should use, are the documented as function heads in the mtXboxController.h file. More documentation about these functions are found above the apropriate function bodies in mtXboxController.c.

Function Description
int mtInitJoyControl(char* name) This function MUST be called before any other. It initialises the usb stream connection.
int mtFinishJoyControl() This function should be called after any interaction with the Controller is finished.
void mtCalcJoyCameraMovement(double interval) This function should be called in very short intervals, to allow a very smooth joystick handling. The parameter is the time since the last call to this method.
MTVec3D mtGetJoyPosition() The current position is retreived (of the camera or object, controlled via the Controller).
MTVec3D mtGetJoyUp() The current up-vector is retreived (of the camera or object, controlled via the Controller).
MTVec3D mtGetJoyCenter() The current center point is retreived (of the camera or object, controlled via the Controller).

Calibration

There are two constants, to change the sensitivity of the joystick input. They are found in the mtXboxController.h and can be changed at will. Please ensure, that these values are of floating point.

Changes might be necessary depending on your application and size of your virtual environment.

Name Default Value Description
MT_XBOX_TRANS_NORMALISATION 500000.0 The smaller this value, the faster the translation will get. Affected are: Right stick, LT Axis and RT Axis (See: Controller Assignment).
MT_XBOX_TURN_NORMALISATION 2000.0 The smaller this value, the faster Pitch and Yaw will be. Left stick is affected (See: Controller Assignment).

The following constants will affect the axis and give them an offset (if value > 0). The offset could be used, to for example ignore the negative axis values.

Name Default Value Assignment
MT_AXIS_2_OFFSET 32768 LT Axis
MT_AXIS_3_OFFSET 0 Left stick
MT_AXIS_4_OFFSET 0 Right stick
MT_AXIS_5_OFFSET 32768 RT Axis

See also: Controller Assignment.

What about the Buttons?

You might have noticed that we ignored any buttons from your Controller and the mtXboxController does in fact not give you any interface for buttons. Reason for that is, that this controller interface acts as an abstraction level for the transformation of axis movements to 3D orientation calculation, that internally uses Quaternions.

Buttons don't need fancy calculations and abstractions around them. So if you like to implement actions for your Xbox Controller buttons, just include the mtJoystick.h and call the appropriate function directly (int getButtonValue(int buttonNumber, short * value)).

Usage

This library can be used to control a camera or object in a 3D environment.

The following example uses the Controller to move the camera in an OpenGL context.

// This is done right at the start of your program, before entering the main loop.
char* jsSource = "/dev/input/js0";
if (!mtInitJoyControl(jsSource)) {
    // Error. Initialisation failed.
}

...

// In GLUT or GLFW, there is a timer, allowing us to get the time interval between
// two frames. We need this interval, to update the camera position via the Controller
float interval = ...
mtCalcJoyMovement(interval);

...

// Later, we want to set our camera position and direction with gluLookAt().
// The result of our functions fit exactly into this scheme.
MTVec3D cam = mtGetJoyPosition();
MTVec3D center = mtGetJoyCenter();
MTVec3D up = mtGetJoyUp();
gluLookAt (cam.x,    cam.y,    cam.z,
           center.x, center.y, center.z,
           up.x,     up.y,     up.z);

...

// Don't forget, to nicely kill the controller ;)
mtFinishJoyControl();

Controller Assignment

All code is tested with the XBox One controller (see following image).

XBox Controller

The following axes are assigned:

Axis Assignment
LT Axis Increases the height of the object/camera along the Y axis.
RT Axis Decreases the height of the object/camera along the Y axis.
Left Stick Controls the Pitch and Yaw axis. (Front/Back: Pitch, Left/Right: Yaw).
Right Stick Moves the object/camera on the X/Z plane relative to the current position and orientation. Front/Back/Left/Right accordingly.

More Repositories

1

Delaunay_Triangulation

My own implementation of a Delaunay triangulation and Voronoi partition in Python applied to images.
Python
255
star
2

Partikel_accelleration_on_GPU

Particle accelleration with OpenGL 4.3, using the compute shader to calculate particle movement on graphics hardware.
C
253
star
3

skiplist

A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist
Go
252
star
4

compiler

Compiler for a small language into x86-64 Assembly
Go
243
star
5

Simple_GLSL_Shader_Example

A very simple example of how shaders in OpenGL can be used, to color Objects or map a texture on some triangles.
C
239
star
6

Voronoi_Image_Manipulation

A system independent tool for interactive image manipulation with Voronoi and Delaunay data structures.
Go
227
star
7

Water_Simulation

Water-Simulation with real time specular reflection on the waters surface. The reflection is implemented in GLSL and runs on the GPU and in screen space. The water itself is implemented using a pressure based approach for the surface calculation.
C
149
star
8

Cloth_Simulation

Cloth-Visualization via particle-simulation.
C
83
star
9

Advanced_Algorithms

Quick implementations of some advanced algorithms for searching, sorting and trees
Python
77
star
10

Screen_Space_Ambient_Occlusion

Giving a scene a depth-dependent shading, completely irregarding the scene complexity, in screen-space.
C
47
star
11

Quaternion_Library

A small library that capsulates most commonly used operations on Quaternions. Also a small sample implementation, that rotates an object around an axis, using Quaternions.
C
40
star
12

Energy-Dome_Terrain

A visually appealing terrain visualization from real-world data with some extras, such as an animated energy dome, LOD tessellation and multisampling
Go
29
star
13

advsearch

A Go library for advanced searching in sorted data structures
Go
22
star
14

Repeat_History

A small but useful command for a linux shell. It makes the bash history more easily accessible than cmd+r.
Shell
19
star
15

Marching_Cubes_on_GPU

A marching cube algorithm, that is executed in parallel on the GPU, using compute shaders. This will later enable a highly parallel creation of advanced landscape/terrain structures in potentially real-time (next project).
Go
9
star
16

tree23

An implementation of a balanced 2,3-tree that allows accessing next/previous elements in O(1) at all times.
Go
8
star
17

Vector_Library

Small vector library in C, containing all basic vector operations.
C
4
star
18

2D_Bin_Packing

several parallel solutions for a 2D bin packing problem for a programming contest.
Python
2
star
19

Variance_Shadow_Maps

Small example of a project, that uses variance shadow maps with hardware Multisampling.
Go
2
star
20

Voronoi_DivideAndConquer

A Go implementation of a voronoi tessellation with the divide and conquer algorithm. It is still work in progress and not yet working properly!
Go
2
star
21

mtVector

A short vector library with all necessary operations for a Delaunay triangulation, including optimized matrix multiplication
Go
1
star
22

game

JavaScript
1
star
23

Agar_Clone_Joystick_Client

A C++ client for our programming challenge (2016) supporting an X-BOX-Controller.
C++
1
star
24

FastDelaunayImages

Go
1
star
25

AdventOfCode

My solutions for the advent of code puzzles (AOC)
Python
1
star
26

Artificial_Neural_Network_Character_Classification

Implementation of an artificial neural network with backpropagation for classification of characters.
Python
1
star
27

Bachelor_Thesis_Arimaa

Implementation of the practical part of my bachelor thesis for the FH-Wedel. The thesis has been awarded with the "Wedeler Hochschulpreis" for innovation. The code implements an artificial intelligence which plays the game of Arimaa.
Java
1
star