Multi touch Interface Class - GavWood/DOGE-Game-Engine GitHub Wiki

The game engine supports multi-touch interactions through an interface class called ShTouch. ShTouch enables the game designer to experiment with multi-touch across Windows PC and mobile devices.

Multi-touch interactions include gestures like pinch zoom or rotate, scale and transform or even scenarios where different users control a mouse.

The following is an example code snippet that calculates the average position of all touches.

#include "BtBase.h"
#include "BtTypes.h"
#include "MtVector2.h"
#include "ShTouch.h"

MtVector2 v2SummedPositions( 0, 0 );
BtU32 count = 0;

for( BtU32 i=0; i<MaxTouches; i++ )
{
   if( ShTouch::IsHeld( i ) == BtTrue )
   {
      count++;
      v2SummedPositions += ShTouch::GetPosition(i);
   }
}
MtVector2 v2AveragePosition = v2SummedPositions / count;

The ShTouch class is designed to allow the same paradigm to be used when programming touch on a mobile device and responding to mouse presses on a desktop machine.

Since we cannot detect the location of a touch on a mobile device when the screen is not pressed - using the position of the touch on a mobile device will always return where the screen was touched, whereas on Windows it will return the current position of the mouse pointer.

To deal with multiple mouse buttons without introducing a separate mouse class, the first mouse button returns a touch at index zero, and the second mouse button returns a touch at index one.


The game engine uses a library called Many Mouse to provide support for more multi-touch on a Windows PC. Many Mouse was written by Ryan C. Gordon and others, and you can read about it here https://icculus.org/manymouse