public JoystickAxis(string axisName, float threshold) { this.axisName = axisName; this.joystick = InputUtility.AxisToJoystick(axisName); this.axis = InputUtility.AxisToJoystickAxis(axisName); this.threshold = threshold; }
public JoystickAxis(Joysticks joystick, JoystickAxes axis, float threshold) { this.joystick = joystick; this.axis = axis; this.axisName = InputUtility.JoystickInputToAxis(joystick, axis); this.threshold = threshold; }
//public static uint SecondsToMicroSeconds( float seconds ) //{ // x; // if( seconds == ForceFeedbackEffect.infiniteTime ) // return DInput.INFINITE; // return (uint)( seconds * DInput.DI_SECONDS ); //} //public static unsafe int SetParameters( ForceFeedbackEffect forceFeedbackEffect, // void* typeSpecificParams, uint specificParamsSize, IDirectInputEffect* directInputEffect ) //{ //DIENVELOPE effectEnvelope = new DIENVELOPE(); //if( forceFeedbackEffect.Envelope.Active ) //{ // effectEnvelope.dwSize = (uint)sizeof( DIENVELOPE ); // effectEnvelope.dwAttackLevel = // (uint)( forceFeedbackEffect.Envelope.AttackLevel * DInput.DI_FFNOMINALMAX ); // effectEnvelope.dwAttackTime = SecondsToMicroSeconds( forceFeedbackEffect.Envelope.AttackTime ); // effectEnvelope.dwFadeLevel = // (uint)( forceFeedbackEffect.Envelope.FadeLevel * DInput.DI_FFNOMINALMAX ); // effectEnvelope.dwFadeTime = SecondsToMicroSeconds( forceFeedbackEffect.Envelope.FadeTime ); //} //uint dwDuration = SecondsToMicroSeconds( forceFeedbackEffect.Duration ); ////uint dwTriggerRepeatInterval = SecondsToMicroSeconds( forceFeedbackEffect.TriggerRepeatInterval ); //uint dwSamplePeriod = SecondsToMicroSeconds( forceFeedbackEffect.SamplePeriod ); ////uint dwTriggerButton = DInput.DIEB_NOTRIGGER; ////if( forceFeedbackEffect.TriggerButtonEnabled ) //// dwTriggerButton = (uint)GetOffsetByButtonType( forceFeedbackEffect.TriggerButton ); //uint dwFlags = DInput.DIEP_TYPESPECIFICPARAMS | DInput.DIEP_DURATION | DInput.DIEP_ENVELOPE | // DInput.DIEP_GAIN | DInput.DIEP_SAMPLEPERIOD; ////uint dwFlags = DInput.DIEP_TYPESPECIFICPARAMS | DInput.DIEP_DURATION | DInput.DIEP_ENVELOPE | //// DInput.DIEP_GAIN | DInput.DIEP_TRIGGERBUTTON | DInput.DIEP_TRIGGERREPEATINTERVAL | //// DInput.DIEP_STARTDELAY | DInput.DIEP_SAMPLEPERIOD; //DIEFFECT diEffect = new DIEFFECT(); //diEffect.dwSize = (uint)sizeof( DIEFFECT ); //diEffect.dwFlags = DInput.DIEFF_CARTESIAN | DInput.DIEFF_OBJECTOFFSETS; //diEffect.lpEnvelope = ( forceFeedbackEffect.Envelope.Active ) ? &effectEnvelope : null; //diEffect.cbTypeSpecificParams = specificParamsSize; //diEffect.lpvTypeSpecificParams = typeSpecificParams; //diEffect.dwDuration = dwDuration; //diEffect.dwGain = forceFeedbackEffect.Gain; //diEffect.dwTriggerButton = DInput.DIEB_NOTRIGGER; ////effectParams.dwTriggerButton = dwTriggerButton; //diEffect.dwTriggerRepeatInterval = 0; ////effectParams.dwTriggerRepeatInterval = dwTriggerRepeatInterval; ////diEffect.dwStartDelay = (uint)( forceFeedbackEffect.StartDelay * DInput.DI_SECONDS ); //diEffect.dwSamplePeriod = dwSamplePeriod; //int hr = IDirectInputEffect.SetParameters( directInputEffect, ref diEffect, dwFlags ); //return hr; //} //public static int GetOffsetByButtonType( JoystickButtons buttonName ) //{ // int offset = (int)buttonName + DInput.DIJOFS_BUTTON0; // return offset; //} static int GetOffsetByAxisType(JoystickAxes axisName) { switch (axisName) { case JoystickAxes.X: return(DInput.DIJOFS_X); case JoystickAxes.Y: return(DInput.DIJOFS_Y); case JoystickAxes.Z: return(DInput.DIJOFS_Z); case JoystickAxes.Rx: return(DInput.DIJOFS_RX); case JoystickAxes.Ry: return(DInput.DIJOFS_RY); case JoystickAxes.Rz: return(DInput.DIJOFS_RZ); default: Log.Fatal("DirectInputForceFeedbackController: GetOffsetByAxisType " + "axisType \"{0}\" incorrect.", axisName); return(-1); } }
public JoystickAxis(string name, string axisName) { this.name = name; this.axisName = axisName; joystick = InputSystem.AxisToJoystick(axisName); axis = InputSystem.AxisToJoystickAxis(axisName); }
public JoystickAxis(string name, Joysticks joystick, JoystickAxes axis) { this.name = name; this.joystick = joystick; this.axis = axis; axisName = InputSystem.JoystickInputToAxis(joystick, axis); }
public Axis GetAxisByName(JoystickAxes axis) { int key = (int)axis; if (key >= axesDictionary.Length) { return(null); } return(axesDictionary[key]); }
public double GetJoystickAxis(JoystickAxes axis) { var index = (int)axis; if (index >= 0 && index < joystickAxes.Length) { return(joystickAxes[index]); } return(0); }
public double GetAxis(JoystickAxes axis) { switch (axis) { case JoystickAxes.Y: return fixDeadZone(-base.GetRawAxis((int)axis)); case JoystickAxes.X: return fixDeadZone(base.GetRawAxis((int)axis)); default: return base.GetRawAxis((int)axis); } }
public override string ToString() { string result = EffectType.ToString(); if (Axes.Count > 0) { result += ", Axes: "; for (int n = 0; n < Axes.Count; n++) { JoystickAxes axis = Axes[n]; if (n > 0) { result += ", "; } result += axis.ToString(); } } return(result); }
// public Axis(JoystickAxes name, RangeF range, bool isForceFeedbackSupported) { this.name = name; this.range = range; this.isForceFeedbackSupported = isForceFeedbackSupported; }
public SystemJoystickValue(JoystickAxes axis, JoystickAxisFilters axisFilter, float strength) { type = Types.Axis; this.axis = axis; this.axisFilter = axisFilter; this.strength = strength; }
public SystemJoystickValue(JoystickAxes axis) { type = Types.Axis; this.axis = axis; }
public SystemJoystickValue( JoystickAxes axis, JoystickAxisFilters axisFilter ) { type = Types.Axis; this.axis = axis; this.axisFilter = axisFilter; }
unsafe static bool EnumDeviceObjectsHandler(IntPtr /*DIDEVICEOBJECTINSTANCE*/ lpddoi, void *pvRef) { DirectInputJoystickInputDevice device = tempDeviceForEnumerate; DIDEVICEOBJECTINSTANCE *deviceObjectInstance = (DIDEVICEOBJECTINSTANCE *)lpddoi; if ((deviceObjectInstance->dwType & DInput.DIDFT_AXIS) != 0) { int hr; // set range DIPROPRANGE diPropRange = new DIPROPRANGE(); diPropRange.diph.dwSize = (uint)sizeof(DIPROPRANGE); diPropRange.diph.dwHeaderSize = (uint)sizeof(DIPROPHEADER); diPropRange.diph.dwHow = DInput.DIPH_BYID; diPropRange.diph.dwObj = deviceObjectInstance->dwType; diPropRange.lMin = -(int)MaxRange; diPropRange.lMax = +(int)MaxRange; GUID *propRangeGuid = (GUID *)DInput.getDIPROP_RANGE(); hr = IDirectInputDevice8.SetProperty_DIPROPRANGE(device.directInputDevice, propRangeGuid, ref diPropRange); //hr = IDirectInputDevice8.SetProperty( device.directInputDevice, // propRangeGuid, ref diPropRange.diph ); if (Wrapper.FAILED(hr)) { Log.Warning("DirectInputJoystickInputDevice: Cannot set axis range for \"{0}\" ({1}).", device.Name, DInput.GetOutString(DInput.DXGetErrorStringW(hr))); } // set axis type //uint userData = 0xFFFFFFFF; if (deviceObjectInstance->guidType == DInput.GUID_Slider) { device.temporarySliderCount++; } if (deviceObjectInstance->guidType == DInput.GUID_XAxis || deviceObjectInstance->guidType == DInput.GUID_YAxis || deviceObjectInstance->guidType == DInput.GUID_ZAxis || deviceObjectInstance->guidType == DInput.GUID_RxAxis || deviceObjectInstance->guidType == DInput.GUID_RyAxis || deviceObjectInstance->guidType == DInput.GUID_RzAxis) { // set dead zone //DIPROPDWORD deadZone = new DIPROPDWORD(); //deadZone.diph.dwSize = (uint)sizeof( DIPROPDWORD ); //deadZone.diph.dwHeaderSize = (uint)sizeof( DIPROPHEADER ); //deadZone.diph.dwHow = DInput.DIPH_BYID; //deadZone.diph.dwObj = deviceObjectInstance->dwType; // Specify the enumerated axis //deadZone.dwData = 500; // dead zone of 5% //GUID* propDeadZone = (GUID*)DInput.getDIPROP_DEADZONE(); //hr = IDirectInputDevice8.SetProperty( joystickDevice, // propDeadZone, ref deadZone.diph ); //if( Wrapper.FAILED( hr ) ) //{ // Log.Error( "Cannot set axis dead zone for '" + Name + "'" ); //} // type settings //userData = 0x80000000 | (uint)device.temporaryAxisList.Count; JoystickAxes axisName = GetJoystickAxisNameByGUID(deviceObjectInstance->guidType); RangeF range = new RangeF(-1, 1); bool forceFeedbackSupported = (deviceObjectInstance->dwFlags & DInput.DIDOI_FFACTUATOR) != 0; JoystickInputDevice.Axis axis = new JoystickInputDevice.Axis( axisName, range, forceFeedbackSupported); device.temporaryAxisList.Add(axis); } //// set user data //DIPROPPOINTER diptr = new DIPROPPOINTER(); //diptr.diph.dwSize = (uint)sizeof( DIPROPPOINTER ); //diptr.diph.dwHeaderSize = (uint)sizeof( DIPROPHEADER ); //diptr.diph.dwHow = DInput.DIPH_BYID; //diptr.diph.dwObj = deviceObjectInstance->dwType; ////if( IntPtr.Size == 8 ) ////{ //// UInt64 v64 = userData; //// NativeUtils.CopyMemory( (IntPtr)( &diptr.uData ), (IntPtr)( &v64 ), IntPtr.Size ); ////} ////else ////{ //// NativeUtils.CopyMemory( (IntPtr)( &diptr.uData ), (IntPtr)( &userData ), IntPtr.Size ); ////} //diptr.uData = IntPtr.Zero; ////diptr.uData = (IntPtr)userData; //GUID* appDataGuid = (GUID*)DInput.getDIPROP_APPDATA(); //hr = IDirectInputDevice8.SetProperty( device.directInputDevice, // appDataGuid, ref diptr.diph ); //if( Wrapper.FAILED( hr ) ) //{ // Log.InvisibleInfo( "DirectInputJoystickDevice: Cannot set appData for \"{0}\".", // device.Name ); // //Log.Warning( "DirectInputJoystickDevice: Cannot set appData for \"{0}\".", // // device.Name ); //} } return(true); // continue }
public DefaultJoystickValueAttribute(JoystickAxes axis, JoystickAxisFilters filter) { value = new GameControlsManager.SystemJoystickValue(axis, filter); }
public SystemJoystickValue(JoystickAxes axis, JoystickAxisFilters axisFilter) { type = Types.Axis; this.axis = axis; this.axisFilter = axisFilter; }
public static string JoystickInputToAxis(Joysticks joystick, JoystickAxes axis) { return(joystick.ToString() + axis); }
public static string JoystickInputToAxis(Joysticks joystick, JoystickAxes axis) { return joystick.ToString() + axis; }
public TestEffectAxisItem( JoystickAxes[] axes ) { this.axes = axes; }
public DefaultJoystickValueAttribute( JoystickAxes axis, JoystickAxisFilters filter ) { value = new GameControlsManager.SystemJoystickValue( axis, filter ); }
public JoystickAxis(string name, string axisName) : base(name, axisName) { _joystick = InputSystem.AxisToJoystick(axisName); _axisInput = InputSystem.AxisToJoystickAxis(axisName); }
unsafe protected override void OnUpdateState() { int hr; // gain access to device hr = IDirectInputDevice8.Poll(directInputDevice); if (Wrapper.FAILED(hr)) { if (hr == DInput.GetHRESULT_DIERR_INPUTLOST()) { if (!IsDeviceLost()) { DeviceLost(); return; } } hr = IDirectInputDevice8.Acquire(directInputDevice); while (hr == DInput.GetHRESULT_DIERR_INPUTLOST()) { hr = IDirectInputDevice8.Acquire(directInputDevice); } IDirectInputDevice8.Poll(directInputDevice); } else { if (IsDeviceLost()) { DeviceRestore(); } } // get data uint entries = BufferSize; DIDEVICEOBJECTDATA *entryPtr = (DIDEVICEOBJECTDATA *)deviceDataBuffer; hr = IDirectInputDevice8.GetDeviceData(directInputDevice, (uint)sizeof(DIDEVICEOBJECTDATA), entryPtr, ref entries, 0); if (Wrapper.FAILED(hr)) { //Log.Info( "Cannot get device data for '" + Name + "' error = " + // DInput.GetOutString( DInput.DXGetErrorStringW( hr ) ) ); return; } // process data for (int k = 0; k < entries; k++) { switch (entryPtr->dwOfs) { case DInput.DIJOFS_X: case DInput.DIJOFS_Y: case DInput.DIJOFS_Z: case DInput.DIJOFS_RX: case DInput.DIJOFS_RY: case DInput.DIJOFS_RZ: { JoystickAxes axisName = JoystickAxes.X; switch (entryPtr->dwOfs) { case DInput.DIJOFS_X: axisName = JoystickAxes.X; break; case DInput.DIJOFS_Y: axisName = JoystickAxes.Y; break; case DInput.DIJOFS_Z: axisName = JoystickAxes.Z; break; case DInput.DIJOFS_RX: axisName = JoystickAxes.Rx; break; case DInput.DIJOFS_RY: axisName = JoystickAxes.Ry; break; case DInput.DIJOFS_RZ: axisName = JoystickAxes.Rz; break; } Axis axis = GetAxisByName(axisName); float value = (float)((int)entryPtr->dwData) / MaxRange; //invert value for specific axes if (axis.Name == JoystickAxes.Y || axis.Name == JoystickAxes.Ry || axis.Name == JoystickAxes.Rz) { value = -value; } axis.Value = value; InputDeviceManager.Instance.SendEvent(new JoystickAxisChangedEvent(this, axis)); } break; case DInput.DIJOFS_SLIDER00: { Vector2F value = Sliders[0].Value; value.X = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[0].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[0], JoystickSliderAxes.X)); } break; case DInput.DIJOFS_SLIDER01: { Vector2F value = Sliders[0].Value; value.Y = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[0].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[0], JoystickSliderAxes.Y)); } break; case DInput.DIJOFS_SLIDER10: { Vector2F value = Sliders[1].Value; value.X = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[1].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[1], JoystickSliderAxes.X)); } break; case DInput.DIJOFS_SLIDER11: { Vector2F value = Sliders[1].Value; value.Y = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[1].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[1], JoystickSliderAxes.Y)); } break; case DInput.DIJOFS_SLIDER20: { Vector2F value = Sliders[2].Value; value.X = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[2].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[2], JoystickSliderAxes.X)); } break; case DInput.DIJOFS_SLIDER21: { Vector2F value = Sliders[2].Value; value.Y = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[2].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[2], JoystickSliderAxes.Y)); } break; case DInput.DIJOFS_SLIDER30: { Vector2F value = Sliders[3].Value; value.X = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[3].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[3], JoystickSliderAxes.X)); } break; case DInput.DIJOFS_SLIDER31: { Vector2F value = Sliders[3].Value; value.Y = -(float)((int)entryPtr->dwData) / MaxRange; Sliders[3].Value = value; InputDeviceManager.Instance.SendEvent( new JoystickSliderChangedEvent(this, Sliders[3], JoystickSliderAxes.Y)); } break; case DInput.DIJOFS_POV0: UpdatePOV(0, entryPtr->dwData); break; case DInput.DIJOFS_POV1: UpdatePOV(1, entryPtr->dwData); break; case DInput.DIJOFS_POV2: UpdatePOV(2, entryPtr->dwData); break; case DInput.DIJOFS_POV3: UpdatePOV(3, entryPtr->dwData); break; default: if (entryPtr->dwOfs >= DInput.DIJOFS_BUTTON0 && entryPtr->dwOfs < DInput.DIJOFS_BUTTON128) { int buttonIndex = (int)(entryPtr->dwOfs - DInput.DIJOFS_BUTTON0); bool pressed = ((entryPtr->dwData & 0x80) != 0); Button button = Buttons[buttonIndex]; if (button.Pressed != pressed) { button.Pressed = pressed; if (pressed) { InputDeviceManager.Instance.SendEvent( new JoystickButtonDownEvent(this, button)); } else { InputDeviceManager.Instance.SendEvent( new JoystickButtonUpEvent(this, button)); } } } break; } entryPtr++; } //update states for effects. effects can be destroyed inside OnUpdateState(). if (ForceFeedbackController != null) { ForceFeedbackController.OnUpdateState(); } }
public void AnimationUpdate() { float curAnimationRound = _joystick.round; float curAnimationVertical = _joystick.vertical; float curAnimationHorizontal = _joystick.horizontal; // Add condition "car burn out" // ---------------------------------------------------------------------------------------------------------------- // if (false) { float normalizedRound = (Mathf.Abs(_joystick.round) > 0 ? Mathf.Sign(_joystick.round) : 0); float normalizedVertical = (Mathf.Abs(_joystick.vertical) > 0 ? Mathf.Sign(_joystick.vertical) : 0); float normalizedHorizontal = (Mathf.Abs(_joystick.horizontal) > 0 ? Mathf.Sign(_joystick.horizontal) : 0); float targetRound = normalizedRound * _joystick.traction; float targetVertical = normalizedVertical * _joystick.traction; float targetHorizontal = normalizedHorizontal * _joystick.traction; curAnimationRound = Mathf.SmoothStep(animator.GetFloat("Round"), targetRound, Time.deltaTime); curAnimationVertical = Mathf.SmoothStep(animator.GetFloat("Vertical"), targetHorizontal, Time.deltaTime); curAnimationHorizontal = Mathf.SmoothStep(animator.GetFloat("Horizontal"), targetHorizontal, Time.deltaTime); } // ---------------------------------------------------------------------------------------------------------------- // //animator.SetFloat("Round", _joystick.round); //animator.SetFloat("Vertical", _joystick.vertical); //animator.SetFloat("Horizontal", _joystick.horizontal); bool localIsIdle = false; animator.SetFloat("Round", curAnimationRound); animator.SetFloat("Vertical", curAnimationVertical); animator.SetFloat("Horizontal", curAnimationHorizontal); animator.SetBool("Power", power.state); animator.speed = 1.0f; // Idle if (Mathf.Abs(_joystick.round) < 0.01f && Mathf.Abs(_joystick.vertical) < 0.01f && Mathf.Abs(_joystick.horizontal) < 0.01f || !power.state) { isWalkAndStrafe = false; // main idle animation isWalkAndRotation = false; isStrafeAndRotation = false; localIsIdle = true; } // Walk and strafe || walk else if ( Mathf.Abs(_joystick.round) < 0.01f && Mathf.Abs(_joystick.vertical) > 0.01f && Mathf.Abs(_joystick.horizontal) > 0.01f || Mathf.Abs(_joystick.round) < 0.01f && Mathf.Abs(_joystick.vertical) > 0.01f && Mathf.Abs(_joystick.horizontal) < 0.01f) { animator.speed = Mathf.Max(Mathf.Abs(_joystick.vertical), Mathf.Abs(_joystick.horizontal)); //animator.speed = _joystick.traction; isWalkAndStrafe = true; isWalkAndRotation = false; isStrafeAndRotation = false; } // Walk and rotation || rotation else if ( Mathf.Abs(_joystick.round) > 0.01f && Mathf.Abs(_joystick.vertical) > 0.01f && Mathf.Abs(_joystick.horizontal) < 0.01f || Mathf.Abs(_joystick.round) > 0.01f && Mathf.Abs(_joystick.vertical) < 0.01f && Mathf.Abs(_joystick.horizontal) < 0.01f) { animator.speed = Mathf.Max(Mathf.Abs(_joystick.vertical), Mathf.Abs(_joystick.round)); //animator.speed = _joystick.traction; isWalkAndStrafe = false; isWalkAndRotation = true; isStrafeAndRotation = false; } // Strafe and rotation || strafe else if ( _joystick.traction > 0.01f && ( Mathf.Abs(_joystick.round) > 0.01f && Mathf.Abs(_joystick.vertical) < 0.01f && Mathf.Abs(_joystick.horizontal) > 0.01f || Mathf.Abs(_joystick.round) < 0.01f && Mathf.Abs(_joystick.vertical) < 0.01f && Mathf.Abs(_joystick.horizontal) > 0.01f)) { animator.speed = Mathf.Max(Mathf.Abs(_joystick.round), Mathf.Abs(_joystick.horizontal)); //animator.speed = _joystick.traction; isWalkAndStrafe = false; isWalkAndRotation = false; isStrafeAndRotation = true; } animator.SetBool("IsWalkAndStrafe", isWalkAndStrafe); animator.SetBool("IsWalkAndRotation", isWalkAndRotation); animator.SetBool("IsStrafeAndRotation", isStrafeAndRotation); isIdle = localIsIdle; _lastJoystick = _joystick; _lastAnimationRound = curAnimationRound; _lastAnimationVertical = curAnimationVertical; _lastAnimationHorizontal = curAnimationHorizontal; }
public Vector2 GetAxes( JoystickAxes axes, int joystickIndex = 0 ) { return _joystickAxes[joystickIndex, (int)axes]; }
/// <summary> /// Check if the Given Input is Binded. Return the currently binded control to the input /// </summary> public bool IsAlreadyBinded(JoystickAxes axis, JoystickAxisFilters filters, out SystemJoystickValue control) { control = null; foreach (GameControlItem item in Items) { if (item.BindedJoystickValues.Count <= 0) continue; foreach (SystemJoystickValue value in item.BindedJoystickValues) { if (value.Type == SystemJoystickValue.Types.Axis && value.Axis == axis && value.AxisFilter == filters) { control = value; return true; } } } return false; }
public SystemJoystickValue(SystemJoystickValue source) { type = source.Type; button = source.Button; axis = source.Axis; axisFilter = source.AxisFilter; pov = source.POV; povDirection = source.POVDirection; _parent = source.Parent; strength = source.strength; }
public JoystickAxis(string name, Joysticks joystick, JoystickAxes axis) : base(name, InputSystem.JoystickInputToAxis(joystick, axis)) { _joystick = joystick; _axisInput = axis; }