voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
sphere.hpp
1 #ifndef BLUB_PROCEDURAL_VOXEL_EDIT_SPHERE_HPP
2 #define BLUB_PROCEDURAL_VOXEL_EDIT_SPHERE_HPP
3 
4 
5 // #include "blub/log/global.hpp"
6 #include "blub/math/axisAlignedBox.hpp"
7 #include "blub/math/math.hpp"
8 #include "blub/math/sphere.hpp"
9 #include "blub/math/transform.hpp"
10 #include "blub/procedural/voxel/edit/base.hpp"
11 
12 
13 namespace blub
14 {
15 namespace procedural
16 {
17 namespace voxel
18 {
19 namespace edit
20 {
21 
22 
26 template <class configType>
27 class sphere : public base<configType>
28 {
29 public:
30  typedef configType t_config;
31  typedef base<t_config> t_base;
32  typedef sharedPointer<sphere<t_config> > pointer;
33  typedef typename t_config::t_data t_voxel;
34 
40  static pointer create(const ::blub::sphere& desc)
41  {
42  return pointer(new sphere(desc));
43  }
44 
49  void setSphere(const ::blub::sphere& desc)
50  {
51  m_sphere = desc;
52  }
57  const ::blub::sphere& getSphere() const
58  {
59  return m_sphere;
60  }
61 
68  {
69  const blub::axisAlignedBox aabb(m_sphere.getCenter() - blub::vector3(m_sphere.getRadius()),
70  m_sphere.getCenter() + blub::vector3(m_sphere.getRadius()));
71  return blub::axisAlignedBox(aabb.getMinimum()*trans.scale + trans.position,
72  aabb.getMaximum()*trans.scale + trans.position);
73  }
74 
75 protected:
82  bool calculateOneVoxel(const vector3& pos, t_voxel* resultVoxel) const override
83  {
84  const blub::real &squaredDist(pos.squaredDistance(m_sphere.getCenter()));
85  const blub::real &radius(m_sphere.getRadius());
86  if (squaredDist < (radius+1.)*(radius+1.))
87  {
88  if (squaredDist < (radius-1.)*(radius-1.))
89  {
90  resultVoxel->setInterpolationMax();
91  }
92  else
93  {
94  const blub::real &result(blub::math::clamp<blub::real>((radius-blub::math::sqrt(squaredDist))*127., -127., 127.));
95  resultVoxel->setInterpolation(static_cast<blub::int8>(result));
96  }
97  return true;
98  }
99  return false;
100  }
101 
102  sphere(const ::blub::sphere& desc)
103  : m_sphere(desc)
104  {
105  }
106 
107 protected:
108  ::blub::sphere m_sphere;
109 
110 };
111 
112 
113 }
114 }
115 }
116 }
117 
118 
119 #endif // VOXEL_EDIT_SPHERE_HPP
real getRadius(void) const
Definition: sphere.hpp:23
Definition: customVertexInformation.cpp:193
void setInterpolationMax()
setInterpolationMax set interpolation to maximum.
Definition: data.hpp:129
bool calculateOneVoxel(const vector3 &pos, t_voxel *resultVoxel) const override
calculateOneVoxel calculates on voxel in getAxisAlignedBoundingBox().
Definition: sphere.hpp:82
Definition: transform.hpp:20
const vector3 & getCenter(void) const
Definition: sphere.hpp:29
real squaredDistance(const vector3 &rhs) const
Definition: vector3.hpp:384
void setSphere(const ::blub::sphere &desc)
setSphere sets the describing sphere. Dont set it while caluculating voxel.
Definition: sphere.hpp:49
blub::axisAlignedBox getAxisAlignedBoundingBox(const blub::transform &trans) const override
getAxisAlignedBoundingBox returns the transformed aab that includes the sphere.
Definition: sphere.hpp:67
The sphere class creates an interpolated voxel-sphere.
Definition: predecl.hpp:79
static pointer create(const ::blub::sphere &desc)
creates an instance
Definition: sphere.hpp:40
void setInterpolation(const int8 &toSet)
setInterpolation sets interpolation
Definition: data.hpp:61
Definition: vector3.hpp:26
const ::blub::sphere & getSphere() const
getSphere
Definition: sphere.hpp:57
Definition: axisAlignedBox.hpp:20
The data class is the default voxel. Contains an 8-bit interpolation value. Replace/derive it and set...
Definition: data.hpp:27
const vector3 & getMinimum(void) const
Definition: axisAlignedBox.hpp:126
const vector3 & getMaximum(void) const
Definition: axisAlignedBox.hpp:141
Definition: deadlineTimer.hpp:10
Definition: customVertexInformation.cpp:177
Definition: sphere.hpp:10