The Input Interface of the Engine - PowerPoint PPT Presentation

1 / 61
About This Presentation
Title:

The Input Interface of the Engine

Description:

Good Old Interface Design(Landon) Interface Definition for an Input Class(??) ... Getting Down to the Keys(Landon) The Pied Piper of Redmond(Stephen) ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 62
Provided by: gameCsie
Category:

less

Transcript and Presenter's Notes

Title: The Input Interface of the Engine


1
The Input Interface of the Engine
  • Speaker 5JJ, Landon,
  • ??, ??,
  • Stephen,
  • Akira, Roy

2
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

3
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

4
Lead in
  • Speaker5JJ

5
Lead in
  • As Einstein said, we really should be ashamed if
    we are just going to use a technical miracle
    without understanding it at all
  • we are the ones developing this tool, so we
    should indeed understand the inner workings of
    the tool
  • This chapter introduces you to DirectInput and
    explains how to encapsulate it to abstract the
    ZFXEngines input device away from DirectX.

6
  • This chapter covers the following topics
  • Initializing DirectInput
  • Implementing a DLL to encapsulate input issues
  • Querying the keyboard, mouse, and joystick for
    input
  • Adding a new component to the ZFXEngine

7
QA
8
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

9
Good Old Interface Design
9
  • Speaker Landon

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
10
Good Old Interface Design
  • In this chapter, we will add another component to
    the ZFXEngine.
  • the static library is called ZFXInput,
  • the DLL is called ZFXDI, where DI stands for
    DirectInput.

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
10
11
Files used for ZFXInput
  • ZFXInput.h and ZFXInput.cpp
  • ZFXInputDevice.h
  • ZFX.h
  • ZFX3D.h

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
11
12
Files used for ZFXDI
  • ZFXDI.def, ZFXDI.h, and ZFXDI.cpp
  • ZFXKeyboard.cpp
  • ZFXMouse.cpp
  • ZFXJoystick.cpp

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
12
13
QA
14
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

15
Interface Definition for an Input Class
  • Speaker ??

16
(No Transcript)
17
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
17
18
GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
18
19
(No Transcript)
20
(No Transcript)
21
QA
22
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

23
Base Class for Input Devices
  • Speaker ?? (Frozenmouse)

24
Overview
  • The Class ZFXDIDevice
  • Creating and Destroying an Input Device
  • Making It Run
  • Querying the Input
  • Q A

25
The Class ZFXDIDevice
  • The base class of any concrete input devices
  • See ZFXDI.h, lines 65 93

26
Creating and Destroying an Input Device
  • void ZFXDIDeviceCreate( LPDIRECTINPUT8, HWND,
    FILE)
  • ZFXDI.cpp, lines 340 345
  • No more than memberwise initialization
  • Called by the subclasses constructors
  • Why not use the constructor to do this job?
  • void ZFXDIDeviceRelease()
  • ZFXDI.cpp, lines 352 259
  • Release the devices

27
Making It Run
  • HRESULT ZFXDIDeviceCrankUp( REFGUID,
    LPCDIDATAFORMAT)
  • ZFXDI.cpp, lines 366 395
  • 3 steps
  • IDirectInput8CreateDevice
  • IDirectInputDevice8SetDataFormat
  • IDirectInputDevice8SetCooperativeLevel

28
Querying the Input
  • HRESULT ZFXDIDeviceGetData( ZFXINPUTDEV,
    void, DWORD)
  • ZFXDI.cpp, lines 405 449
  • Related functions
  • IDirectInputDevice8GetDeviceData
  • For mouse
  • IDirectInputDevice8GetDeviceState
  • For keyboard / joystick
  • IDirectInputDevice8Acquire
  • While the device is lost or not acquired

29
Q A
30
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

