Exemplo n.º 1
0
        protected override unsafe void OnUpdateEffectTypeSpecificParameters()
        {
            base.OnUpdateEffectTypeSpecificParameters();

            if (directInputEffect != null)
            {
                DIPERIODIC diPeriodic = new DIPERIODIC();
                diPeriodic.dwMagnitude = (uint)(10000.0f * Magnitude);
                diPeriodic.lOffset     = (int)((float)diPeriodic.dwMagnitude * Offset);
                diPeriodic.dwPhase     = (uint)(36000.0f * Phase);
                diPeriodic.dwPeriod    = (uint)(Period * DInput.DI_SECONDS);

                DIEFFECT diEffect = new DIEFFECT();
                diEffect.dwSize  = (uint)sizeof(DIEFFECT);
                diEffect.dwFlags = DInput.DIEFF_CARTESIAN | DInput.DIEFF_OBJECTOFFSETS;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIPERIODIC);
                diEffect.lpvTypeSpecificParams = &diPeriodic;

                int hr = IDirectInputEffect.SetParameters(directInputEffect, ref diEffect,
                                                          DInput.DIEP_TYPESPECIFICPARAMS);
                if (Wrapper.FAILED(hr))
                {
                    Log.Warning("DirectInputForceFeedbackPeriodicEffect: " +
                                "Cannot update Periodic effect parameters ({0}).",
                                DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                    return;
                }
            }
        }
Exemplo n.º 2
0
        protected override unsafe void OnUpdateEffectTypeSpecificParameters()
        {
            base.OnUpdateEffectTypeSpecificParameters();

            if (directInputEffect != null)
            {
                DIRAMPFORCE diRamp = new DIRAMPFORCE();
                diRamp.lStart = (int)(StartForce * DInput.DI_FFNOMINALMAX);
                diRamp.lEnd   = (int)(EndForce * DInput.DI_FFNOMINALMAX);

                DIEFFECT diEffect = new DIEFFECT();
                diEffect.dwSize  = (uint)sizeof(DIEFFECT);
                diEffect.dwFlags = DInput.DIEFF_CARTESIAN | DInput.DIEFF_OBJECTOFFSETS;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIRAMPFORCE);
                diEffect.lpvTypeSpecificParams = &diRamp;

                int hr = IDirectInputEffect.SetParameters(directInputEffect, ref diEffect,
                                                          DInput.DIEP_TYPESPECIFICPARAMS);
                if (Wrapper.FAILED(hr))
                {
                    Log.Warning("DirectInputForceFeedbackRampEffect: " +
                                "Cannot update Ramp effect parameters ({0}).",
                                DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                    return;
                }
            }
        }
Exemplo n.º 3
0
        protected override unsafe void OnUpdateEffectTypeSpecificParameters()
        {
            base.OnUpdateEffectTypeSpecificParameters();

            if (directInputEffect != null)
            {
                DICONDITION diCondition = new DICONDITION();
                diCondition.lOffset = (int)(Offset * DInput.DI_FFNOMINALMAX);
                diCondition.lNegativeCoefficient = (int)(NegativeCoefficient * DInput.DI_FFNOMINALMAX);
                diCondition.lPositiveCoefficient = (int)(PositiveCoefficient * DInput.DI_FFNOMINALMAX);
                diCondition.dwNegativeSaturation = (uint)(NegativeSaturation * DInput.DI_FFNOMINALMAX);
                diCondition.dwPositiveSaturation = (uint)(PositiveSaturation * DInput.DI_FFNOMINALMAX);
                diCondition.lDeadBand            = (int)(DeadBand * DInput.DI_FFNOMINALMAX);

                DIEFFECT diEffect = new DIEFFECT();
                diEffect.dwSize  = (uint)sizeof(DIEFFECT);
                diEffect.dwFlags = DInput.DIEFF_CARTESIAN | DInput.DIEFF_OBJECTOFFSETS;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DICONDITION);
                diEffect.lpvTypeSpecificParams = &diCondition;

                int hr = IDirectInputEffect.SetParameters(directInputEffect, ref diEffect,
                                                          DInput.DIEP_TYPESPECIFICPARAMS);
                if (Wrapper.FAILED(hr))
                {
                    Log.Warning("DirectInputForceFeedbackConditionEffect: " +
                                "Cannot update Condition effect parameters ({0}).",
                                DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                    return;
                }
            }
        }
