User Tools

Site Tools


c_screen_tutorial

This is an old revision of the document!


Screen Tutorial

GestureWorks can be setup to run in two different modes. Screen mode is the simplest, in this mode touch points from the screen are sent to GestureWorks and gestures are sent back. There is no association with a specific gesture and a specific object. For example if you wanted a fullscreen pan or rotation this mode sets it up easily.

Full code for this sample is at GestureWorks\C++\gestureworks-demo-screen\

1 - Include the header “GestureWorks2.h” and link to the appropriate C++ dll library. GestureWorks is built with Visual Studio and includes 32 and 64 bit dlls for debug and release.

2 - Declare a variable to hold GestureWorks:

static GestureWorks *gesture_works = nullptr;

This will hold the instance of GestureWorks for this scene.

3 - Initialize GestureWorks by passing the current width and height of the Window to GestureWorks.

gesture_works = initializeGestureWorksScreenGestures(width, height);

4 - Pass touch input from the application to GestureWorks. In this example the touch data is taken directly from WndProc and passed to GestureWorks:

static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_POINTERDOWN:
	{
		POINTER_INFO pi;
		GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pi);

		addEvent(gesture_works, pi.pointerId, GW_TOUCHADDED, (float)pi.ptPixelLocation.x, (float)pi.ptPixelLocation.y);

		break;
	}
	case WM_POINTERUP:
	{
		POINTER_INFO pi;
		GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pi);

		addEvent(gesture_works, pi.pointerId, GW_TOUCHREMOVED, (float)pi.ptPixelLocation.x, (float)pi.ptPixelLocation.y);

		break;
	}
	case WM_POINTERUPDATE:
	{
		POINTER_INFO pi;
		GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pi);

		addEvent(gesture_works, pi.pointerId, GW_TOUCHUPDATE, (float)pi.ptPixelLocation.x, (float)pi.ptPixelLocation.y);

		break;
	}

5 - Next we call to update the GestureWorks screen one per frame:

updateScreenFrame(gesture_works);

6 - Then the gestures from GestureWorks are read and their values are applied to our object:

	GestureInfo *gesture_info;

	const int gesture_count = getGestureEvents(gesture_works, &gesture_info);
	for (int i = 0; i != gesture_count; ++i)
	{
		GestureInfo event = gesture_info[i];

		if (strcmp("drag", event.gesture_type) == 0)
		{
			s_image_x += event.getValue("drag_dx") * s_window_width;
			s_image_y += event.getValue("drag_dy") * s_window_height;
		}
		else if (strcmp("rotate", event.gesture_type) == 0)
		{
			s_image_rotation += event.getValue("rotate_dtheta");
		}
		else if (strcmp("scale", event.gesture_type) == 0)
		{
			s_image_scale += event.getValue("scale_dsx") * s_window_width;
		}
	}

7 - Destroy GestureWorks as the application closes. This is done in wndProc

	case WM_DESTROY:
		destroyGestureWorks(gesture_works);

The final code is at GestureWorks2\Samples\C++\gestureworks-demo-screen\src\main.cpp

c_screen_tutorial.1493925179.txt.gz · Last modified: 2019/01/21 16:35 (external edit)