Thread: someone explain this code? (directx)

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    someone explain this code? (directx)

    Code:
    #define AXIS_THRESHOLD  20
    
    void HandleAction(UINT nAction, DWORD dwData)
    {
        int nAxisPos = (int)dwData;
    
        switch (nAction)
        {
        case ACTIONS_LEFTRIGHT:
            if (nAxisPos < -AXIS_THRESHOLD)
            {
                g_bLeft = true;
                g_bRight = false;
            }
            else if (nAxisPos > AXIS_THRESHOLD)
            {
                g_bRight = true;
                g_bLeft = false;
            }
            else
            {
                g_bLeft = g_bRight = false;
            }
            break;
        
        case ACTIONS_LEFT:
            g_bLeft = (dwData != 0);
            break;
    
        case ACTIONS_RIGHT:
            g_bRight = (dwData != 0);
            break;
    
        case ACTIONS_QUIT:
            g_bQuit = true;
            break;
        
        default:
            break;
        }
    }
    could someone explain how "g_bRight = (dwData !=0)" works, and the part about the axis threshold? (from sunlight's tutorials)
    oh and if this helps:
    Code:
    // Check each device for actions
    void CheckInput()
    {
        DIDEVICEOBJECTDATA  pdidod[INPUT_DATA_LIMIT];
        DWORD               dwObjCount;
    
        if (g_pDeviceArray == NULL)
            return;
    
        for (int iDevice = 0; iDevice < g_nDevices; iDevice++)
        {
            // Poll the device for data. 
            g_pDeviceArray[iDevice]->Poll(); 
     
            // Retrieve the data.
            dwObjCount = INPUT_DATA_LIMIT;
            g_pDeviceArray[iDevice]->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),
                                                   pdidod,
                                                   &dwObjCount, 0);
            for (DWORD i = 0; i < dwObjCount; i++)
                // Handle the actions regardless of what device returned them.
                HandleAction(pdidod[i].uAppData, pdidod[i].dwData);
        }
    }
    Last edited by Leeman_s; 09-08-2002 at 12:14 PM.

  2. #2
    Registered User Dr. Bebop's Avatar
    Join Date
    Sep 2002
    Posts
    96
    >g_bRight = (dwData !=0)"
    g_bRight is assigned the boolean value of dwData != 0, so g_bRight will have either 1 or 0. The expression can be broken down like this, assuming dwData is 0:

    g_bRight = (dwData !=0)
    g_bRight = (0 !=0) // False
    g_bRight = 0

    Bebop
    Processing error: Stupidity detected.
    ------------------------------
    Dr. Bebop
    Windows XP Professional Ed.
    Microsoft Visual Studio 6

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. explain code
    By manzoor in forum C++ Programming
    Replies: 8
    Last Post: 09-15-2008, 05:28 AM
  2. explain this code please
    By lastresort in forum C++ Programming
    Replies: 1
    Last Post: 02-06-2005, 12:02 PM
  3. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM