diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-06-19 12:06:23 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-06-19 12:06:23 +0300 |
commit | 0a7715e30862345c8ed4eb681898a178b68bf4fb (patch) | |
tree | 074e58a0261557ae8f5da2f0d3450bb955091cc5 /source/blender/simulations/bparticles/forces.cpp | |
parent | 3138c7c5d7912c4b90b13e78263886873e964826 (diff) |
move forces into separate file
Diffstat (limited to 'source/blender/simulations/bparticles/forces.cpp')
-rw-r--r-- | source/blender/simulations/bparticles/forces.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp new file mode 100644 index 00000000000..622d7f8ba3f --- /dev/null +++ b/source/blender/simulations/bparticles/forces.cpp @@ -0,0 +1,60 @@ +#include "BLI_noise.h" + +#include "forces.hpp" + +namespace BParticles { + +class DirectionalForce : public Force { + private: + float3 m_force; + + public: + DirectionalForce(float3 force) : m_force(force) + { + } + + void add_force(AttributeArrays UNUSED(attributes), + ArrayRef<uint> indices_mask, + ArrayRef<float3> dst) override + { + for (uint i = 0; i < indices_mask.size(); i++) { + dst[i] += m_force; + } + }; +}; + +class TurbulenceForce : public BParticles::Force { + private: + float m_strength; + + public: + TurbulenceForce(float strength) : m_strength(strength) + { + } + + void add_force(AttributeArrays attributes, + ArrayRef<uint> indices_mask, + ArrayRef<float3> dst) override + { + auto positions = attributes.get_float3("Position"); + for (uint i = 0; i < indices_mask.size(); i++) { + uint pindex = indices_mask[i]; + + float3 pos = positions[pindex]; + float value = BLI_hnoise(0.5f, pos.x, pos.y, pos.z); + dst[i].z += value * m_strength; + } + } +}; + +std::unique_ptr<Force> FORCE_directional(float3 force) +{ + return std::unique_ptr<Force>(new DirectionalForce(force)); +} + +std::unique_ptr<Force> FORCE_turbulence(float strength) +{ + return std::unique_ptr<Force>(new TurbulenceForce(strength)); +} + +} // namespace BParticles |