Exemplo n.º 4
0
        public static unsafe void UpdateEffectDirection(ForceFeedbackEffect effect,
                                                        IDirectInputEffect *directInputEffect)
        {
            if (effect.Direction != null)
            {
                int *pDirections = stackalloc int[effect.Direction.Count];
                for (int n = 0; n < effect.Direction.Count; n++)
                {
                    pDirections[n] = (int)(effect.Direction[n] * DInput.DI_FFNOMINALMAX);
                }

                uint dwFlags = DInput.DIEP_DIRECTION;

                DIEFFECT diEffect = new DIEFFECT();
                diEffect.dwSize       = (uint)sizeof(DIEFFECT);
                diEffect.dwFlags      = DInput.DIEFF_CARTESIAN | DInput.DIEFF_OBJECTOFFSETS;
                diEffect.cAxes        = (uint)effect.Axes.Count;
                diEffect.rglDirection = pDirections;

                int hr = IDirectInputEffect.SetParameters(directInputEffect, ref diEffect, dwFlags);

                if (Wrapper.FAILED(hr))
                {
                    Log.Warning("DirectInputForceFeedbackEffect: " +
                                "Cannot update direction ({0}).",
                                DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                    return;
                }
            }
        }
Exemplo n.º 5
0
        public unsafe static IDirectInputEffect *CreateEffect(DirectInputJoystickInputDevice device,
                                                              ForceFeedbackEffectTypes effectType, IList <JoystickAxes> axes)
        {
            uint *pAxes       = stackalloc uint[axes.Count];
            int * pDirections = stackalloc int[axes.Count];

            for (int n = 0; n < axes.Count; n++)
            {
                pAxes[n]       = (uint)GetOffsetByAxisType(axes[n]);
                pDirections[n] = 0;
            }

            //

            DICONSTANTFORCE diConstantForce = new DICONSTANTFORCE();
            //DICUSTOMFORCE diCustomForce = new DICUSTOMFORCE();
            DICONDITION diCondition = new DICONDITION();
            DIPERIODIC  diPeriodic  = new DIPERIODIC();
            DIRAMPFORCE diRamp      = new DIRAMPFORCE();

            GUID     effectTypeGuid = new GUID();
            DIEFFECT diEffect       = new DIEFFECT();

            switch (effectType)
            {
            case ForceFeedbackEffectTypes.Spring:
                effectTypeGuid = DInput.GUID_Spring;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DICONDITION);
                diEffect.lpvTypeSpecificParams = &diCondition;
                break;

            case ForceFeedbackEffectTypes.Damper:
                effectTypeGuid = DInput.GUID_Damper;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DICONDITION);
                diEffect.lpvTypeSpecificParams = &diCondition;
                break;

            case ForceFeedbackEffectTypes.Friction:
                effectTypeGuid = DInput.GUID_Friction;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DICONDITION);
                diEffect.lpvTypeSpecificParams = &diCondition;
                break;

            case ForceFeedbackEffectTypes.Inertia:
                effectTypeGuid = DInput.GUID_Inertia;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DICONDITION);
                diEffect.lpvTypeSpecificParams = &diCondition;
                break;

            case ForceFeedbackEffectTypes.ConstantForce:
                effectTypeGuid = DInput.GUID_ConstantForce;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DICONSTANTFORCE);
                diEffect.lpvTypeSpecificParams = &diConstantForce;
                break;

            //case ForceFeedbackEffectTypes.CustomForce:
            //   effectTypeGuid = DInput.GUID_CustomForce;
            //   diEffect.cbTypeSpecificParams = (uint)sizeof( DICUSTOMFORCE );
            //   diEffect.lpvTypeSpecificParams = &diCustomForce;
            //   break;

            case ForceFeedbackEffectTypes.SawtoothDown:
                effectTypeGuid = DInput.GUID_SawtoothDown;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIPERIODIC);
                diEffect.lpvTypeSpecificParams = &diPeriodic;
                break;

            case ForceFeedbackEffectTypes.SawtoothUp:
                effectTypeGuid = DInput.GUID_SawtoothUp;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIPERIODIC);
                diEffect.lpvTypeSpecificParams = &diPeriodic;
                break;

            case ForceFeedbackEffectTypes.Sine:
                effectTypeGuid = DInput.GUID_Sine;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIPERIODIC);
                diEffect.lpvTypeSpecificParams = &diPeriodic;
                break;

            case ForceFeedbackEffectTypes.Square:
                effectTypeGuid = DInput.GUID_Square;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIPERIODIC);
                diEffect.lpvTypeSpecificParams = &diPeriodic;
                break;

            case ForceFeedbackEffectTypes.Triangle:
                effectTypeGuid = DInput.GUID_Triangle;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIPERIODIC);
                diEffect.lpvTypeSpecificParams = &diPeriodic;
                break;

            case ForceFeedbackEffectTypes.Ramp:
                effectTypeGuid = DInput.GUID_RampForce;
                diEffect.cbTypeSpecificParams  = (uint)sizeof(DIRAMPFORCE);
                diEffect.lpvTypeSpecificParams = &diRamp;
                break;
            }

            diEffect.dwSize                  = (uint)sizeof(DIEFFECT);
            diEffect.dwFlags                 = DInput.DIEFF_CARTESIAN | DInput.DIEFF_OBJECTOFFSETS;
            diEffect.dwDuration              = DInput.INFINITE;
            diEffect.dwSamplePeriod          = 0;
            diEffect.dwGain                  = DInput.DI_FFNOMINALMAX;
            diEffect.dwTriggerButton         = DInput.DIEB_NOTRIGGER;
            diEffect.dwTriggerRepeatInterval = 0;
            diEffect.cAxes          = (uint)axes.Count;
            diEffect.rgdwAxes       = pAxes;
            diEffect.rglDirection   = pDirections;
            diEffect.lpEnvelope     = null;
            diEffect.dwStartDelay   = 0;
            diEffect.dwSamplePeriod = 0;

            //

            void */*IDirectInputEffect*/ directInputEffect = null;

            int hr = IDirectInputDevice8.CreateEffect(device.directInputDevice,
                                                      ref effectTypeGuid, ref diEffect, out directInputEffect, null);

            if (Wrapper.FAILED(hr))
            {
                Log.Warning("DirectInputForceFeedbackController: " +
                            "Cannot create ForceFeedbackEffect for \"{0}\" ({1}).", device.Name,
                            DInput.GetOutString(DInput.DXGetErrorStringW(hr)));
                return(null);
            }

            return((IDirectInputEffect *)directInputEffect);
        }
 public unsafe static extern int SetParameters(void * /*IDirectInputEffect*/ _this,
                                               ref DIEFFECT /*LPCDIEFFECT*/ peff, uint dwFlags);
 public unsafe static extern int CreateEffect(void * /*IDirectInputDevice8*/ _this,
                                              ref GUID rguid, ref DIEFFECT /*LPCDIEFFECT*/ lpeff,
                                              out void * /*LPDIRECTINPUTEFFECT*/ ppdeff, void * /*LPUNKNOWN*/ punkOuter);