home | login | register | DMCA | contacts | help | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


my bookshelf | genres | recommend | rating of books | rating of authors | reviews | new | | collections | | | add
fantasy
space fantasy
fantasy is horrors
heroic
prose
  military
  child
  russian
detective
  action
  child
  ironical
  historical
  political
western
adventure
adventure (child)
child's stories
love
religion
antique
Scientific literature
biography
business
home pets
animals
art
history
computers
linguistics
mathematics
religion
home_garden
sport
technique
publicism
philosophy
chemistry
close

Loading...


Getting mouse data

As with the keyboard, we have a new function called ProcessMouse which is called from our Render function. This means that ProcessMouse will also be called once per frame. The code for ProcessMouse is shown below.

void CGame::ProcessMouse() {

DIMOUSESTATE MouseState;

if (FAILED(m_pMouse->GetDeviceState(sizeof(MouseState),(LPVOID)&MouseState))) {

return;

}

//Is the left mouse button down?

if (MOUSEBUTTONDOWN(MouseState.rgbButtons[MOUSEBUTTON_LEFT])) {

m_nMouseLeft = 1;

} else {

m_nMouseLeft = 0;

}

//Is the right mouse button down?

if (MOUSEBUTTONDOWN(MouseState.rgbButtons[MOUSEBUTTON_RIGHT])) {

m_nMouseRight = 1;

} else {

m_nMouseRight = 0;

}

m_nMouseX += MouseState.lX;

m_nMouseY += MouseState.lY;

}

So, to get access to the mouse data we make a call to GetDeviceState which fills a DIMOUSESTATE structure with data from the mouse. The DIMOUSESTATE structure has four members:

lX: Distance the mouse has moved along the x-axis since the last call to GetDeviceState.

lY: Distance the mouse has moved along the y-axis since the last call to GetDeviceState.

lZ: Distance mouse wheel has moved since the last call to GetDeviceState.

rgbButtons: Array of mouse button states.

lX, lY and lZ return the distance moved in device units (NOT pixels) since the last call to GetDeviceState. If you want to get the current screen position in pixels, you can use the Win32 GetCursorPos function. We use the macro MOUSEBUTTONDOWN to determine if a given mouse button is down or not. This macro is shown below along with some constants used for referring to mouse buttons.

#define MOUSEBUTTONDOWN(key) (key & 0x80)

#define MOUSEBUTTON_LEFT 0

#define MOUSEBUTTON_RIGHT 1

#define MOUSEBUTTON_MIDDLE 2


Getting keyboard data | DirectX 8 Programming Tutorial | Using the data







Loading...