User Tools

Site Tools


c_scene_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c_scene_tutorial [2017/05/04 19:16]
curtisb created
c_scene_tutorial [2019/01/21 16:34]
Line 1: Line 1:
-====== GestureWorks Scene Tutorial ====== 
- 
-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:​** 
-<​code>​ 
-static GestureWorks *gesture_works = nullptr; 
-</​code>​ 
-This will hold the instance of GestureWorks for this scene. ​ 
- 
-**3 - Initialize GestureWorks.** Here we do a basic initialization of GestureWorks:​ 
-<​code>​ 
-gesture_works = initializeGestureWorks(width,​ height); 
-</​code>​ 
-**4 - Register a touch object for GestureWorks.** In a larger application there could be many different touch objects registered. 
- 
-<​code>​ 
-registerTouchObject(gesture_works,​ s_test_object_name);​ 
-</​code>​ 
- 
-**5 - Register additional gestures for the touch object.** Here we are adding drag, rotate, scale to a touch object: 
-  
-<​code>​ 
-addGesture(gesture_works,​ s_test_object_name,​ "​ndrag"​);​ 
-addGesture(gesture_works,​ s_test_object_name,​ "​nrotate"​);​ 
-addGesture(gesture_works,​ s_test_object_name,​ "​nscale"​);​ 
-</​code>​ 
- 
-**6 - Similar to the screen tutorial, touch information is passed to GestureWorks:​** 
-<​code>​ 
-        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; 
- } 
-</​code>​ 
- 
-**7 - Read touch points.** Here we take the current points GW is processing and if we had more than one touch object we would decide, usually through some collision detection hit test, which object this point is associated with and on addTouchPointToObject pass in the correct object id. 
-<​code>​ 
- PointInfo *points; 
- const int point_count = getPointEvents(gesture_works,​ &​points);​ 
- 
- for (int i = 0; i != point_count;​ ++i) 
- { 
- PointInfo point = points[i]; 
- 
- switch (point.status) 
- { 
- case GW_TOUCHADDED:​ 
- addTouchPointToObject(gesture_works,​ s_test_object_name,​ point.point_id);​ 
- break; 
- 
- case GW_TOUCHUPDATE:​ 
- break; 
- 
- case GW_TOUCHREMOVED:​ 
- break; 
- } 
- } 
-</​code>​ 
- 
-**8 - Update the frame for GestureWorks** ​ 
-<​code>​ 
-updateFrame(gesture_works);​ 
-</​code>​ 
-**9 - Read gestures, each gesture will be associated with a specific touch object** 
-<​code>​ 
- 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];​ 
- 
- std::cout << "​Reading Gesture for Touch object " << event.target << std::endl; 
- 
- 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;​ 
- } 
- } 
-</​code>​ 
  
c_scene_tutorial.txt · Last modified: 2019/01/21 16:34 (external edit)