How to make mouseJoints "multi touchable" ?

I am controlling a box2D application with my Iphone.
As the iphone is a multitouch screen, you may have several inputs, unlike the computer mouse.
I box2D multi touchable ?

My mouseJoints only work with one user Input, but all goes crazy when there are several inputs.
it doesn't work with this (contact is the position, I get from the iphone, which replaces mouseX, mouseY):

What am I doing wrong here ?

public function checkContact(contact, id:Number):void {

var body:b2Body=GetBodyAtMouse(contact);

if (body /* && (body.GetUserData() is PlayerActor */ ) {
if (PlayerActor(body.GetUserData()).waiting) {
PlayerActor(body.GetUserData()).waiting = false;
PlayerActor(body.GetUserData()).onClick(new MouseEvent(MouseEvent.CLICK));
}
var mouseJointDef:b2MouseJointDef=new b2MouseJointDef;
mouseJointDef.body1=PhysiVals.world.GetGroundBody();
mouseJointDef.body2=body;
mouseJointDef.target.Set(contact.x/PhysiVals.RATIO, contact.y/PhysiVals.RATIO);
mouseJointDef.maxForce=30000;
mouseJointDef.timeStep=PhysiVals.FRAME_RATE;
mouseJointArr[id]=PhysiVals.world.CreateJoint(mouseJointDef) as b2MouseJoint;
}
}

public function destroyContact(id:Number):void {
if (mouseJointArr[id]) {
PhysiVals.world.DestroyJoint( mouseJointArr[id] );
mouseJointArr[id] = null;
}
}

public function GetBodyAtMouse(contact,includeStatic:Boolean=false):b2Body {
var mouseXWorldPhys:Number = contact.x/PhysiVals.RATIO;
var mouseYWorldPhys:Number = contact.y/PhysiVals.RATIO;
trace ("mouseXWorldPhys",mouseXWorldPhys);
_mousePVec.Set(mouseXWorldPhys, mouseYWorldPhys);
var aabb:b2AABB = new b2AABB();
aabb.lowerBound.Set(mouseXWorldPhys - 0.001, mouseYWorldPhys - 0.001);
aabb.upperBound.Set(mouseXWorldPhys + 0.001, mouseYWorldPhys + 0.001);
var k_maxCount:int=10;
var shapes:Array = new Array();
var count:int=PhysiVals.world.Query(aabb,shapes,k_maxCount);
var body:b2Body=null;
for (var i:int = 0; i < count; ++i) {
if (shapes[i].GetBody().IsStatic()==false||includeStatic) {
var tShape:b2Shape=shapes[i] as b2Shape;
var inside:Boolean=tShape.TestPoint(tShape.GetBody().GetXForm(),_mousePVec);
if (inside) {
body=tShape.GetBody();
break;
}
}
}
return body;
}
How are you updating your mouse joints?
Plus, that force value of 30,000 seems really high to me. You might be getting some extrememly unstable behaviour because your forces are too high.
more generally spoken, what do I have to think of, if I want to make a multitouch game with Box 2D, especially when I work with mousejoints ?

Is box2D world capable of handling several mousejoints at all ?
I looked in the source code, but am not quite shure about that.
I guess the original idea of a mousejoint is to handle one input, cause you normally only have one mouse ...
can Box2D support multiple mouseJoints
-yes.

can you in your multi touch world, keep track of which touch is related to which mouse joint?
-probably, but I've never worked in multi-touch.

on the creation of a touch(like mouse-down) you would create a mouseJoint,
and on touch-move or on enter frame, you would update the mouseJoint position to follow the touch
when touch disappears(like mouse-up), you should remove its mouseJoint.
If you're using multiple mouse joints, you might run into stability issues if they're both attached to the same body. Might be better to use a good old fashioned Hooke's law spring force (with damping) instead, since it might be somewhat better behaved if the target positions are not possible to reach exactly.

Otherwise, you'll definitely need to play with the tuning factors on the mouse joint to make things stable, I don't think you could just cop and paste the ones from the testbed and get very good results.

Could be wrong, though...
@ewjordan is their a joint already made for Hookes Spring?

is it close to what boris did here?
http://personal.boristhebrave.com/project/controller-grab-pack/demo
(press Right twice to get to the spring test bed)
thank you for your answers so far.

today I will do the final testing at a multi touch table, if it's possible to use mouseJoints for that.

what would be a easy alternative for me ... I am really in timing troubles slowly ...

I just need something comparative to:


1. onMultitouch "add" (~mouseClick/hitTest ): does a new multitouch (add) hit a Box2D Body:
--> (via body.GetXForm () ) ???

2. onMultitouch "move" (~startDrag/mouseMove): move Box2D Body position like multitouch moves with all the physics of Box2D (Collision detecting, etc):
--> how would that work ?????

3. onMultitouch "remove"
(~stopDrag/mouseRelease): stop Box2D Body moving to the position of the multitouch moving and set it free to Box2D world again
sketchbookgames wrote:@ewjordan is their a joint already made for Hookes Spring?

is it close to what boris did here?
http://personal.boristhebrave.com/project/controller-grab-pack/demo
(press Right twice to get to the spring test bed)

Yup, exactly like Boris' demo - though in Box2d you can use the distance joint as a spring, too, if you play with the joint parameters. I think it should work fairly well, it's a little stiffer than you could achieve just by applying forces, which might be what you want.
I was just thinking about using multiple mouse joints to manipulate an object using two fingers with multitouch. It would allow for precise orientation control.

Has anybody implemented this to see if there are stability issues? I would hope that if the anchors are pulled apart or pushed together that those forces would cancel out. If not I think it would not be too difficult to programmatically ensure that they are kept the correct initial distance apart.

This would be very very cool to see, especially in a game running on a tablet.

Original thread: https://box2d.org/forum/viewtopic.php?t=3548