SpriteBatchQuery.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SPRITE_BATCH_QUERY_H_
  23. #define _SPRITE_BATCH_QUERY_H_
  24. #ifndef _SPRITE_BATCH_QUERY_RESULT_H_
  25. #include "2d/core/SpriteBatchQueryResult.h"
  26. #endif
  27. ///-----------------------------------------------------------------------------
  28. class SpriteBatch;
  29. class SpriteBatchItem;
  30. ///-----------------------------------------------------------------------------
  31. class SpriteBatchQuery :
  32. protected b2DynamicTree,
  33. public b2QueryCallback,
  34. public b2RayCastCallback
  35. {
  36. public:
  37. SpriteBatchQuery( SpriteBatch* pSpriteBatch );
  38. virtual ~SpriteBatchQuery() {}
  39. /// Standard scope.
  40. S32 add( SpriteBatchItem* pSpriteBatchItem );
  41. void remove( SpriteBatchItem* pSpriteBatchItem );
  42. bool update( SpriteBatchItem* pSpriteBatchItem, const b2AABB& aabb, const b2Vec2& displacement );
  43. //// Spatial queries.
  44. U32 queryArea( const b2AABB& aabb, const bool targetOOBB );
  45. U32 queryOOBB( const b2AABB& aabb, b2PolygonShape& oobb, const bool targetOOBB );
  46. U32 queryRay( const Vector2& point1, const Vector2& point2, const bool targetOOBB );
  47. U32 queryPoint( const Vector2& point, const bool targetOOBB );
  48. /// Results.
  49. void clearQuery( void );
  50. typeSpriteBatchQueryResultVector& getQueryResults( void ) { return mQueryResults; }
  51. inline U32 getQueryResultsCount( void ) const { return mQueryResults.size(); }
  52. inline bool getIsRaycastQueryResult( void ) const { return mIsRaycastQueryResult; }
  53. void sortRaycastQueryResult( void );
  54. /// Unused result callbacks.
  55. virtual bool ReportFixture( b2Fixture* fixture ) { return true; }
  56. virtual F32 ReportFixture( b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, F32 fraction ) { return 1.0; }
  57. /// Callbacks.
  58. bool QueryCallback( S32 proxyId );
  59. F32 RayCastCallback( const b2RayCastInput& input, S32 proxyId );
  60. private:
  61. static S32 QSORT_CALLBACK rayCastFractionSort(const void* a, const void* b);
  62. private:
  63. SpriteBatch* mpSpriteBatch;
  64. b2PolygonShape mComparePolygonShape;
  65. b2RayCastInput mCompareRay;
  66. b2Vec2 mComparePoint;
  67. b2Transform mCompareTransform;
  68. bool mCheckOOBB;
  69. bool mCheckPoint;
  70. typeSpriteBatchQueryResultVector mQueryResults;
  71. bool mIsRaycastQueryResult;
  72. typeSceneObjectVector mAlwaysInScopeSet;
  73. U32 mMasterQueryKey;
  74. };
  75. #endif // _SPRITE_BATCH_QUERY_H_