babylon_boundingbox.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "stdafx.h"
  2. #include "BabylonVertex.h"
  3. #include <numeric>
  4. #include <algorithm>
  5. #include "BabylonCamera.h"
  6. babylon_boundingbox::babylon_boundingbox()
  7. : _minX(std::numeric_limits<float>::max()),
  8. _minY(std::numeric_limits<float>::max()),
  9. _minZ(std::numeric_limits<float>::max()),
  10. _maxX(std::numeric_limits<float>::min()),
  11. _maxY(std::numeric_limits<float>::min()),
  12. _maxZ(std::numeric_limits<float>::min())
  13. {
  14. }
  15. babylon_boundingbox::babylon_boundingbox(FbxScene* scene){
  16. FbxVector4 vmin, vmax, vcenter;
  17. scene->ComputeBoundingBoxMinMaxCenter(vmin, vmax, vcenter);
  18. _minX = static_cast<float>(vmin[0]);
  19. _minY = static_cast<float>(vmin[1]);
  20. _minZ = static_cast<float>(vmin[2]);
  21. _maxX = static_cast<float>(vmax[0]);
  22. _maxY = static_cast<float>(vmax[1]);
  23. _maxZ = static_cast<float>(vmax[2]);
  24. }
  25. void babylon_boundingbox::addPosition(float x, float y, float z){
  26. _minX = std::min(x, _minX);
  27. _minY = std::min(y, _minY);
  28. _minZ = std::min(z, _minZ);
  29. _maxX = std::max(x, _maxX);
  30. _maxY = std::max(y, _maxY);
  31. _maxZ = std::max(z, _maxZ);
  32. }
  33. babylon_boundingbox::~babylon_boundingbox()
  34. {
  35. }
  36. babylon_boundingbox mergeBoundingBoxes(const std::vector<babylon_boundingbox>& boxes){
  37. babylon_boundingbox result;
  38. for (const auto& b : boxes){
  39. result.addPosition(b.getMin());
  40. result.addPosition(b.getMax());
  41. }
  42. return result;
  43. }