2016-07-19 4 views
1

Xinput API를 사용하고 있는데 다음 코드와 관련하여 문제가 있습니다. 내 가정은 R/LX와 R/LY의 정의가 반복적으로 호출됨에 따라 동적으로 변경되어야하지만 엄지 스틱의 위치 값은 임의로 -13108로 설정되므로 정규화 된 X 및 Y 크기 -707이며 정규화 된 크기는 ~428입니다. 나는 계속 스틱을 움직이려고 노력하지만 값은 변하지 않을 것입니다. 어떤 아이디어? Xinput API를 오해하고 있습니까? 구조체 컨트롤러 상태가 의미가 있습니까? 아래의 코드는 왼쪽 스틱에 대한 것이지만 오른쪽 스틱은 매우 비슷합니다.Xbox 컨트롤러 Xinput을 사용하여 양쪽 엄지 손가락이 값을 변경하지 않습니다.

#define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849 
#define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689 
#define XINPUT_GAMEPAD_TRIGGER_THRESHOLD 30 
struct CONTROLLER_STATE 
    { 
     XINPUT_STATE state; 
     bool bConnected; 
    }; 
    CONTROLLER_STATE g_Controllers[4]; 

    while(1) 
    { 
      //... 
      XINPUT_STATE state = g_Controllers[1].state; 


      float LX = state.Gamepad.sThumbLX; 
      float LY = state.Gamepad.sThumbLY; 

      //determine how far the controller is pushed 
      float magnitude = sqrt(LX*LX + LY*LY); 

      //determine the direction the controller is pushed 
      float normalizedLX = LX/magnitude; 
      float normalizedLY = LY/magnitude; 
      cout << " Y " << LY << endl; 
      float normalizedMagnitude = 0; 

      //check if the controller is outside a circular dead zone 
      if (magnitude > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) 
      { 
       //clip the magnitude at its expected maximum value 
       if (magnitude > 32767) magnitude = 32767; 

       //adjust magnitude relative to the end of the dead zone 
       magnitude -= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE; 

       //optionally normalize the magnitude with respect to its expected range 
       //giving a magnitude value of 0.0 to 1.0 
       normalizedMagnitude = magnitude/(32767 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE); 
       cout << "normalizedMagnitude " << normalizedMagnitude; 

      } 
      else //if the controller is in the deadzone zero out the magnitude 
      { 
       magnitude = 0.0; 
       normalizedMagnitude = 0.0; 
      } 
    } 
+0

컨트롤러가 문제가 될 수 있습니까? – Zotto

+0

게시 한 코드에 컨트롤러 읽기가 표시되지 않습니다. 그러나 가장 가능성있는 오류의 위치는 XInputGetState() 근처의 코드입니다. (당신은 XInputGetState를 호출하고 있습니까?) –

답변

0

상태를 정규화했으며 다소 비어 있습니다. 나는 당신이 bool 함수 bConnected에서 XInputGetState()를 자주 호출한다고 가정 할 것이다. 그러나 이것은 아마도 한 번 호출 될 것이고 따라서 값은 동일하게 유지 될 것이다. 따라서 위 또는 위에 표시된 관련 함수에서 main 함수 또는 getstate 함수를 한 번 호출해야합니다. while 루프에서 첫 번째 줄은 실행될 때마다 상태가 계속 업데이트됩니다.