News:

SMF - Just Installed!

Main Menu

How to use a Joystick

Started by Luke_128, January 21, 2011, 11:35:38 AM

Previous topic - Next topic

Luke_128

I would like to move inside the machines simulator using my Joysctick.
Is possible? ???

EasyPLC_Master

From version 1.4 is available the library JoystickLib.dll

Then you can make a program where the camera will be moved by the Joystick, to do it, you must to add the JoystickLib.dll external reference to your installation, then you can access at the Joystick buttons and axis.

I'm attach you here an example program:

JoystickLib.Joy joy;
Vector3 vc;
float view;

public void Init()
{
   joy = new JoystickLib.Joy();
   view = camera.ViewTo;
   vc = camera.Position;
}

public void Main(GameTime gameTime)
{
camera.enableKeyboard = false;
camera.Movement = Vector3.Zero;

joy.ReadJoystick();

if(joy.XPos < 1000)
{
   view += 1f;
   if(view > 360)
      view = 0;
   camera.ViewTo = view;
}
if(joy.XPos > 40000)
{
   view -= 1f;
   if(view<0)
      view = 360;
   camera.ViewTo = view;
}    
if(joy.YPos < 1000)
{
   vc = camera.Movement;
   vc.Z -= 3f;    
   camera.Movement = vc;
}    
if(joy.YPos > 40000)
{
   vc = camera.Movement;
   vc.Z += 3f;
   camera.Movement = vc;
}
if(joy.Buttons == 1)
{   
   vc = camera.Movement;
   vc.Y += 2f;
   camera.Movement = vc;
}
if(joy.Buttons == 2)
{   
   vc = camera.Movement;
   vc.Y -= 2f;
   camera.Movement = vc;
}   
}
public void Draw(GameTime gameTime)
{

}
public void Finish()
{

}

Luke_128