Results 1 to 39 of 39

Thread: Forcefeedback

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Forcefeedback

    How do I use forcefeedback on a gamepad in Visual Basic 2008?

    I can only find things that relate to C++

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Forcefeedback

    Hey,

    Are you using XNA?

    If so, the following may be of interest to you:

    http://www.krissteele.net/blogdetails.aspx?id=153

    Hope that helps!

    Gary

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Quote Originally Posted by gep13 View Post
    Hey,

    Are you using XNA?

    If so, the following may be of interest to you:

    http://www.krissteele.net/blogdetails.aspx?id=153

    Hope that helps!

    Gary
    Thanks Gary,

    Im not using XNA - can it be used to write windows apps in VB.net? I thought it was just for games.

    I will have a look at that site and see if I can incorporate any of that tutorial into my project.

    Thanks again
    Chris

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Forcefeedback

    Hey,

    On that side I am not sure, I haven't really used XNA, I just know about it existence.

    Gary

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Ok, thanks.

    I will have a look at XNA. If thats not successful, does anyone else know how I could achieve this in VB?

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Anyone else got any ideas please?

    I read something about using C++/# code (I think it was to do with DirectX) in a wrapper in VB.NET. What is a wrapper and how do I use it?

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Forcefeedback

    Hey,

    A wrapper would be simply including the C# Library in your application and exposing the functionality of it through VB.Net.

    Gary

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    which gamepad is it? Are you the guy who asked me about the xbox 360 gamepad?

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    gep13 - I thought that was the sort of idea. How do I go about doing this?

    kleinma - It was an original xbox controller (not 360) but yes it was me who PM'ed you.

    Thanks both

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    If that controller is compatible (it probably is) then it should be as easy as setting a reference to the Microsoft.Xna.Framework (you will need to first download and install XNA game studio 3.0 SDK which is free)

    Once you do that, you will be able to set the above reference in your code.

    Then (as far as sending rumble) it should be as simple as

    Code:
    GamePad.SetVibration(PlayerIndex.One, 1, 1)
    the two 1 values being passed are for the left and right motor (assuming it has 2 vibration motors like the 360 controller does) I would imagine if it only has 1, then one of those values is ignored. The intensity of the vibration is any value from 0.0 (none) to 1.0 (max vibration)

  11. #11

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Quote Originally Posted by kleinma View Post
    If that controller is compatible (it probably is) then it should be as easy as setting a reference to the Microsoft.Xna.Framework (you will need to first download and install XNA game studio 3.0 SDK which is free)

    Once you do that, you will be able to set the above reference in your code.

    Then (as far as sending rumble) it should be as simple as

    Code:
    GamePad.SetVibration(PlayerIndex.One, 1, 1)
    the two 1 values being passed are for the left and right motor (assuming it has 2 vibration motors like the 360 controller does) I would imagine if it only has 1, then one of those values is ignored. The intensity of the vibration is any value from 0.0 (none) to 1.0 (max vibration)
    I have done Tools -> Add reference -> Microsoft.XNA.Framework.

    I then put the following code

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            GamePad.SetVibration(PlayerIndex.One, 1, 1)
        End Sub
    But it says "Name 'GamePad' is not declared" and "Name 'PlayerIndex' is not declared".

    What have I done wrong?

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    at the very top of your code (above the class definition), put this:

    Code:
    Imports Microsoft.Xna.Framework
    Imports Microsoft.Xna.Framework.Input

  13. #13

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    There seems to be no errors now but when I click the button the rumble does not activate.

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    It has been a little while since I have worked with it, and I was working with a controller that I knew was supported. However you could try running it in a loop and see if has any effect when you do that.

    The application I used it for was polling, meaning it was constantly evaluating the controller state to apply whatever actions were needed.

  15. #15

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Maybe it is the controller that is not supported - Im pretty sure that XNA is for Xbox 360 controllers. The one I'm using relies on DirectInput which I don't think the 360 needs??

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    XNA is basically a wrapper around DirectInput. XNA is actually a wrapper around DirectX. There is no such thing as "managed directx" anymore. It was merged into XNA.

    I believe the XNA classes work with ANY device that supports direct input. The rumble thing COULD be different though.

  17. #17

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Ok, sorry for my ignorance! =]

    I will have another look at directinput, see what I can dig up. If you have any other ideas I would be very grateful.

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    Lets try something simple to start.

    Try putting this in your code:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            With GamePad.GetState(PlayerIndex.One)
                If .Buttons.A = ButtonState.Pressed Then
                    MessageBox.Show("Button A is pressed")
                Else
                    MessageBox.Show("Button A is NOT pressed, or this doesn't work")
                End If
            End With
        End Sub
    as you can see this is code for a button click event. So run your app and on your gamepad, hold down the A button, and then click the button on the form with the mouse. Which message does it give you?

  19. #19

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Quote Originally Posted by kleinma View Post
    Lets try something simple to start.

    Try putting this in your code:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            With GamePad.GetState(PlayerIndex.One)
                If .Buttons.A = ButtonState.Pressed Then
                    MessageBox.Show("Button A is pressed")
                Else
                    MessageBox.Show("Button A is NOT pressed, or this doesn't work")
                End If
            End With
        End Sub
    as you can see this is code for a button click event. So run your app and on your gamepad, hold down the A button, and then click the button on the form with the mouse. Which message does it give you?
    I get "Button A is NOT pressed" if I run that code, no matter which button I push on the xbox controller.

  20. #20
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    do you know if this controller is setup and installed correctly in Windows? Does it work in games? Does it show up in game controllers in the control panel?

  21. #21

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    The controller is set up fine. Windows recognises it and I already have some code in my project that gets data from the thumbsticks and recognises button presses.

  22. #22
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Forcefeedback

    Hey,

    Can you post some of the code that you are already using? That may help.

    Gary

  23. #23

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    The code I am using comes from the zip file on the 2nd post from here:

    http://www.vbforums.com/showthread.php?t=583176

  24. #24
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    that code looks the same as what I gave you, so perhaps the original xbox controller simply does not support sending rumble commands. I know it has rumble abilities, but maybe it was something non standard when the original xbox came out. I know this all works fine with a 360 controller, because I have used them personally.

  25. #25

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    It definitely supports rumble because there is a program in the DirectX SDK that makes the controller rumble depending on where you have moved the mouse - the only problem is that it is written in C#/++ (not sure which) rather than VB.

    Also, the XBCD driver that I am using has a little utility with it that allows you to activate the rumble. Come to think of it I think you can activate the rumble from the Windows game controllers control panel applet.

  26. #26
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    try using just this code to see if you get notifications of button presses when you press one of the A,B,X,Y buttons.

    Code:
    Imports Microsoft.Xna.Framework
    Imports Microsoft.Xna.Framework.Input
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim ControllerTimer As New Timer
            ControllerTimer.Interval = 100
            AddHandler ControllerTimer.Tick, AddressOf TimerTick
            ControllerTimer.Start()
    
        End Sub
    
        Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs)
    
            If GamePad.GetState(PlayerIndex.One).Buttons.A = ButtonState.Pressed Then
                MessageBox.Show("A button")
            End If
            If GamePad.GetState(PlayerIndex.One).Buttons.B = ButtonState.Pressed Then
                MessageBox.Show("B button")
            End If
            If GamePad.GetState(PlayerIndex.One).Buttons.X = ButtonState.Pressed Then
                MessageBox.Show("X button")
            End If
            If GamePad.GetState(PlayerIndex.One).Buttons.Y = ButtonState.Pressed Then
                MessageBox.Show("Y button")
            End If
        End Sub
    
    End Class

  27. #27

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Quote Originally Posted by kleinma View Post
    try using just this code to see if you get notifications of button presses when you press one of the A,B,X,Y buttons.

    Code:
    Imports Microsoft.Xna.Framework
    Imports Microsoft.Xna.Framework.Input
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim ControllerTimer As New Timer
            ControllerTimer.Interval = 100
            AddHandler ControllerTimer.Tick, AddressOf TimerTick
            ControllerTimer.Start()
    
        End Sub
    
        Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs)
    
            If GamePad.GetState(PlayerIndex.One).Buttons.A = ButtonState.Pressed Then
                MessageBox.Show("A button")
            End If
            If GamePad.GetState(PlayerIndex.One).Buttons.B = ButtonState.Pressed Then
                MessageBox.Show("B button")
            End If
            If GamePad.GetState(PlayerIndex.One).Buttons.X = ButtonState.Pressed Then
                MessageBox.Show("X button")
            End If
            If GamePad.GetState(PlayerIndex.One).Buttons.Y = ButtonState.Pressed Then
                MessageBox.Show("Y button")
            End If
        End Sub
    
    End Class


    Error: Name 'PlayerIndex' is not declared.

  28. #28
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    you sure you have the 2 import statements at the top?

    The full qualification of the enum value is:

    Microsoft.Xna.Framework.PlayerIndex.One

  29. #29

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Aha, I missed one of the imports

    I added it but still nothing. There are no errors reported but when I press buttons on the controller I dont get any messageboxes.

    I thought "GamePad.GetState(PlayerIndex.One).Buttons.A" was to do with Xbox 360 controllers?

    I came across this

    Code:
    applicationDevice.SendForceFeedbackCommand(ForceFeedbackCommand.SetActuatorsOn)
    I haven't actually got this code working but it looks hopeful. Does this mean anything to you?

  30. #30
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    You are probably correct about the original controller not being supported by XNA. I took another look, and it isn't DirectInput that is required of the device, it is XInput (the replacement for DirectInput). So this means that XNA doesn't require the 360 controller per say, but it does require a controller that was built with xinput in mind, which I would imagine the companies that still make these devices for games (like logitech) support now in their new devices.

    So it does look like to use the old XBOX controller, you would have to find or create some sort of DirectInput wrapper to expose it to .NET.

    Or you know... you could get a 360 controller

  31. #31

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Quote Originally Posted by kleinma View Post
    You are probably correct about the original controller not being supported by XNA. I took another look, and it isn't DirectInput that is required of the device, it is XInput (the replacement for DirectInput). So this means that XNA doesn't require the 360 controller per say, but it does require a controller that was built with xinput in mind, which I would imagine the companies that still make these devices for games (like logitech) support now in their new devices.

    So it does look like to use the old XBOX controller, you would have to find or create some sort of DirectInput wrapper to expose it to .NET.

    Or you know... you could get a 360 controller

    The code that I linked to in an earlier post, that's a DirectInput wrapper isn't it?

    Presumably if I can get input from the controller there isn't much more that needs to be done to send force feedback commands too? (I believe force feedback is part of DirectInput)?

  32. #32

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Ahh, I have just realised...

    You posted earlier asking about the code I was using - I did a VERY stupid thing and gave you a link to this thread.

    The thread I meant was this one:

    http://www.xtremevbtalk.com/showthread.php?t=246406

    The code I'm using is from the 2nd post on that thread, it's in a zip file.

    Sorry!

  33. #33
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    I can't view the zip file because I am not a member there. If you want you can upload the zip here and I can look. My guess is it is either making direct calls to DirectX, or it is using MDX (managed direct x) which is now discontiuned in favor of XNA (Managed Direct X 2.0 was cancelled and rolled into XNA)

    You can probably still get the 1.1 version of MDX though if you look around MS site for a download.

  34. #34

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    My code is identical to the attached code except I have added the following on the bottom:

    Oh, and the code for button 1 doesnt work

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
      applicationDevice.SendForceFeedbackCommand(ForceFeedbackCommand.SetActuatorsOn)
    
        End Sub
    
        Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    
            If labelButtons.Text <> ("") Then
                Label3.Text = ("Success")
            Else : Label3.Text = ("Fail")
    
    
            End If
    Attached Files Attached Files

  35. #35
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Forcefeedback

    ill have a look, but can't really test anything until im home, where my controller is.

  36. #36

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Ok, thank you very much =]

  37. #37

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    I downloaded the files from here and ran them and it worked:

    http://www.codeproject.com/KB/direct...efeedback.aspx

    In amongst those files is one called 'DirectInputWrapper.cs'

    Is this what I need in terms of a wrapper? Could I use it and if so, how?

  38. #38

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Any ideas?

  39. #39

    Thread Starter
    Member
    Join Date
    Sep 2007
    Posts
    48

    Re: Forcefeedback

    Bump

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width