Octree.pkg 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $#include "Octree.h"
  2. /// %Octree component. Should be added only to the root scene node
  3. class Octree : public Component
  4. {
  5. public:
  6. /// Resize octree. If octree is not empty, drawable objects will be temporarily moved to the root.
  7. void Resize(const BoundingBox& box, unsigned numLevels);
  8. /// Update and reinsert drawable objects.
  9. void Update(const FrameInfo& frame);
  10. /// Add a drawable manually.
  11. void AddManualDrawable(Drawable* drawable);
  12. /// Remove a manually added drawable.
  13. void RemoveManualDrawable(Drawable* drawable);
  14. /// Return drawable objects by a query.
  15. void GetDrawables(OctreeQuery& query) const;
  16. /// Return drawable objects by a ray query.
  17. void Raycast(RayOctreeQuery& query) const;
  18. /// Return the closest drawable object by a ray query.
  19. // void RaycastSingle(RayOctreeQuery& query) const;
  20. tolua_outside RayQueryResult OctreeRaycastSingle @ RaycastSingle(const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags);
  21. /// Return subdivision levels.
  22. unsigned GetNumLevels() const { return numLevels_; }
  23. /// Mark drawable object as requiring an update.
  24. void QueueUpdate(Drawable* drawable);
  25. /// Mark drawable object as requiring a reinsertion. Is thread-safe.
  26. void QueueReinsertion(Drawable* drawable);
  27. /// Visualize the component as debug geometry.
  28. void DrawDebugGeometry(bool depthTest);
  29. };
  30. ${
  31. static RayQueryResult OctreeRaycastSingle(Octree* octree, const Ray& ray, RayQueryLevel level, float maxDistance, unsigned char drawableFlags)
  32. {
  33. PODVector<RayQueryResult> result;
  34. RayOctreeQuery query(result, ray, level, maxDistance, drawableFlags);
  35. octree->RaycastSingle(query);
  36. if (!query.result_.Empty())
  37. return query.result_[0];
  38. else
  39. {
  40. RayQueryResult empty;
  41. empty.drawable_ = 0;
  42. empty.node_ = 0;
  43. empty.distance_ = M_INFINITY;
  44. empty.subObject_ = 0;
  45. return empty;
  46. }
  47. }
  48. $}