Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. ///
  2. ///Header
  3. ///
  4. #include "Box2D\Box2D.h"
  5. class RayCastListener: public b2RayCastCallback
  6. {
  7. protected:
  8.     bool intersectedObject;
  9. public:
  10.     bool ObjectIntersected();
  11.     RayCastListener();
  12.     ~RayCastListener(void);
  13.     float32 ReportFixture(b2Fixture* fixture, const b2Vec2& point,const b2Vec2& normal, float32 fraction);
  14. };
  15. ///
  16. ///Source
  17. ///
  18. #include "RayCastListener.h"
  19.  
  20. RayCastListener::RayCastListener():intersectedObject(false){}
  21.  
  22. RayCastListener::~RayCastListener(void){}
  23.  
  24. float32 RayCastListener::ReportFixture(b2Fixture* fixture, const b2Vec2& point,const b2Vec2& normal, float32 fraction){
  25.     intersectedObject = true;
  26.     return 0.0f;
  27. }
  28.  
  29. bool RayCastListener::ObjectIntersected(){
  30.     return intersectedObject;
  31. }
  32.  
  33. ///
  34. ///To Use
  35. ///
  36. RayCasListener *rayCastListener = new RayCastListener(mWorld)
  37. mWorld->RayCast(rayCastListener,startPoint,endPoint);
  38. if(rayCastListener->ObjectIntersected()){
  39.     //hit something
  40. }
  41. delete rayCastListener;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement