Nirtec Studio Forum

General Category => Machines Simulator => Topic started by: Luke_128 on January 21, 2011, 11:35:38 AM

Title: How to use a Joystick
Post by: Luke_128 on January 21, 2011, 11:35:38 AM
I would like to move inside the machines simulator using my Joysctick.
Is possible? ???
Title: Re: How to use a Joystick
Post by: EasyPLC_Master on January 21, 2011, 11:58:53 AM
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()
{

}
Title: Re: How to use a Joystick
Post by: Luke_128 on January 24, 2011, 04:43:36 PM
Clear!

Thank you very much.