Hello and good morning @ all
I'm using the b2MouseJoint to pick objects in my game. Dragging works fine
but when i lift the object at the corner, it rotates in the opposite direction
it should.

I compared my code with the code of the example and can't find any
differences (exept mouse-world-conversion)
The conversion mouse-to-worldspace should be correct (the line starts at the mouse).
Seems the anchor is at the wrong place in the body.
Where's my mistake ❓
thank you in advance
ps. yes, my english is bad
I'm using the b2MouseJoint to pick objects in my game. Dragging works fine
but when i lift the object at the corner, it rotates in the opposite direction
it should.

I compared my code with the code of the example and can't find any
differences (exept mouse-world-conversion)
Code:
// global:
b2MouseJoint *joint;
// mousedown:
if (joint)
{
world->GetWorld()->DestroyJoint(joint);
joint = 0;
}
Vector3 pnear;
POINT point;
point.x = LOWORD(p->lParam); // get mousepos
point.y = HIWORD(p->lParam);
pnear.x = point.x / (float)pdev->GetWidth() * 100.f; // calculate position in world space
pnear.y = (float)(pdev->GetHeight() - point.y) / (float)pdev->GetWidth() * 100.f;
RigidBody *b = world->Raycast(Vector2(pnear.x, pnear.y)); // "Raycast" performs an AABB Query
if (b) // if we found a body
{
b2MouseJointDef def;
def.body1 = world->GetWorld()->GetGroundBody();
def.body2 = b->GetRigidBody();
def.maxForce = 5.f * b->GetRigidBody()->GetMass();
def.target = VectorExchange(Vector2(pnear.x, pnear.y)); // VectorExchange converts to a b2Vec2
joint = static_cast<b2MouseJoint *>(world->GetWorld()->CreateJoint(&def));
b->GetRigidBody()->WakeUp();
}
// mouseup:
if (joint)
{
world->GetWorld()->DestroyJoint(joint);
joint = 0;
}
// mousemove:
if (joint)
{
Vector3 pnear;
POINT point;
point.x = LOWORD(p->lParam);
point.y = HIWORD(p->lParam);
pnear.x = point.x / (float)pdev->GetWidth() * 100.f; // same conversion
pnear.y = (float)(pdev->GetHeight() - point.y) / (float)pdev->GetWidth() * 100.f;
joint->SetTarget(VectorExchange(Vector2(pnear.x, pnear.y)));
}
b2MouseJoint *joint;
// mousedown:
if (joint)
{
world->GetWorld()->DestroyJoint(joint);
joint = 0;
}
Vector3 pnear;
POINT point;
point.x = LOWORD(p->lParam); // get mousepos
point.y = HIWORD(p->lParam);
pnear.x = point.x / (float)pdev->GetWidth() * 100.f; // calculate position in world space
pnear.y = (float)(pdev->GetHeight() - point.y) / (float)pdev->GetWidth() * 100.f;
RigidBody *b = world->Raycast(Vector2(pnear.x, pnear.y)); // "Raycast" performs an AABB Query
if (b) // if we found a body
{
b2MouseJointDef def;
def.body1 = world->GetWorld()->GetGroundBody();
def.body2 = b->GetRigidBody();
def.maxForce = 5.f * b->GetRigidBody()->GetMass();
def.target = VectorExchange(Vector2(pnear.x, pnear.y)); // VectorExchange converts to a b2Vec2
joint = static_cast<b2MouseJoint *>(world->GetWorld()->CreateJoint(&def));
b->GetRigidBody()->WakeUp();
}
// mouseup:
if (joint)
{
world->GetWorld()->DestroyJoint(joint);
joint = 0;
}
// mousemove:
if (joint)
{
Vector3 pnear;
POINT point;
point.x = LOWORD(p->lParam);
point.y = HIWORD(p->lParam);
pnear.x = point.x / (float)pdev->GetWidth() * 100.f; // same conversion
pnear.y = (float)(pdev->GetHeight() - point.y) / (float)pdev->GetWidth() * 100.f;
joint->SetTarget(VectorExchange(Vector2(pnear.x, pnear.y)));
}
The conversion mouse-to-worldspace should be correct (the line starts at the mouse).
Seems the anchor is at the wrong place in the body.
Where's my mistake ❓
thank you in advance
ps. yes, my english is bad