MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / get_axis_value

Method get_axis_value

win32/WinController.cpp:814–978  ·  view source on GitHub ↗

note controller is index into ControlList.

Source from the content-addressed store, hash-verified

812
813// note controller is index into ControlList.
814float gameWinController::get_axis_value(int8_t controller, uint8_t axis, ct_format format, bool invert) {
815 if (controller <= NULL_WINCONTROLLER || controller >= CT_MAX_CONTROLLERS)
816 return 0.0f;
817
818 struct gameWinController::t_controller *ctldev = &m_ControlList[controller];
819 if (ctldev->id == CTID_INVALID)
820 return 0.0f;
821
822#ifdef _DEBUG
823 if (m_ControlList[controller].id == CTID_KEYBOARD) {
824 Int3();
825 return 0.0f;
826 }
827#endif
828
829 // verify controller axis
830 const int axisIndex = axis - 1;
831 if (!CHECK_FLAG(ctldev->flags, 1 << axisIndex))
832 return 0.0f;
833
834 // get raw value
835 float axisval = 0.0f;
836 switch (axis) {
837 // note we take care of mouse controls and external controls here
838 case CT_X_AXIS:
839 axisval = (float)((ctldev->id == CTID_MOUSE) ? m_MseState.m_deltaX : m_ExtCtlStates[ctldev->id].x);
840 break;
841 case CT_Y_AXIS:
842 axisval = (float)((ctldev->id == CTID_MOUSE) ? m_MseState.m_deltaY : m_ExtCtlStates[ctldev->id].y);
843 break;
844 case CT_Z_AXIS:
845 axisval = (float)((ctldev->id == CTID_MOUSE) ? m_MseState.m_deltaZ : m_ExtCtlStates[ctldev->id].z);
846 break;
847 case CT_R_AXIS:
848 axisval = (float)m_ExtCtlStates[ctldev->id].r;
849 break;
850 case CT_U_AXIS:
851 axisval = (float)m_ExtCtlStates[ctldev->id].u;
852 break;
853 case CT_V_AXIS:
854 axisval = (float)m_ExtCtlStates[ctldev->id].v;
855 break;
856 default:
857 Int3(); // NOT A VALID AXIS
858 }
859
860 // create normalizer
861 float normalizer, nullzone;
862 if (ctldev->id == CTID_MOUSE) {
863 const float kMinFrameTime = 0.000001f;
864 if (m_frame_time < kMinFrameTime) {
865 m_frame_time = kMinFrameTime;
866 }
867
868 normalizer = ctldev->normalizer[axisIndex] * m_frame_time;
869 nullzone = MOUSE_DEADZONE;
870 } else {
871 // really small deadzones will not take joystick drift into account, hence your mouse control will be cancelled out.

Callers

nothing calls this directly

Calls 4

GetFunctionModeFunction · 0.85
ObjSetOrientFunction · 0.85
vm_AnglesToMatrixFunction · 0.50
vm_OrthogonalizeFunction · 0.50

Tested by

no test coverage detected