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

Mouse collisions

Topics: User Forum
Dec 28, 2006 at 10:19 AM

What are best practices for mouse collision detection?
Use PointEntity and mouse coordination?

Kind regards from Poland
Mateusz Kierepka
Dec 28, 2006 at 4:13 PM
The engine doesn't currently have an elegant solution for mouse collision. I'll put it on my list.

Just being able to test intersection of any point against any Geometry would be nice. Not sure it will be in the next release or not but i'll try to get it in as soon as I can.
Dec 28, 2006 at 4:42 PM
ok, so right now I can't implement my game :(
I try to use PointEntity but it seems not working properly (no collisions at all with PointGeometry).

btw. you should remove PhysicsSimulator parameter in PointEntity and PolygonEntity constructors.
Dec 28, 2006 at 5:11 PM
hmm I checked - for me Bounding box is good solution:

In RigidBody I added:

public BoundingBox BoundingBox
return new BoundingBox(new Vector3(Geometry.AABB.Min, 0),
new Vector3(Geometry.AABB.Max, 0));

And in my code I'm checking collision in this way:

BoundingBox bb = new BoundingBox(new Vector3(mousePosition, 0),
new Vector3(mousePosition.X + 1, mousePosition.Y + 1, 0));
if (circleGlassBallEntitiesi.RigidBody.BoundingBox.Intersects(bb))

And this is working - for ball selection is good enough.

Btw is it possible to drag objects? I need to select ball and drag it to another place? Seting it's position?
Dec 28, 2006 at 11:22 PM
You wouldn't want to set it's position directly. I think I need to add the ability to attach a spring or joint to the mouse position. Then when you click on the body, you could create the joint and drag... allowing the spring or joint to move the body.
Dec 29, 2006 at 1:31 PM
ok I will try AddJoint.

btw. Again new problem - there should be RemoveJoint ;)
Dec 29, 2006 at 2:39 PM
Is this correct:

glassBall.IsSelected = !glassBall.IsSelected;
if (glassBall.IsSelected)
Vector2 join =
mouseEntity.Position + ((mouseEntity.Position - glassBall.Position) / 2);

mouseJoint = new RevoluteJoint(mouseEntity.RigidBody, glassBall.RigidBody, join);

Dec 29, 2006 at 3:24 PM
Does it work?

I just added all the things necassary to do mouse dragging. It will be in the next release wich is coming probably tomorrow.
Dec 29, 2006 at 10:16 PM
ok - I will test this new code.

My code is working but mouse is too sesitive.
Jan 1, 2007 at 7:43 PM
Nice! You did all changes! I don't have too much time to test it, but I checked samples - it looks great!