2
0

PhysWorld.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include <vector>
  10. #include <functional>
  11. #include "Math.h"
  12. #include "Collision.h"
  13. class PhysWorld
  14. {
  15. public:
  16. PhysWorld(class Game* game);
  17. // Used to give helpful information about collision results
  18. struct CollisionInfo
  19. {
  20. // Point of collision
  21. Vector3 mPoint;
  22. // Normal at collision
  23. Vector3 mNormal;
  24. // Component collided with
  25. class BoxComponent* mBox;
  26. // Owning actor of component
  27. class Actor* mActor;
  28. };
  29. // Test a line segment against boxes
  30. // Returns true if it collides against a box
  31. bool SegmentCast(const LineSegment& l, CollisionInfo& outColl);
  32. // Tests collisions using naive pairwise
  33. void TestPairwise(std::function<void(class Actor*, class Actor*)> f);
  34. // Test collisions using sweep and prune
  35. void TestSweepAndPrune(std::function<void(class Actor*, class Actor*)> f);
  36. // Add/remove box components from world
  37. void AddBox(class BoxComponent* box);
  38. void RemoveBox(class BoxComponent* box);
  39. private:
  40. class Game* mGame;
  41. std::vector<class BoxComponent*> mBoxes;
  42. };