b2_chain_polygon_contact.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // MIT License
  2. // Copyright (c) 2019 Erin Catto
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. #include "b2_chain_polygon_contact.h"
  19. #include "box2d/b2_block_allocator.h"
  20. #include "box2d/b2_fixture.h"
  21. #include "box2d/b2_chain_shape.h"
  22. #include "box2d/b2_edge_shape.h"
  23. #include <new>
  24. b2Contact* b2ChainAndPolygonContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)
  25. {
  26. void* mem = allocator->Allocate(sizeof(b2ChainAndPolygonContact));
  27. return new (mem) b2ChainAndPolygonContact(fixtureA, indexA, fixtureB, indexB);
  28. }
  29. void b2ChainAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)
  30. {
  31. ((b2ChainAndPolygonContact*)contact)->~b2ChainAndPolygonContact();
  32. allocator->Free(contact, sizeof(b2ChainAndPolygonContact));
  33. }
  34. b2ChainAndPolygonContact::b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB)
  35. : b2Contact(fixtureA, indexA, fixtureB, indexB)
  36. {
  37. b2Assert(m_fixtureA->GetType() == b2Shape::e_chain);
  38. b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon);
  39. }
  40. void b2ChainAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)
  41. {
  42. b2ChainShape* chain = (b2ChainShape*)m_fixtureA->GetShape();
  43. b2EdgeShape edge;
  44. chain->GetChildEdge(&edge, m_indexA);
  45. b2CollideEdgeAndPolygon( manifold, &edge, xfA,
  46. (b2PolygonShape*)m_fixtureB->GetShape(), xfB);
  47. }