Guest User

Untitled

a guest
Feb 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "Box2D.h"
  2. #import <vector>
  3. #import <algorithm>
  4.  
  5. struct MyContact
  6. {
  7.     b2Fixture *fixtureA;
  8.     b2Fixture *fixtureB;
  9.     bool operator==(const MyContact& other) const
  10.     {
  11.         return (fixtureA == other.fixtureA) && (fixtureB == other.fixtureB);
  12.     }
  13. };
  14.  
  15.  
  16.  
  17. class MyContactListener : public b2ContactListener
  18. {
  19.    
  20. public:
  21.     std::vector<MyContact>_contacts;
  22.    
  23.     MyContactListener();
  24.     ~MyContactListener();
  25.    
  26.     virtual void BeginContact(b2Contact* contact);
  27.     virtual void EndContact(b2Contact* contact);
  28.     virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
  29.     virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
  30.    
  31. };
  32.  
  33.  
  34. ///////////////////////////////
  35.  
  36.  
  37.  
  38.  
  39. #import "MyContactListener.h"
  40.  
  41. MyContactListener::MyContactListener() : _contacts()
  42. {
  43.    
  44. }
  45.  
  46. MyContactListener::~MyContactListener()
  47. {
  48.    
  49. }
  50.  
  51. void MyContactListener::BeginContact(b2Contact* contact)
  52. {
  53.     // We need to copy out the data because the b2Contact passed in
  54.     // is reused.
  55.     MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
  56.     _contacts.push_back(myContact);
  57.    
  58. }
  59.  
  60. void MYContactListener::EndContact(b2Contact* contact)
  61. {
  62.     MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
  63.    
  64.    
  65.    
  66.     std::vector<MyContact>::iterator pos;
  67.     pos = std::find(_contacts.begin(), _contacts.end(), myContact);
  68.    
  69.     if (pos != _contacts.end())
  70.     {
  71.         _contacts.erase(pos);
  72.     }
  73. }
  74.  
  75. void MyContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
  76. {
  77.    
  78. }
  79.  
  80. void MyContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
  81. {
  82.    
  83. }
Add Comment
Please, Sign In to add comment