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

◆ apply_spatial_interactions()

void MayaFlux::Nodes::Network::PhysicsOperator::apply_spatial_interactions ( )
private

Definition at line 420 of file PhysicsOperator.cpp.

421{
422 for (size_t g1 = 0; g1 < m_collections.size(); ++g1) {
423 auto& group1 = m_collections[g1];
424 auto& points1 = group1.collection->get_points();
425
426 for (size_t i = 0; i < points1.size(); ++i) {
427 const auto& pos_i = points1[i].position;
428 auto& state_i = group1.physics_state[i];
429
430 for (size_t g2 = 0; g2 < m_collections.size(); ++g2) {
431 auto& group2 = m_collections[g2];
432 auto& points2 = group2.collection->get_points();
433
434 size_t start_j = (g1 == g2) ? i + 1 : 0;
435
436 for (size_t j = start_j; j < points2.size(); ++j) {
437 const auto& pos_j = points2[j].position;
438 auto& state_j = group2.physics_state[j];
439
440 glm::vec3 delta = pos_j - pos_i;
441 float distance = glm::length(delta);
442
443 if (distance < m_interaction_radius && distance > 0.001F) {
444 glm::vec3 direction = delta / distance;
445
446 float spring_force = m_spring_stiffness * (distance - m_interaction_radius * 0.5F);
447
448 float repulsion_force = 0.0F;
449 if (distance < m_interaction_radius * 0.3F) {
450 repulsion_force = m_repulsion_strength / (distance * distance);
451 }
452
453 glm::vec3 force = direction * (spring_force - repulsion_force);
454
455 state_i.force += force;
456 state_j.force -= force;
457 }
458 }
459 }
460 }
461 }
462}
std::vector< CollectionGroup > m_collections

References m_collections, m_interaction_radius, m_repulsion_strength, and m_spring_stiffness.

Referenced by apply_forces().

+ Here is the caller graph for this function: