From 0a7715e30862345c8ed4eb681898a178b68bf4fb Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 19 Jun 2019 11:06:23 +0200 Subject: move forces into separate file --- source/blender/simulations/bparticles/forces.cpp | 60 ++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 source/blender/simulations/bparticles/forces.cpp (limited to 'source/blender/simulations/bparticles/forces.cpp') 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 indices_mask, + ArrayRef 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 indices_mask, + ArrayRef 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_directional(float3 force) +{ + return std::unique_ptr(new DirectionalForce(force)); +} + +std::unique_ptr FORCE_turbulence(float strength) +{ + return std::unique_ptr(new TurbulenceForce(strength)); +} + +} // namespace BParticles -- cgit v1.2.3