31
Getting Down to the Keys
31
  • Speaker Landon

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
32
class ZFXKeyboard public ZFXDIDevice
  • public
  • ZFXKeyboard(LPDIRECTINPUT8, HWND, FILE)
  • virtual ZFXKeyboard(void)
  • HRESULT Init(void)
  • HRESULT Update(void)
  • bool IsPressed(UINT nID)
  • bool IsReleased(UINT nID)
  • private
  • char m_Keys256
  • char m_KeysOld256
  • // class

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
32
33
Constructor and Destructor
  • ZFXKeyboardZFXKeyboard(LPDIRECTINPUT8 pDI, HWND
    hWnd, FILE pLog)
  • Create(pDI, hWnd, pLog)
  • ZFXKeyboardZFXKeyboard(void) Release()

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
33
34
HRESULT ZFXKeyboardInit(void)
  • if (FAILED(CrankUp(GUID_SysKeyboard,
    c_dfDIKeyboard)))
  • return ZFX_FAIL
  • // clear memory
  • memset(m_Keys, 0, sizeof(m_Keys))
  • memset(m_KeysOld, 0, sizeof(m_KeysOld))
  • // acquire the device
  • m_pDevice-gtAcquire()
  • return ZFX_OK
  • // Init

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
34
35
HRESULT ZFXKeyboardUpdate(void)
  • memcpy(m_KeysOld, m_Keys, sizeof(m_Keys))
  • // query status
  • if (FAILED(GetData(IDV_KEYBOARD, m_Keys0,
    NULL)))
  • return ZFX_FAIL
  • return ZFX_OK
  • // Update

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
35
36
Scan Codes
  • The DirectInput header dinput.h from the DirectX
    SDK defines several hexadecimal values that are
    the scan codes used in Windows to check for the
    keys.
  • --EX--
  • define ZVK_ESCAPE 0x01
  • define ZVK_TAB 0x0F
  • define ZVK_SPACE 0x39
  • define ZVK_RETURN 0x1C

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
36
37
IsPressed IsReleased
  • bool ZFXKeyboardIsPressed(UINT nID)
  • if (m_KeysnID 0x80)
  • return true
  • return false
  • // IsPressed
  • bool ZFXKeyboardIsReleased(UINT nID)
  • if ( (m_KeysOldnID0x80) !(m_KeysnID0x80)
    )
  • return true
  • return false
  • // IsPressed

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
37
38
QA
39
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

40
No Joy Without a Joystick
  • Speaker Chen, Chang-Min

41
No Joy Without a Joystick
  • ZFXJoystick Class
  • Initializing and Releasing
  • Updating

42
ZFXJoystick Class
  • Enumerate all attached devices
  • EnumJoyCallback()

43
ZFXJoystick Class (cont.)
44
Initializing and Releasing
  • Construction and Release

void ZFXDIDeviceCreate(LPDIRECTINPUT8 pDI, HWND
hWnd, FILE pLog) m_pLog pLog
m_hWnd hWnd m_pDI pDI
m_pDevice NULL
void ZFXDIDeviceRelease(void) if
(m_pDevice) m_pDevice-gtUnacquire()
m_pDevice-gtRelease() m_pDevice NULL
Log("input device offline (ok)") //
Release
45
Initializing and Releasing (cont.)
  • DirectInput enumeration function
  • IDirectInput8EnumDevices
  • Get a list of all attached joysticks

46
Initializing and Releasing (cont.)
47
Initializing and Releasing (cont.)
48
Initializing and Releasing (cont.)
49
Updating
  • Get the data from the hardware device
  • IDirectInputDevice8Poll
  • retrieves data from polled objects on a
    DirectInput device
  • IDirectInputDevice8Acquire
  • obtains access to the input device
  • IDirectInputDevice8GetDeviceData
  • retrieves buffered data from the device

GetData()
50
Updating (cont.)
51
Updating (cont.)
52
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

53
Implementing the Interface
  • Speaker Roy

54
Implementing the Interface
  • ZFXDI.h
  • ZFXDI.cpp

55
QA
56
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

57
Demo Application
57
  • Speaker ??

GAME.Lab/CSIE/NDHU
The Input Interface of the Engine
58
QA
59
Agenda
  • Lead in(5JJ)
  • Good Old Interface Design(Landon)
  • Interface Definition for an Input Class(??)
  • Base Class for Input Devices(??)
  • Getting Down to the Keys(Landon)
  • The Pied Piper of Redmond(Stephen)
  • No Joy Without a Joystick(Akira)
  • Implementing the Interface(Roy)
  • Demo Application(??)
  • One Look Back, Two Steps Forward(Akira)

60
One Look Back, Two Steps Forward
  • Speaker Chen, Chang-Min

61
One Look Back, Two Steps Forward
  • Initialize a render device?initialize the input
    device and vice versa
  • Force-feedback device
  • Simulated turbulence for a flight simulator
  • A bumpy road for a racing game
  • Action-mapping
  • Map certain user commands to arbitrary keys or
    buttons
  • ActionMapper Sample Code in DirectX 8.1 SDK until
    Summer 2004
  • XInput.h -- This module defines XBOX controller
    APIs
Write a Comment
User Comments (0)
About PowerShow.com