1 #ifndef PROCEDURAL_VOXEL_EDIT_BOX_HPP
2 #define PROCEDURAL_VOXEL_EDIT_BOX_HPP
4 #include "blub/math/axisAlignedBox.hpp"
5 #include "blub/math/quaternion.hpp"
6 #include "blub/math/plane.hpp"
7 #include "blub/math/ray.hpp"
8 #include "blub/procedural/voxel/edit/base.hpp"
10 #include "blub/core/sharedPointer.hpp"
11 #include "blub/math/intersection.hpp"
12 #include "blub/math/ray.hpp"
13 #include "blub/math/transform.hpp"
14 #include "blub/procedural/voxel/tile/container.hpp"
30 template <
class voxelType>
31 class box :
public base<voxelType>
34 typedef base<voxelType> t_base;
35 typedef sharedPointer<box<voxelType> > pointer;
45 return pointer(
new box(size, rotation));
55 m_aabb.
getMaximum()*trans.scale + trans.position);
66 , m_rotation(rotation.getNormalised())
67 , m_aabb(-size.length(), size.length())
82 m_planes[2] =
blub::plane(rotatedRight, normalRight);
83 m_planes[3] =
blub::plane(-rotatedRight, -normalRight);
88 m_planes[4] =
blub::plane(rotatedFront, normalFront);
89 m_planes[5] =
blub::plane(-rotatedFront, -normalFront);
103 const vector3int32 posContainerAbsolut(voxelContainerOffset*t_base::t_voxelContainerTile::voxelLength);
105 vector3int32 toLoop[] = {{1, t_base::t_voxelContainerTile::voxelLength, t_base::t_voxelContainerTile::voxelLength},
106 {t_base::t_voxelContainerTile::voxelLength, 1, t_base::t_voxelContainerTile::voxelLength},
107 {t_base::t_voxelContainerTile::voxelLength, t_base::t_voxelContainerTile::voxelLength, 1}
109 vector3 rayDir[] = {{1., 0., 0.},
112 for (int32 indAxis = 0; indAxis < 3; ++indAxis)
114 for (int32 indX = 0; indX < toLoop[indAxis].x; ++indX)
116 for (int32 indY = 0; indY < toLoop[indAxis].y; ++indY)
118 for (int32 indZ = 0; indZ < toLoop[indAxis].z; ++indZ)
121 vector3 posAbsolut(posContainerAbsolut + posVoxel);
123 posAbsolut -= trans.position;
124 posAbsolut /= trans.scale;
126 const ray test(posAbsolut, rayDir[indAxis]);
131 blub::uint16 numCutPointsFound(0);
133 for (blub::int32 indPlane = 0; indPlane < 6; ++indPlane)
135 if (test.intersects(m_planes[indPlane], &cutPoint))
137 bool pointOnBoxSurface(
true);
138 for (blub::int32 indPlane2 = 0; indPlane2 < 6; ++indPlane2)
140 if (indPlane2 == indPlane)
144 if (m_planes[indPlane2].getDistance(cutPoint) > 0.0)
146 pointOnBoxSurface =
false;
150 if (!pointOnBoxSurface)
154 cutPoints[numCutPointsFound] = (cutPoint[indAxis]*trans.scale[indAxis] + trans.position[indAxis]) - static_cast<real>(posContainerAbsolut[indAxis]);
155 cutPlanes[numCutPointsFound] = m_planes[indPlane];
157 if (numCutPointsFound > 2)
159 numCutPointsFound = 0;
164 if(numCutPointsFound == 0)
168 if(numCutPointsFound != 2)
173 real cutPointsSorted[2];
175 cutPointsSorted[0] = math::min<real>(cutPoints[0], cutPoints[1]);
176 cutPointsSorted[1] = math::max<real>(cutPoints[0], cutPoints[1]);
177 if (cutPointsSorted[0] != cutPoints[0])
179 std::swap(cutPlanes[0], cutPlanes[1]);
181 const real length(cutPointsSorted[1]-cutPointsSorted[0]);
189 t_base::createLine(voxelContainer, posVoxel, cutPointsSorted[0], length, t_base::axis::x, cutPlanes[0], cutPlanes[1]);
192 t_base::createLine(voxelContainer, posVoxel, cutPointsSorted[0], length, t_base::axis::y, cutPlanes[0], cutPlanes[1]);
195 t_base::createLine(voxelContainer, posVoxel, cutPointsSorted[0], length, t_base::axis::z, cutPlanes[0], cutPlanes[1]);
224 #endif // PROCEDURAL_VOXEL_EDIT_BOX_HPP
virtual void createLine(t_voxelContainerTile *voxelContainer, const vector3int32 &posVoxel, const real &from, const real &len, const axis &ax, const blub::plane &planeA, const blub::plane &planeB) const
createLine creates a voxel-line on one axis with a specific length
Definition: base.hpp:198
Definition: quaternion.hpp:25
void calculateVoxel(typename t_base::t_voxelContainerTile *voxelContainer, const vector3int32 &voxelContainerOffset, const transform &trans) const override
calculateVoxel cuts the box in voxelLines. Only sets values if voxel is inside box.
Definition: box.hpp:101
box(const vector3 &size, const quaternion &rotation)
constructor. Sets up the cutPlanes of the box
Definition: box.hpp:64
blub::axisAlignedBox getAxisAlignedBoundingBox(const transform &trans) const override
getAxisAlignedBoundingBox returns the scaled, transformed bounding box of the to calculate voxels ...
Definition: box.hpp:52
Definition: vector3.hpp:26
Definition: axisAlignedBox.hpp:20
const vector3 & getMinimum(void) const
Definition: axisAlignedBox.hpp:126
const vector3 & getMaximum(void) const
Definition: axisAlignedBox.hpp:141
static pointer create(const vector3 &size, const quaternion &rotation)
create creates an instance of box.
Definition: box.hpp:43
vector3 getNormalise() const
Definition: vector3.hpp:611
Definition: deadlineTimer.hpp:10