Haptic Direct User Input with Direct Input 8

  • Slides: 24
Download presentation
Haptic & Direct User Input with ® Direct. Input 8 Graphics Lab. Korea Univ.

Haptic & Direct User Input with ® Direct. Input 8 Graphics Lab. Korea Univ. API

Contents CGVR n n n n User Input & Virtual World Direct. Input® 8

Contents CGVR n n n n User Input & Virtual World Direct. Input® 8 API Basic Steps of Direct. Input® Programming Examples Using Haptic Device Basic Concepts of Force Feedback in Direct. Input® Demonstration cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 2

User Input & Virtual World CGVR n Interaction Styles and Metaphors n 3 D

User Input & Virtual World CGVR n Interaction Styles and Metaphors n 3 D “real world” metaphor as opposed to a 2 D “paper” metaphor Be easy and intuitive to explore virtual world n Communicate with Virtual World fast and with less delay n Typical forms of input devices in PC n n Keyboard, Mouse, Joystick, Trackball etc. cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 3

® Direct. Input 8 API

® Direct. Input 8 API

Direct. Input® API CGVR n Faster access to input data by communicating directly with

Direct. Input® API CGVR n Faster access to input data by communicating directly with the hardware drivers rather than relying on Microsoft Windows® messages. n Support with any type of input devices as well as force feedback n Each Direct. Input. Device object in turn has device objects, which are individual controls or switches such as keys, buttons, or axes cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 5

Direct. Input® API CGVR Direct. Input does not provide any advantages for applications that

Direct. Input® API CGVR Direct. Input does not provide any advantages for applications that use the keyboard for text entry or the mouse for navigation with mouse cursor n Buffered data vs. Immediate data n Buffered data - A record of events that are stored until an application retrieves them n Immediate data - A snapshot of the current state of a device n cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 6

Basic Steps of Direct. Input® Programming n n n n CGVR Creating Direct. Input

Basic Steps of Direct. Input® Programming n n n n CGVR Creating Direct. Input Object Creating the Direct. Input Device Setting Data Format Setting Device Behavior Gaining Access to the Device Retrieving Data from the Device Closing Down the Direct. Input System cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 7

Example - Keyboard CGVR n Creating Direct. Input Object HINSTANCE HRESULT LPDIRECTINPUT 8 g_hinst;

Example - Keyboard CGVR n Creating Direct. Input Object HINSTANCE HRESULT LPDIRECTINPUT 8 g_hinst; hr; g_lp. DI; // Direct. Input 8 Interface hr = Direct. Input 8 Create( g_hinst, DIRECTINPUT_VERSION, IID_IDirect. Input 8, (void**)&g_lp. DI, NULL); if FAILED(hr) { // Direct. Input not available; take appropriate action } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 8

Example - Keyboard CGVR n Creating Direct. Input Device HRESULT hr; LPDIRECTINPUTDEVICE 8 g_lp.

Example - Keyboard CGVR n Creating Direct. Input Device HRESULT hr; LPDIRECTINPUTDEVICE 8 g_lp. DIDevice; // Device for Keyboard hr = g_lp. DI->Create. Device(GUID_Sys. Keyboard, &g_lp. DIDevice, NULL); // GUID_Sys. Mouse // GUID of Joystick is need to enumerate if FAILED(hr) { DI_Term(); return FALSE; } cgvr. korea. ac. kr // Terminate Direct. Input Described later Graphics Lab. / Korea Univ. 9

