[Bf-blender-cvs] [aa05731607d] functions: compute new positions and velocities in separate buffer
Jacques Lucke
noreply at git.blender.org
Mon Jun 10 12:05:50 CEST 2019
Commit: aa05731607d0e13ebffa20c5887bc2e60c51e12d
Author: Jacques Lucke
Date: Mon Jun 10 12:05:28 2019 +0200
Branches: functions
https://developer.blender.org/rBaa05731607d0e13ebffa20c5887bc2e60c51e12d
compute new positions and velocities in separate buffer
===================================================================
M source/blender/blenlib/BLI_math.hpp
M source/blender/simulations/bparticles/playground_solver.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index f73213995df..c2a6206d6cb 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -26,6 +26,12 @@ struct float3 {
{
return {a.x * b, a.y * b, a.z * b};
}
+
+ friend float3 operator/(float3 a, float b)
+ {
+ BLI_assert(b != 0);
+ return {a.x / b, a.y / b, a.z / b};
+ }
};
} // namespace BLI
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index cfcc1bb230e..d0c741808cb 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -64,23 +64,37 @@ class SimpleSolver : public Solver {
}
}
- BLI_NOINLINE void step_slice(MyState &state, NamedBuffers &slice, float elapsed_seconds)
+ BLI_NOINLINE void step_slice(MyState &state, NamedBuffers &buffers, float elapsed_seconds)
{
- auto positions = slice.get_float3("Position");
- auto velocities = slice.get_float3("Velocity");
+ auto positions = buffers.get_float3("Position");
+ auto velocities = buffers.get_float3("Velocity");
- SmallVector<float3> combined_force(slice.size());
- this->compute_combined_force(slice, combined_force);
+ SmallVector<float3> combined_force(buffers.size());
+ this->compute_combined_force(buffers, combined_force);
- for (uint i = 0; i < slice.size(); i++) {
- positions[i] += velocities[i] * elapsed_seconds;
- velocities[i] += combined_force[i] * elapsed_seconds;
+ SmallVector<float3> new_positions(buffers.size());
+ SmallVector<float3> new_velocities(buffers.size());
+
+ float mass = 1.0f;
+ for (uint i = 0; i < buffers.size(); i++) {
+ new_positions[i] = positions[i] + velocities[i] * elapsed_seconds;
+ new_velocities[i] = velocities[i] + combined_force[i] / mass * elapsed_seconds;
}
- auto birth_times = slice.get_float("Birth Time");
- auto kill_states = slice.get_byte("Kill State");
+ for (uint i = 0; i < buffers.size(); i++) {
+ if (positions[i].y <= 2 && new_positions[i].y > 2) {
+ new_positions[i].z += 1;
+ new_velocities[i].y *= -1;
+ }
+ }
- for (uint i = 0; i < slice.size(); i++) {
+ positions.copy_from(new_positions);
+ velocities.copy_from(new_velocities);
+
+ auto birth_times = buffers.get_float("Birth Time");
+ auto kill_states = buffers.get_byte("Kill State");
+
+ for (uint i = 0; i < buffers.size(); i++) {
float age = state.seconds_since_start - birth_times[i];
if (age > 5) {
kill_states[i] = 1;
More information about the Bf-blender-cvs
mailing list