The small3d library
BoundingBoxSet.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <memory>
14 #include "Logger.hpp"
15 #include <vector>
16 #include "Math.hpp"
17 #include "Model.hpp"
18 
19 namespace small3d {
20 
28  private:
29 
30  uint32_t numBoxes = 0;
31  void triangulate();
32  void calcExtremes();
33  void generateBoxesFromExtremes();
34  void generateExtremes(const std::vector<float>& vertexData, const Vec3& scale, uint32_t subdivisions);
35  void generateSubExtremes(const std::vector<float>& vertexData, const Vec3& scale);
36 
37  public:
38 
42  struct extremes {
43 
44  float minZ = 0.0f, maxZ = 0.0f, minX = 0.0f, maxX = 0.0f, minY = 0.0f, maxY = 0.0f;
45  bool tagged = false;
46 
47  };
48 
52  std::vector<extremes> boxExtremes;
53 
58  int getNumBoxes() const;
59 
64 
76  BoundingBoxSet(const std::vector<float>& vertexData, const Vec3& scale, uint32_t subdivisions);
77 
81  ~BoundingBoxSet() = default;
82 
87  std::vector<std::vector<float> > vertices;
88 
93  std::vector<std::vector<unsigned int> > facesVertexIndexes;
94 
98  std::vector<std::vector<unsigned int> > facesVertexIndexesTriangulated;
99 
108  bool contains(const Vec3 point, const Vec3 thisOffset,
109  const Mat4 thisRotation) const;
110 
123  bool containsCorners(const BoundingBoxSet& otherBoxSet,
124  const Vec3 thisOffset,
125  const Mat4 thisRotation,
126  const Vec3 otherOffset,
127  const Mat4 otherRotation) const;
128 
133  std::vector<Model> getModels();
134 
135  };
136 }
Math.hpp
Vectors, matrices and other math things.
small3d::BoundingBoxSet::facesVertexIndexes
std::vector< std::vector< unsigned int > > facesVertexIndexes
Faces vertex indexes (rectangles)
Definition: BoundingBoxSet.hpp:93
Model.hpp
A 3D model class.
small3d::BoundingBoxSet::containsCorners
bool containsCorners(const BoundingBoxSet &otherBoxSet, const Vec3 thisOffset, const Mat4 thisRotation, const Vec3 otherOffset, const Mat4 otherRotation) const
Check any of the corners of another set of bounding boxes is inside any of the boxes of this set.
Definition: BoundingBoxSet.cpp:49
small3d::BoundingBoxSet::vertices
std::vector< std::vector< float > > vertices
Vertex coordinates.
Definition: BoundingBoxSet.hpp:87
small3d::BoundingBoxSet::contains
bool contains(const Vec3 point, const Vec3 thisOffset, const Mat4 thisRotation) const
Check if a point is inside any of the boxes.
Definition: BoundingBoxSet.cpp:27
small3d::BoundingBoxSet::boxExtremes
std::vector< extremes > boxExtremes
The extreme coordinates (max and min) of each box.
Definition: BoundingBoxSet.hpp:52
small3d::BoundingBoxSet::~BoundingBoxSet
~BoundingBoxSet()=default
Destructor.
small3d::BoundingBoxSet
Set of bounding boxes for a SceneObject, calculated based on the vertices of a Model.
Definition: BoundingBoxSet.hpp:27
small3d
Definition: BinaryFile.hpp:15
small3d::BoundingBoxSet::BoundingBoxSet
BoundingBoxSet()
Default constructor.
Definition: BoundingBoxSet.cpp:17
small3d::BoundingBoxSet::getNumBoxes
int getNumBoxes() const
Get the number of boxes contained in the set.
Definition: BoundingBoxSet.cpp:315
small3d::BoundingBoxSet::facesVertexIndexesTriangulated
std::vector< std::vector< unsigned int > > facesVertexIndexesTriangulated
Faces vertex indexes (triangles, for rendering)
Definition: BoundingBoxSet.hpp:98
small3d::Vec3
3 component float vector
Definition: Math.hpp:19
small3d::BoundingBoxSet::getModels
std::vector< Model > getModels()
Get the bounding boxes in a set of Models that can be rendered.
Definition: BoundingBoxSet.cpp:319
small3d::Mat4
4x4 float matrix
Definition: Math.hpp:99
Logger.hpp
Logger used in small3d.