Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. // TODO 1: If mouse button 1 is pressed ...
  2. if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_DOWN)
  3. {
  4. // test if the current body contains mouse position
  5. bool hit;
  6. b2Transform transform = b->GetTransform();
  7. b2Shape* shape = f->GetShape();
  8. hit = shape->TestPoint(transform, point);
  9.  
  10.  
  11. if (hit == true)
  12. {
  13. b2MouseJointDef def;
  14. def.bodyA = ground;
  15. def.bodyB = b;
  16. def.target = point;
  17. def.dampingRatio = 0.5f;
  18. def.frequencyHz = 2.0f;
  19. def.maxForce = 100.0f * b->GetMass();
  20. mouse_joint = (b2MouseJoint*)world->CreateJoint(&def);
  21. }
  22. }
  23.  
  24. if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_REPEAT && mouse_joint)
  25. {
  26. mouse_joint->SetTarget(point);
  27. 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);
  28. }
  29. if (App->input->GetMouseButton(SDL_BUTTON_LEFT) == KEY_UP && mouse_joint)
  30. {
  31. world->DestroyJoint(mouse_joint);
  32. mouse_joint = nullptr;
  33. }
  34. }
  35. }
  36.  
  37. return UPDATE_CONTINUE;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement