Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TODO 1: If mouse button 1 is pressed ...
- if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_DOWN)
- {
- // test if the current body contains mouse position
- bool hit;
- b2Transform transform = b->GetTransform();
- b2Shape* shape = f->GetShape();
- hit = shape->TestPoint(transform, point);
- if (hit == true)
- {
- b2MouseJointDef def;
- def.bodyA = ground;
- def.bodyB = b;
- def.target = point;
- def.dampingRatio = 0.5f;
- def.frequencyHz = 2.0f;
- def.maxForce = 100.0f * b->GetMass();
- mouse_joint = (b2MouseJoint*)world->CreateJoint(&def);
- }
- }
- if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_REPEAT && mouse_joint)
- {
- mouse_joint->SetTarget(point);
- App->renderer->DrawLine(METERS_TO_PIXELS(point.x), METERS_TO_PIXELS(point.y), METERS_TO_PIXELS(mouse_joint->GetAnchorB().x), METERS_TO_PIXELS(mouse_joint->GetAnchorB().y), 255, 255, 255);
- }
- if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_UP && mouse_joint)
- {
- world->DestroyJoint(mouse_joint);
- mouse_joint = nullptr;
- }
- }
- }
- return UPDATE_CONTINUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement