DirectX Force Feedback Question

Last post 02-01-2008, 4:44 PM by Johan Solo. 0 replies.
Sort Posts: Previous Next
  •  02-01-2008, 4:44 PM

    DirectX Force Feedback Question

    First off, if this isn't the right place for this question, then I apologize.

    Anyway, my question is two-fold.  I'm doing work in DirectX 9 on Visual Studio in Visual C# (but that can change if truly necessary) to get force feedback effects on a Sidewinder joystick.  As it is I have pre-loaded vibration effects (like gun recoil, chainsaw buzz, etc) playing like a charm, and have recently been working with ConstantForce, and after much finagling I did actually get it to do something like what it's supposed to do.  But it has caused two things:

    1) How do I get it to go in different directions?  I know that there is the "eff.SetDirection(new int[axis.Length]);" condition, and I know that replacing axis.Length with 0 will cause the force vector to push forward, but everything else causes it to push left.  I really need control over the direction of the force vector.

    2) Why is it that the same code when compiled in Visual Studio .Net results in a different sensation than when compiled in Visual Studio 2005?  Like, noticiably different!

    Hopefully someone can help me out here.  I would appreciate it.  Below I'll put the pertinent code for all to see and enjoy.
    Note: The trackbar1, 2, etc. values are just trackbar form elements I put into the design so that I could change the values for Gain, Magnitude, etc. on the fly.
    if(checkBox2.Checked)
    {
    foreach (EffectInformation ei in device.GetEffects(EffectType.All))
    {
    //If the joystick supports ConstantForce, then apply it.
    if (DInputHelper.GetTypeCode(ei.EffectType) == (int)EffectType.ConstantForce)
    {

    Effect eff = new Effect();
    // Allocate some memory for
    //directions and axis.
    eff.SetDirection(new int[0]); // new int[0] = forward zomg, everything else = left... hmmm
    eff.SetAxes(axis);

    eff.EffectType = EffectType.ConstantForce;
    eff.ConditionStruct = new Condition[axis.Length];
    eff.Constant = new ConstantForce();
    eff.Constant.Magnitude = trackBar1.Value;
    eff.Gain = trackBar2.Value;
    eff.SamplePeriod = trackBar3.Value;
    eff.Duration = trackBar4.Value;
    eff.TriggerRepeatInterval = trackBar5.Value;
    eff.TriggerButton = (int)Microsoft.DirectX.DirectInput.Button.NoTrigger;
    eff.Flags = EffectFlags.ObjectOffsets | EffectFlags.Cartesian;
    eff.UsesEnvelope = false;

    // Create the effect, using the passed in guid.
    eo = new EffectObject(ei.EffectGuid, eff, device);
    eo.Download();

    eo.Start(1,EffectStartFlags.NoDownload);

    label2.Text = "Effect GUID: " + eo.EffectGuid.ToString();
    label2.Text += "\n Is Effect Playing?: " + eo.EffectStatus.Playing.ToString();
    label2.Text += "\n Effect Type: " + eff.EffectType.ToString();
    label2.Text += "\n Axis Length: " + axis.Length;
    label2.Text += "\n Gain: " + trackBar2.Value.ToString();
    label2.Text += "\n Magnitude: " + trackBar1.Value.ToString();
    label2.Text += "\n Sample Period: " + trackBar3.Value.ToString();
    }
    }

    if (eo == null)
    {
    throw new Exception("ConstantForce is not supported.");
    }
    }

View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback