diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-07-05 17:56:40 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-07-05 17:56:40 +0300 |
commit | f67431d7293ad570e539051ecb90276ec16e093e (patch) | |
tree | 7735b13f944349b01790b38c62c190263dfab9e4 /source/blender/simulations/bparticles/forces.cpp | |
parent | 30c6880fe00b5c90555c918ef248dd43d2f594d3 (diff) |
use gravity node in simulation
Diffstat (limited to 'source/blender/simulations/bparticles/forces.cpp')
-rw-r--r-- | source/blender/simulations/bparticles/forces.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp index ea5fc83a79b..4b3215720eb 100644 --- a/source/blender/simulations/bparticles/forces.cpp +++ b/source/blender/simulations/bparticles/forces.cpp @@ -8,19 +8,31 @@ Force::~Force() { } -class DirectionalForce : public Force { +class GravityForce : public Force { private: - float3 m_force; + SharedFunction m_compute_acceleration_fn; + TupleCallBody *m_compute_acceleration_body; public: - DirectionalForce(float3 force) : m_force(force) + GravityForce(SharedFunction &compute_acceleration_fn) + : m_compute_acceleration_fn(compute_acceleration_fn) { + m_compute_acceleration_body = m_compute_acceleration_fn->body<TupleCallBody>(); } void add_force(ParticlesBlock &block, ArrayRef<float3> r_force) override { + FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_acceleration_body, fn_in, fn_out); + + FN::ExecutionStack stack; + FN::ExecutionContext execution_context(stack); + + m_compute_acceleration_body->call(fn_in, fn_out, execution_context); + + float3 acceleration = fn_out.get<float3>(0); + for (uint i = 0; i < block.active_amount(); i++) { - r_force[i] += m_force; + r_force[i] += acceleration; } }; }; @@ -46,9 +58,9 @@ class TurbulenceForce : public BParticles::Force { } }; -Force *FORCE_directional(float3 force) +Force *FORCE_gravity(SharedFunction &compute_acceleration_fn) { - return new DirectionalForce(force); + return new GravityForce(compute_acceleration_fn); } Force *FORCE_turbulence(float strength) |