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

Slides:



Advertisements
Similar presentations
F27SB2 Software Development 2 Lecture 1: Introduction.
Advertisements

DirectInput® 9.0 C. Shane Evans / Bernard George Program Manager DirectX Microsoft ® Corporation.
Tutorial 8: Developing an Excel Application
Tutorial 12: Enhancing Excel with Visual Basic for Applications
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
CS 275Tidwell Course NotesPage 128 Chapter 8: Builders And Editors Whether providing the user with an application to create and/or edit text, tables,
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Ch 7 & 8 Interaction Styles page 1 CS 368 Designing the Interaction Interaction Design The look and feel (appearance and behavior) of interaction objects.
Based on slides created by Edward Angel
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Other Interaction Styles: Direct Manipulation, Haptic, Multimedia, Multimodal, Virtual Reality, Video Games Dr.s Barnes and Leventhal.
Computer-Based Animation. ● To animate something – to bring it to life ● Animation covers all changes that have visual effects – Positon (motion dynamic)
DEMONSTRATION FOR SIGMA DATA ACQUISITION MODULES Tempatron Ltd Data Measurements Division Darwin Close Reading RG2 0TB UK T : +44 (0) F :
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Chapter 2: Understanding and conceptualizing interaction Question 1.
XP Chapter 4 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Collecting Data for Well-Designed Forms Chapter 4 “Making.
DOS Understanding what you can do. Operating System Traits An OS only works with one type of processor –X86 processors for us; Motorola for Mac –Must.
LabVIEW an Introduction
Lecture 2 Event driven programming Mobile and Handheld Applications1 Programming of Handheld and Mobile Devices Lecture 2: Event driven programming concepts.
Interactive Input Methods & Graphical User Input
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Chapter 8: Writing Graphical User Interfaces
CGMB214: Introduction to Computer Graphics
11.10 Human Computer Interface www. ICT-Teacher.com.
Introduction to Matlab & Data Analysis
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Developing the Game User Interface (UI) Lesson 5.
Josh Stephens Comp Characteristics Degrees of Freedom: particular, independent way that a body moves in space Input type/Frequency of data: Discrete:
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
Ray Bradley Karla N. Juárez David Wood Advisor: Dr. Stephen Murrell May 2 nd, 2005.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Computer Graphics I, Fall 2010 Input and Interaction.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
CSE3AGT Paul Taylor Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.
Haptic technology, or haptics, is a tactile feedback technology that takes advantage of our sense of touch by applying forces, vibrations, and/or motions.
Editors And Debugging Systems Other System Software Text Editors Interactive Debugging Systems UNIT 5 S.Sharmili Priyadarsini.
E.g.: MS-DOS interface. DIR C: /W /A:D will list all the directories in the root directory of drive C in wide list format. Disadvantage is that commands.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Object Oriented Programming.  Interface  Event Handling.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
The Challenge of Accessible Rich Media Presenters: Chris Newman Chris Frost.
University of New Mexico
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Computer Programming Modeling a Passive Solar Home.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
3D Geometric Transformation
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
Systems and User Interface Software. Types of Operating System  Single User  Multi User  Multi-tasking  Batch Processing  Interactive  Real Time.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
An operating system (OS) is a collection of system programs that together control the operation of a computer system.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Designing Effective Input. Design input forms for users of business systems Design engaging input displays for users of information systems Design useful.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
HAPTIC REALITY SYSTEMS
CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Unit 2 User Interface Design.
Game Programming (User Input)
Interactive Input Methods & Graphical User Input
Interactive Input Methods & Graphical User Input
Presentation transcript:

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

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

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

DirectInput ® 8 API

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

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

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

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 8 Example - Keyboard Creating DirectInput Object HINSTANCE g_hinst; HRESULT hr; LPDIRECTINPUT8 g_lpDI; // DirectInput8 Interface hr = DirectInput8Create( g_hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_lpDI, NULL); if FAILED(hr) { // DirectInput not available; take appropriate action }

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 9 Example - Keyboard Creating DirectInput Device HRESULT hr; LPDIRECTINPUTDEVICE8 g_lpDIDevice; // Device for Keyboard hr = g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL); // GUID_SysMouse // GUID of Joystick is need to enumerate if FAILED(hr) { DI_Term(); // Terminate DirectInput  Described later return FALSE; }

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 10 Example - Keyboard Setting Data Format hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard); // c_dfDIMouse, c_dfDIMouse2  Mouse // c_dfDIJoystick, c_dfDIJoystick2  Joystick things // These are predefined global variables if FAILED(hr) { DI_Term(); return FALSE; }

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

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 12 Example – Keyboard (Behavior Flags) DISCL_BACKGROUND The application requires background access. DISCL_EXCLUSIVE The application requires exclusive access. 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. DISCL_NONEXCLUSIVE The application requires nonexclusive access. 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 Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 13 Example - Keyboard Gaining Access to the Device // The application must acquire the device before retrieving data from it if (g_lpDIDevice) g_lpDIDevice->Acquire();

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

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

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 16 Example - Mouse Retrieve mouse data in immediate mode HRESULT ProcessData( HWND hDlg )// Immediate access { HRESULT hr; DIMOUSESTATE2 dims2; // DirectInput mouse state structure if( NULL == g_pMouse ) return S_OK; // Get the input's device state, and put the state in dims ZeroMemory( &dims2, sizeof(dims2) ); hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 ); if( FAILED(hr) ) { // If input is lost then acquire and keep trying hr = g_pMouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pMouse->Acquire(); return S_OK; }

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 17 Example - Mouse Retrieve mouse data and display in text _stprintf( strNewText, // Display retrieved data in text TEXT("(X=% 3.3d, Y=% 3.3d, Z=% 3.3d) B0=%c B1=%c B2=%c B3=%c B4=%c B5=%c B6=%c B7=%c"), dims2.lX, // X-Axis dims2.lY, // Y-Axis dims2.lZ,// Z-Axis (Wheel) (dims2.rgbButtons[0] & 0x80) ? '1' : '0',// Buttons.... (dims2.rgbButtons[1] & 0x80) ? '1' : '0', (dims2.rgbButtons[2] & 0x80) ? '1' : '0', (dims2.rgbButtons[3] & 0x80) ? '1' : '0', (dims2.rgbButtons[4] & 0x80) ? '1' : '0', (dims2.rgbButtons[5] & 0x80) ? '1' : '0', (dims2.rgbButtons[6] & 0x80) ? '1' : '0', (dims2.rgbButtons[7] & 0x80) ? '1' : '0'); return S_OK; }

Haptic Device

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

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 20 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: Constant force  A steady force in a single direction. Ramp force  A force that steadily increases or decreases in magnitude. Periodic effect  A force that pulsates according to a defined wave pattern. Condition  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. Basic Concepts of Force Feedback in DirectInput ®

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

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

CGVR Graphics Lab. / Korea Univ. cgvr.korea.ac.kr 23 Simple Demonstration Force Editor Provided by MicroSoft DirectX ®

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