This project has moved and is read-only. For the latest updates, please go here.

How use MouseInputComponent?

Topics: User Forum
Dec 21, 2006 at 8:18 PM
I try to use it like this:

MouseInputComponent.AddButtonAction(new ButtonPressedAction(Buttons.Left, MousePressed));
Mouse.WindowHandle = Window.Handle;

But when I press mouse and try to drag it I got this error:

System.ArithmeticException was unhandled

Which is executed here:


w System.Math.Sign(Single value)
w FarseerGames.FarseerXNAPhysics.Dynamics.Body.ApplyDrag()
w FarseerGames.FarseerXNAPhysics.Dynamics.Body.IntegrateVelocity(Single dt)
w FarseerGames.FarseerXNAPhysics.PhysicsSimulator.ApplyForces(Single dt)
w FarseerGames.FarseerXNAPhysics.PhysicsSimulator.Update(Single dt)
w FarseerGames.FarseerXNAGame.Components.FarseerPhysicsComponent.Update(GameTime gameTime)
w Microsoft.Xna.Framework.Game.Update(GameTime gameTime)
w FarseerGames.FarseerXNAGame.FarseerGame.Update(GameTime gameTime)
w Microsoft.Xna.Framework.Game.Tick()
w Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
w Microsoft.Xna.Framework.GameHost.OnIdle()
w Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
w System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
w System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.Run(Form mainForm)
w Microsoft.Xna.Framework.WindowsGameHost.Run()
w Microsoft.Xna.Framework.Game.Run()
w ChristmasTree.Program.Main(String[] args)
Dec 22, 2006 at 5:03 AM
What is the code in the MousePressed function?
Dec 22, 2006 at 9:25 AM
It was problem with this code in MousePressed.

I don't convert mouse position to meters and my calculations for force was to big.

Btw is there any sample how to drag objects in Farseer - or how to disable object rigid body (make object incollidable) for time when it is moving.

Dec 22, 2006 at 1:00 PM
do drag, you would have to calculate a force based on the vector difference between your mouse and the object.

I don't think I have a disable collision parameter in there yet, but I do need to add it.

Dec 22, 2006 at 1:11 PM
ok. I will try to add - disable collision in rigid body. I sow nice code addin in WildBoarders game. They using new event - Collision it is really nice.
Dec 22, 2006 at 7:13 PM
I just thought of a way you "disable" collision for a body. It's a workaround until I get a CollisionEnabled property in.

The workaround. Set the bodies collision group to some number that no other body is set to. CollisionGroups only collide with like collision groups. By default all bodies are a member of the 0 collision group.
Dec 22, 2006 at 8:41 PM
hmm I just used this code:

private bool collidable = true;

/// <summary>
/// Is object collidable
/// </summary>
public bool Collidable
get { return collidable; }
set { collidable = value; }

private RigidBodyList notCollidable = new RigidBodyList();

/// <summary>
/// Objects which this object can't collide
/// </summary>
public RigidBodyList NotCollidable
get { return notCollidable; }
set { notCollidable = value; }

public void Collide(RigidBody rigidBody, ContactList contactList)
if (collidable)
if (!NotCollidable.Contains(rigidBody) && !rigidBody.NotCollidable.Contains(this))