[ Pobierz całość w formacie PDF ]
.GUID_RxAxisAn axis representing rotation relative to the x-axis.GUID_RyAxisAn axis representing rotation relative to the y-axis.GUID_RzAxisAn axis representing rotation relative to the z-axis.99 GUID_SliderA slider axis (for example, the throttle slider that appears on some joysticks).GUID_ButtonA button (on a mouse or joystick).GUID_KeyA key (on a keyboard).GUID_POVA POV hat that appears on some joysticks.GUID_UnknownAn unknown type of device.When an application requests the current state of the device, the information needs to be transmitted insome meaningful way.Just getting a list of bytes wouldn't provide enough information, and forcingapplications to use a standard communication method wouldn't elegantly solve the problem for all thedifferent types of devices on the market.Because of this, DirectInput lets the application dictate to thedevice how it wishes to receive its data.If you only want one or two buttons on a joystick, you don'tneed to request all of the data from the joystick, which may have dozens of buttons.Among otherthings, the application can decide if any axes on the device should be absolute (centered around aneutral origin, like a joystick axis) or relative (freely moving, like a mouse axis).When a device iscreated, you must call IDirectInputDevice8::SetDataFormat.HRESULT IDirectInputDevice8::SetDataFormat(LPCDIDATAFORMAT lpdf);lpdfA pointer to a DIDATAFORMAT structure that defines the format of the data received fromthe device.There are some defined constants that you can use:c_dfDIKeyboard Standard keyboard structure.An array of 256 characters, one foreach key.c_dfDIMouse Standard mouse structure.Three axes and four buttons.Corresponds to the DIMOUSESTATE structure.c_dfDIMouse2 Extended mouse structure.Three axes and eight buttons.Corresponds to the DIMOUSESTATE2 structure.c_dfDIJoystick Standard joystick.Three positional axes, three rotation axes, two100 sliders, a POV hat, and 32 buttons.Corresponds to the DIJOYSTATE structure.c_dfDIJoystick2 Extended capability joystick.Refers to the SDK documentation forthe truly massive data format definition.Corresponds to the DIJOYSTATE2 structure.Receiving Device StatesThere are two ways to receive data from a device: immediate data access and buffered data access.This code only uses immediate data access, but buffered data access is not without its merits.Buffereddata access is useful for when you absolutely need to get every input event that happens.If a key isquickly pressed and released between immediate device state requests, you will miss it since the statechanges aren't queued.If the application is running at any reasonable frame rate, however, this won'tbe a problem.Immediate data access is used to find the current state of the device at some point intime.If buttons were pressed and released between when you ask, you don't see them.You ask for thedevice state using IDirectInputDevice8::GetDeviceState:HRESULT IDirectInputDevice8::GetDeviceState(DWORD cbData,LPVOID lpvData);cbDataSize, in bytes, of the data structure being passed in with lpvData.lpvDataPointer to a buffer to fill with the device state.The format of the data depends on theformat you defined using SetDataFormat.For mouse devices, if you set the data format to c_dfDIMouse, the parameters to GetDeviceData shouldbe sizeof(DIMOUSESTATE) and the address of a valid DIMOUSESTATE structure.After the functioncompletes, if it is successful, the structure will be filled with the data from the mouse.typedef struct DIMOUSESTATE {LONG lX;LONG lY;LONG lZ;BYTE rgbButtons[4];} DIMOUSESTATE, *LPDIMOUSESTATE;lXX-axis of movement.Relative movement; if the axis hasn't moved since the last timeyou checked this will be 0.101 lYY-axis of movement.Relative movement; if the axis hasn't moved since the last timeyou checked this will be 0.lZZ-axis (mouse wheel) movement.Relative movement; if the axis hasn't moved sincethe last time it was checked this will be 0.rgbButtonsA set of bytes, one for each of four mouse buttons.To support a mouse with morebuttons, use the DIMOUSESTATE2 structure.As for the keyboard data, all you do is pass in a 256-element array of characters.Each characterrepresents a certain key.You can index into the array to find a certain key using the DirectInput keyconstants.There is a constant for every possible key on a keyboard.Table 3.2 has a list of the commonones.Some of the more obscure ones, like the ones for Japanese keyboards and web keyboards, arenot included.See the SDK documentation for a complete list at DirectX 9.0 C++Documentation/DirectInput/ DirectInput C++ Reference/Device Constants/Keyboard Device.Table 3.2: The common DirectInput keyboard constantsDIK_A & DIK_Z A through Z keysDIK_0 & DIK_9 0 through 9 keysDIK_F1 & DIK_F15 F1 through F15 keys, if they existDIK_NUMPAD0 & Number pad keys.The keys are the same regardless of whetherDIK_NUMPAD9or not Num Lock is on [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • necian.htw.pl