Example - Keyboard CGVR n Setting Data Format hr = g_lp. DIDevice->Set. Data. Format(&c_df.

Example - Keyboard CGVR n Setting Data Format hr = g_lp. DIDevice->Set. Data. Format(&c_df. DIKeyboard); // c_df. DIMouse , c_df. DIMouse 2 Mouse // c_df. DIJoystick , c_df. DIJoystick 2 Joystick things // These are predefined global variables if FAILED(hr) { DI_Term(); return FALSE; } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 10

Example - Keyboard CGVR n Setting Device Behavior // Set the cooperative level hr

Example - Keyboard CGVR n Setting Device Behavior // Set the cooperative level hr = g_lp. DIDevice->Set. Cooperative. Level(g_hwnd, // Window handle DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); // Set foreground access and non-exclusive mode if FAILED(hr) { DI_Term(); return FALSE; } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 11

Example – Keyboard (Behavior Flags) n CGVR DISCL_BACKGROUND The application requires background access. n

Example – Keyboard (Behavior Flags) n CGVR DISCL_BACKGROUND The application requires background access. n DISCL_EXCLUSIVE The application requires exclusive access. n DISCL_FOREGROUND The application requires foreground access. If foreground access is granted, the device is automatically unacquired when the associated window moves to the background. n DISCL_NONEXCLUSIVE The application requires nonexclusive access. n DISCL_NOWINKEY Disable the Windows logo key. Applications must specify either DISCL_FOREGROUND or DISCL_BACKGROUND; it is an error to specify both or neither. Similarly, applications must specify either DISCL_EXCLUSIVE or DISCL_NONEXCLUSIVE cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 12

Example - Keyboard CGVR n Gaining Access to the Device // The application must

Example - Keyboard CGVR n Gaining Access to the Device // The application must acquire the device before retrieving data from it if (g_lp. DIDevice) g_lp. DIDevice->Acquire(); cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 13

Example - Keyboard CGVR n Retrieving data from Keyboard void Process. KBInput() { char

Example - Keyboard CGVR n Retrieving data from Keyboard void Process. KBInput() { char buffer[256]; HRESULT hr; // Create custom function that will be called in the loop continuously hr = g_lp. DIDevice->Get. Device. State(sizeof(buffer), (LPVOID)&buffer); if FAILED(hr) { // If it failed, the device has probably been lost. Try to acquire again. hr = g_lp. DIDevice ->Acquire(); while( hr == DIERR_INPUTLOST ) // Try until acquired hr = g_lp. DIDevice ->Acquire(); return; } // use immediate data // If an element's high bit is 1, the key was down, if not, the key was down if (buffer[DIK_RIGHT] & 0 x 80) { // Right arrow key pressed else if(buffer[DIK_LEFT] & 0 x 80) { // Left arrow key pressed if (buffer[DIK_UP] & 0 x 80) { // Up arrow key pressed else if (buffer[DIK_DOWN] & 0 x 80) { // Down arrow key pressed } } } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 14

Example - Keyboard CGVR n Closing down the Direct. Input System void DI_Term() //

Example - Keyboard CGVR n Closing down the Direct. Input System void DI_Term() // Terminate Direct. Input { if (g_lp. DI) { if (g_lp. DIDevice) { // Always unacquire device before Release g_lp. DIDevice->Unacquire(); g_lp. DIDevice->Release(); g_lp. DIDevice = NULL; } g_lp. DI->Release(); g_lp. DI = NULL; } } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 15

Example - Mouse CGVR n Retrieve mouse data in immediate mode HRESULT Process. Data(

Example - Mouse CGVR n Retrieve mouse data in immediate mode HRESULT Process. Data( HWND h. Dlg ) { HRESULT hr; DIMOUSESTATE 2 dims 2; // Immediate access // Direct. Input mouse state structure if( NULL == g_p. Mouse ) return S_OK; // Get the input's device state, and put the state in dims Zero. Memory( &dims 2, sizeof(dims 2) ); hr = g_p. Mouse->Get. Device. State( sizeof(DIMOUSESTATE 2), &dims 2 ); if( FAILED(hr) ) { // If input is lost then acquire and keep trying hr = g_p. Mouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_p. Mouse->Acquire(); return S_OK; } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 16

Example - Mouse CGVR n Retrieve mouse data and display in text _stprintf( str.

Example - Mouse CGVR n Retrieve mouse data and display in text _stprintf( str. New. Text, // Display retrieved data in text TEXT("(X=% 3. 3 d, Y=% 3. 3 d, Z=% 3. 3 d) B 0=%c B 1=%c B 2=%c B 3=%c B 4=%c B 5=%c B 6=%c B 7=%c"), dims 2. l. X, // X-Axis dims 2. l. Y, // Y-Axis dims 2. l. Z, // Z-Axis (Wheel) (dims 2. rgb. Buttons[0] & 0 x 80) ? '1' : '0', // Buttons. . (dims 2. rgb. Buttons[1] & 0 x 80) ? '1' : '0', (dims 2. rgb. Buttons[2] & 0 x 80) ? '1' : '0', (dims 2. rgb. Buttons[3] & 0 x 80) ? '1' : '0', (dims 2. rgb. Buttons[4] & 0 x 80) ? '1' : '0', (dims 2. rgb. Buttons[5] & 0 x 80) ? '1' : '0', (dims 2. rgb. Buttons[6] & 0 x 80) ? '1' : '0', (dims 2. rgb. Buttons[7] & 0 x 80) ? '1' : '0'); return S_OK; } cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 17

Haptic Device

Haptic Device

Using Haptic Device CGVR n What is haptic interaction? n n n A haptic

Using Haptic Device CGVR n What is haptic interaction? n n n A haptic interface is a force reflecting device which allows a user to touch, feel, manipulate, create and/or alter simulated 3 D objects in a virtual environment Haptic n Of or relating to the sense of touch; tactile n Greek haptikos, from haptesthai, to grasp, touch Haptics n touch, tactile, force-feedback, texture, heat, vibration cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 19

Basic Concepts of Force Feedback in Direct. Input® n CGVR A particular instance of

Basic Concepts of Force Feedback in Direct. Input® n CGVR A particular instance of force feedback is called an effect, and the push or resistance is called the force. Most effects fall into one of the following categories: n Constant force o n Ramp force o n A force that steadily increases or decreases in magnitude. Periodic effect o n A steady force in a single direction. A force that pulsates according to a defined wave pattern. Condition o cgvr. korea. ac. kr A reaction to motion or position along an axis. Two examples are a friction effect that generates resistance to movement of the joystick, and a spring effect that pushes the stick back toward a certain position after it has been moved from that position. Graphics Lab. / Korea Univ. 20

Components of a Force CGVR n Magnitude n n Direction n n Duration of

Components of a Force CGVR n Magnitude n n Direction n n Duration of one cycle, also measured in microseconds Envelope n n Measured in microseconds Period n n Direction of Force Duration n n Magnitude of Force : -10, 000 to 10, 000 Defines an attack value and a fade value, which modify the beginning and ending magnitude of the effect Sustain level n Defined by the basic magnitude of the force to which the envelope is being applied cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 21

Graphical Representation of Ramp Force with Envelope CGVR Periodic Force Resultant Force Envelope cgvr.

Graphical Representation of Ramp Force with Envelope CGVR Periodic Force Resultant Force Envelope cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 22

Simple Demonstration CGVR Force Editor Provided by Micro. Soft Direct. X® cgvr. korea. ac.

Simple Demonstration CGVR Force Editor Provided by Micro. Soft Direct. X® cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 23

Simple Demonstration CGVR • Force Added • Loading Effect File • Gatling • Crash

Simple Demonstration CGVR • Force Added • Loading Effect File • Gatling • Crash • Engine Vibration cgvr. korea. ac. kr Graphics Lab. / Korea Univ. 24