The small3d library
Tiny C++ 3D game development library for Win/MacOS/Linux/FreeBSD
Loading...
Searching...
No Matches
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
19namespace 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}
Logger used in small3d.
Vectors, matrices and other math things.
A 3D model class.
Set of bounding boxes for a SceneObject, calculated based on the vertices of a Model.
Definition BoundingBoxSet.hpp:27
int getNumBoxes() const
Get the number of boxes contained in the set.
Definition BoundingBoxSet.cpp:321
std::vector< std::vector< unsigned int > > facesVertexIndexes
Faces vertex indexes (rectangles)
Definition BoundingBoxSet.hpp:93
std::vector< std::vector< unsigned int > > facesVertexIndexesTriangulated
Faces vertex indexes (triangles, for rendering)
Definition BoundingBoxSet.hpp:98
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
~BoundingBoxSet()=default
Destructor.
std::vector< extremes > boxExtremes
The extreme coordinates (max and min) of each box.
Definition BoundingBoxSet.hpp:52
std::vector< Model > getModels()
Get the bounding boxes in a set of Models that can be rendered.
Definition BoundingBoxSet.cpp:325
BoundingBoxSet()
Default constructor.
Definition BoundingBoxSet.cpp:17
std::vector< std::vector< float > > vertices
Vertex coordinates.
Definition BoundingBoxSet.hpp:87
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
Definition BinaryFile.hpp:15
Structure to hold the coordinates of the extremes of each box.
Definition BoundingBoxSet.hpp:42
4x4 float matrix
Definition Math.hpp:112
3 component float vector
Definition Math.hpp:21