sceneQueryUtil.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _SCENEQUERY_UTIL_H_
  2. #define _SCENEQUERY_UTIL_H_
  3. /// A contextual hint passed to the polylist methods which
  4. /// allows it to return the appropriate geometry.
  5. enum PolyListContext
  6. {
  7. /// A hint that the polyist is intended
  8. /// for collision testing.
  9. PLC_Collision,
  10. /// A hint that the polyist is for decal
  11. /// geometry generation.
  12. PLC_Decal,
  13. /// A hint that the polyist is used for
  14. /// selection from an editor or other tool.
  15. PLC_Selection,
  16. /// A hint that the polylist is used for
  17. /// building a representation of the environment
  18. /// used for navigation.
  19. PLC_Navigation,
  20. /// A hint that the polyist will be used
  21. /// to export geometry and would like to have
  22. /// texture coords and materials.
  23. PLC_Export
  24. };
  25. struct SceneBinRange
  26. {
  27. U16 minCoord[2];
  28. U16 maxCoord[2];
  29. inline U32 getWidth() const
  30. {
  31. return maxCoord[0] - minCoord[0];
  32. }
  33. inline U32 getHeight() const
  34. {
  35. return maxCoord[1] - minCoord[1];
  36. }
  37. inline void setGlobal()
  38. {
  39. minCoord[0] = 0;
  40. minCoord[1] = 0;
  41. maxCoord[0] = 0xFFFF;
  42. maxCoord[1] = 0xFFFF;
  43. }
  44. static SceneBinRange makeFromBin(U32 minX, U32 maxX, U32 minY, U32 maxY)
  45. {
  46. SceneBinRange outRange;
  47. outRange.minCoord[0] = minX;
  48. outRange.minCoord[1] = minY;
  49. outRange.maxCoord[0] = maxX;
  50. outRange.maxCoord[1] = maxY;
  51. return outRange;
  52. }
  53. static SceneBinRange makeGlobal()
  54. {
  55. SceneBinRange outRange;
  56. outRange.setGlobal();
  57. return outRange;
  58. }
  59. inline bool isGlobal() const
  60. {
  61. return minCoord[0] == 0 &&
  62. minCoord[1] == 0 &&
  63. maxCoord[0] == 0xFFFF &&
  64. maxCoord[1] == 0xFFFF;
  65. }
  66. inline bool shouldOverflow() const;
  67. inline bool operator==(const SceneBinRange& other) const
  68. {
  69. return memcmp(minCoord, other.minCoord, sizeof(minCoord)) == 0 &&
  70. memcmp(maxCoord, other.maxCoord, sizeof(maxCoord)) == 0;
  71. }
  72. inline bool operator!=(const SceneBinRange& other) const
  73. {
  74. return !(*this == other);
  75. }
  76. };
  77. /// Lookup for bins assigned to SceneObject
  78. struct SceneBinListLookup
  79. {
  80. SceneBinRange mRange; ///< Range object is placed in
  81. U32 mListHandle; ///< Handle for ref list
  82. };
  83. /// For simple queries. Simply creates a vector of the objects
  84. class SimpleQueryList
  85. {
  86. public:
  87. Vector< SceneObject* > mList;
  88. SimpleQueryList()
  89. {
  90. VECTOR_SET_ASSOCIATION(mList);
  91. }
  92. void insertObject(SceneObject* obj) { mList.push_back(obj); }
  93. static void insertionCallback(SceneObject* obj, void* key)
  94. {
  95. SimpleQueryList* pList = reinterpret_cast<SimpleQueryList*>(key);
  96. pList->insertObject(obj);
  97. }
  98. };
  99. #endif