예제 #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;
                }
            }
        }
예제 #2
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);
        }