예제 #1
0
        private void SetDirection(EffectObject effect, int[] direction)
        {
            // https://github.com/tloimu/adapt-ffb-joy/blob/master/FeedbackTester/frmMain.cs

            Effect param = new Effect();

            param.Flags = EffectFlags.Cartesian | EffectFlags.ObjectOffsets;
            effect.GetParameters(ref param, EffectParameterFlags.AllParams);

            param.SetDirection(direction);

            effect.SetParameters(param, EffectParameterFlags.Direction);
        }
예제 #2
0
        public void ApplyForce(double x, double y)
        {
            if (ForceFeedbackSupported)
            {
                var dd = e.GetDirection();

                dd[0] = (int)(x * 100);
                dd[1] = (int)(y * 100);
                e.SetDirection(dd);

                e.Constant.Magnitude = (int)(Math.Sqrt(x * x + y * y) * 10000.0);

                eo.SetParameters(e, EffectParameterFlags.Direction);
            }
        }
예제 #3
0
        private void controlSelect_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if(ffActuator != null)	ffActuator.Unacquire();
            feedbackAmountSlider.Enabled = false;
            objectGUIDValue.Enabled = false;
            xmlQueryButton.Enabled = false;
            foreach(DeviceInstance di in Manager.GetDevices(DeviceClass.All, EnumDevicesFlags.ForceFeeback))
            {
                if(((string)controlSelect.SelectedItem).CompareTo(di.InstanceName) == 0)
                {
                    ffActuator = new Device(di.InstanceGuid);
                    if(ffActuator == null)
                    {
                        throw new Exception("Cannot instantiate joystick");
                    }
                    //set cooperative level.
                    ffActuator.SetCooperativeLevel(
                        this,
                        CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background);

                    //Set axis mode absolute.
                    ffActuator.Properties.AxisModeAbsolute = true;

                    //Acquire joystick for capturing.
                    ffActuator.Acquire();

                    //Configure axes
                    foreach(DeviceObjectInstance doi in ffActuator.Objects)
                    {

                        //Set axes ranges.
                        if((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                        {
                            ffActuator.Properties.SetRange(
                                ParameterHow.ById,
                                doi.ObjectId,
                                new InputRange(-5000,5000));
                        }

                        int[] temp;

                        // Get info about first two FF axii on the device
                        if ((doi.Flags & (int)ObjectInstanceFlags.Actuator) != 0)
                        {
                            if (forceAxes != null)
                            {
                                temp = new int[forceAxes.Length + 1];
                                forceAxes.CopyTo(temp,0);
                                forceAxes = temp;
                            }
                            else
                            {
                                forceAxes = new int[1];
                            }

                            // Store the offset of each axis.
                            forceAxes[forceAxes.Length - 1] = doi.Offset;
                            if (forceAxes.Length == 2)
                            {
                                break;
                            }

                            string path =
                                @"C:\temp\force.ffe";
                            EffectList el = null;
                            el = ffActuator.GetEffects(path,FileEffectsFlags.ModifyIfNeeded);
                            EffectObject feo = null;
                            foreach(FileEffect fe in el)
                            {
                                constantVibrate = fe.EffectStruct;
                                feo = new EffectObject(
                                      fe.EffectGuid,
                                      fe.EffectStruct,
                                      ffActuator);
                                try
                                {
                                    feo.Download();
                                }
                                catch(Exception ex)
                                {
                                    throw new Exception("Could not download force feedback effect file.", ex);
                                }
                                eo = feo;
                                break;
                            }
                            constantVibrate.Constant.Magnitude = 0;
                            eo.SetParameters(constantVibrate, EffectParameterFlags.TypeSpecificParams);
                            eo.Download();
                            eo.Start(1);
                            feedbackAmountSlider.Enabled = true;
                            objectGUIDValue.Enabled = true;
                            xmlQueryButton.Enabled = true;
                        }
                    }
                    break;
                }
            }
        }