| 1902 | } |
| 1903 | |
| 1904 | void UpdateFrame() |
| 1905 | { |
| 1906 | static double lastTime; |
| 1907 | |
| 1908 | // real elapsed frame time |
| 1909 | double frameBeginTime = GetSeconds(); |
| 1910 | |
| 1911 | g_realdt = float(frameBeginTime - lastTime); |
| 1912 | lastTime = frameBeginTime; |
| 1913 | |
| 1914 | // do gamepad input polling |
| 1915 | double currentTime = frameBeginTime; |
| 1916 | static double lastJoyTime = currentTime; |
| 1917 | |
| 1918 | if (g_gamecontroller && currentTime - lastJoyTime > g_dt) |
| 1919 | { |
| 1920 | lastJoyTime = currentTime; |
| 1921 | |
| 1922 | int leftStickX = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_LEFTX); |
| 1923 | int leftStickY = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_LEFTY); |
| 1924 | int rightStickX = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_RIGHTX); |
| 1925 | int rightStickY = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY); |
| 1926 | int leftTrigger = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT); |
| 1927 | int rightTrigger = SDL_GameControllerGetAxis(g_gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
| 1928 | |
| 1929 | Vec2 leftStick(joyAxisFilter(leftStickX, 0), joyAxisFilter(leftStickY, 0)); |
| 1930 | Vec2 rightStick(joyAxisFilter(rightStickX, 1), joyAxisFilter(rightStickY, 1)); |
| 1931 | Vec2 trigger(leftTrigger / 32768.0f, rightTrigger / 32768.0f); |
| 1932 | |
| 1933 | if (leftStick.x != 0.0f || leftStick.y != 0.0f || |
| 1934 | rightStick.x != 0.0f || rightStick.y != 0.0f) |
| 1935 | { |
| 1936 | // note constant factor to speed up analog control compared to digital because it is more controllable. |
| 1937 | g_camVel.z = -4 * g_camSpeed * leftStick.y; |
| 1938 | g_camVel.x = 4 * g_camSpeed * leftStick.x; |
| 1939 | |
| 1940 | // cam orientation |
| 1941 | g_camAngle.x -= rightStick.x * 0.05f; |
| 1942 | g_camAngle.y -= rightStick.y * 0.05f; |
| 1943 | } |
| 1944 | |
| 1945 | // Handle left stick motion |
| 1946 | static bool bLeftStick = false; |
| 1947 | |
| 1948 | if ((leftStick.x != 0.0f || leftStick.y != 0.0f) && !bLeftStick) |
| 1949 | { |
| 1950 | bLeftStick = true; |
| 1951 | } |
| 1952 | else if ((leftStick.x == 0.0f && leftStick.y == 0.0f) && bLeftStick) |
| 1953 | { |
| 1954 | bLeftStick = false; |
| 1955 | g_camVel.z = -4 * g_camSpeed * leftStick.y; |
| 1956 | g_camVel.x = 4 * g_camSpeed * leftStick.x; |
| 1957 | } |
| 1958 | |
| 1959 | // Handle triggers as controller button events |
| 1960 | void ControllerButtonEvent(SDL_ControllerButtonEvent event); |
| 1961 |
no test coverage detected