MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ apply_interaction_forces()

void MayaFlux::Nodes::Network::ParticleNetwork::apply_interaction_forces ( )
private

Apply interaction forces based on topology.

Definition at line 366 of file ParticleNetwork.cpp.

367{
371 }
372
373 for (const auto& [idx, neighbors] : m_neighbor_map) {
374 auto& particle_a = m_particles[idx];
375 glm::vec3 pos_a = particle_a.point->get_position();
376
377 for (size_t neighbor_idx : neighbors) {
378 auto& particle_b = m_particles[neighbor_idx];
379 glm::vec3 pos_b = particle_b.point->get_position();
380
381 glm::vec3 delta = pos_b - pos_a;
382 float distance = glm::length(delta);
383
384 if (distance > 0.001F) {
385 glm::vec3 direction = delta / distance;
386
387 float spring_force = m_spring_stiffness * (distance - m_interaction_radius);
388
389 float repulsion_force = 0.0F;
390 if (distance < m_interaction_radius * 0.5F) {
391 repulsion_force = m_repulsion_strength / (distance * distance);
392 }
393
394 glm::vec3 force = direction * (spring_force - repulsion_force);
395 particle_a.force += force;
396 }
397 }
398 }
400 for (const auto& [idx, neighbors] : m_neighbor_map) {
401 auto& particle_a = m_particles[idx];
402 glm::vec3 pos_a = particle_a.point->get_position();
403
404 for (size_t neighbor_idx : neighbors) {
405 auto& particle_b = m_particles[neighbor_idx];
406 glm::vec3 pos_b = particle_b.point->get_position();
407
408 glm::vec3 delta = pos_b - pos_a;
409 float distance = glm::length(delta);
410
411 if (distance > 0.001F) {
412 glm::vec3 direction = delta / distance;
413 float spring_force = m_spring_stiffness * (distance - 1.0F); // Rest length = 1.0
414 particle_a.force += direction * spring_force;
415 }
416 }
417 }
418 }
419}
@ CHAIN
Linear sequence: node[i] → node[i+1].
@ GRID_2D
2D lattice with 4-connectivity
@ GRID_3D
3D lattice with 6-connectivity
@ SPATIAL
Dynamic proximity-based (nodes within radius interact)
@ RING
Circular: last node connects to first.
void rebuild_spatial_neighbors()
Rebuild neighbor map for SPATIAL topology.
std::unordered_map< size_t, std::vector< size_t > > m_neighbor_map

References MayaFlux::Nodes::Network::NodeNetwork::CHAIN, MayaFlux::Nodes::Network::NodeNetwork::GRID_2D, MayaFlux::Nodes::Network::NodeNetwork::GRID_3D, m_interaction_radius, m_neighbor_map, m_neighbor_map_dirty, m_particles, m_repulsion_strength, m_spring_stiffness, MayaFlux::Nodes::Network::NodeNetwork::m_topology, rebuild_spatial_neighbors(), MayaFlux::Nodes::Network::NodeNetwork::RING, and MayaFlux::Nodes::Network::NodeNetwork::SPATIAL.

Referenced by process_batch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: