Octree.pkg 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. $#include "Octree.h"
  2. class Octree : public Component
  3. {
  4. void SetSize(const BoundingBox& box, unsigned numLevels);
  5. void Update(const FrameInfo& frame);
  6. void AddManualDrawable(Drawable* drawable);
  7. void RemoveManualDrawable(Drawable* drawable);
  8. // void GetDrawables(OctreeQuery& query) const;
  9. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesPoint @ GetDrawables(const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  10. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesBoundingBox @ GetDrawables(const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  11. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesFrustum @ GetDrawables(const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  12. tolua_outside const PODVector<OctreeQueryResult>& OctreeGetDrawablesSphere @ GetDrawables(const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK) const;
  13. // void Raycast(RayOctreeQuery& query) const;
  14. tolua_outside const PODVector<RayQueryResult>& OctreeRaycast @ Raycast(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK) const;
  15. // void RaycastSingle(RayOctreeQuery& query) const;
  16. tolua_outside RayQueryResult OctreeRaycastSingle @ RaycastSingle(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK) const;
  17. unsigned GetNumLevels() const;
  18. void QueueUpdate(Drawable* drawable);
  19. void DrawDebugGeometry(bool depthTest);
  20. tolua_readonly tolua_property__get_set unsigned numLevels;
  21. };
  22. ${
  23. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesPoint(const Octree* octree, const Vector3& point, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  24. {
  25. PODVector<Drawable*> drawableResult;
  26. PointOctreeQuery query(drawableResult, point, drawableFlags, viewMask);
  27. octree->GetDrawables(query);
  28. static PODVector<OctreeQueryResult> result;
  29. result.Resize(drawableResult.Size());
  30. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  31. {
  32. result[i].drawable_ = drawableResult[i];
  33. result[i].node_ = drawableResult[i]->GetNode();
  34. }
  35. return result;
  36. }
  37. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesBoundingBox(const Octree* octree, const BoundingBox& box, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  38. {
  39. PODVector<Drawable*> drawableResult;
  40. BoxOctreeQuery query(drawableResult, box, drawableFlags, viewMask);
  41. octree->GetDrawables(query);
  42. static PODVector<OctreeQueryResult> result;
  43. result.Resize(drawableResult.Size());
  44. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  45. {
  46. result[i].drawable_ = drawableResult[i];
  47. result[i].node_ = drawableResult[i]->GetNode();
  48. }
  49. return result;
  50. }
  51. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesFrustum(const Octree* octree, const Frustum& frustum, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  52. {
  53. PODVector<Drawable*> drawableResult;
  54. FrustumOctreeQuery query(drawableResult, frustum, drawableFlags, viewMask);
  55. octree->GetDrawables(query);
  56. static PODVector<OctreeQueryResult> result;
  57. result.Resize(drawableResult.Size());
  58. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  59. {
  60. result[i].drawable_ = drawableResult[i];
  61. result[i].node_ = drawableResult[i]->GetNode();
  62. }
  63. return result;
  64. }
  65. static const PODVector<OctreeQueryResult>& OctreeGetDrawablesSphere(const Octree* octree, const Sphere& sphere, unsigned char drawableFlags = DRAWABLE_ANY, unsigned viewMask = DEFAULT_VIEWMASK)
  66. {
  67. PODVector<Drawable*> drawableResult;
  68. SphereOctreeQuery query(drawableResult, sphere, drawableFlags, viewMask);
  69. octree->GetDrawables(query);
  70. static PODVector<OctreeQueryResult> result;
  71. result.Resize(drawableResult.Size());
  72. for (unsigned i = 0; i < drawableResult.Size(); ++i)
  73. {
  74. result[i].drawable_ = drawableResult[i];
  75. result[i].node_ = drawableResult[i]->GetNode();
  76. }
  77. return result;
  78. }
  79. static RayQueryResult OctreeRaycastSingle(const Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK)
  80. {
  81. PODVector<RayQueryResult> result;
  82. RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags, viewMask);
  83. octree->RaycastSingle(query);
  84. if (!query.result_.Empty())
  85. return query.result_[0];
  86. else
  87. {
  88. RayQueryResult empty;
  89. empty.position_ = Vector3::ZERO;
  90. empty.normal_ = Vector3::ZERO;
  91. empty.distance_ = M_INFINITY;
  92. empty.subObject_ = 0;
  93. return empty;
  94. }
  95. }
  96. static const PODVector<RayQueryResult>& OctreeRaycast(const Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags, unsigned viewMask = DEFAULT_VIEWMASK)
  97. {
  98. static PODVector<RayQueryResult> result;
  99. result.Clear();
  100. RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags, viewMask);
  101. octree->Raycast(query);
  102. return result;
  103. }
  104. $}