MayaFlux 0.4.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 432 of file PhysicsOperator.cpp.

433{
434 for (size_t g1 = 0; g1 < m_collections.size(); ++g1) {
435 auto& group1 = m_collections[g1];
436 auto& points1 = group1.collection->get_points();
437
438 for (size_t i = 0; i < points1.size(); ++i) {
439 const auto& pos_i = points1[i].position;
440 auto& state_i = group1.physics_state[i];
441
442 for (size_t g2 = 0; g2 < m_collections.size(); ++g2) {
443 auto& group2 = m_collections[g2];
444 auto& points2 = group2.collection->get_points();
445
446 size_t start_j = (g1 == g2) ? i + 1 : 0;
447
448 for (size_t j = start_j; j < points2.size(); ++j) {
449 const auto& pos_j = points2[j].position;
450 auto& state_j = group2.physics_state[j];
451
452 glm::vec3 delta = pos_j - pos_i;
453 float distance = glm::length(delta);
454
455 if (distance < m_interaction_radius && distance > 0.001F) {
456 glm::vec3 direction = delta / distance;
457
458 float spring_force = m_spring_stiffness * (distance - m_interaction_radius * 0.5F);
459
460 float repulsion_force = 0.0F;
461 if (distance < m_interaction_radius * 0.3F) {
462 repulsion_force = m_repulsion_strength / (distance * distance);
463 }
464
465 glm::vec3 force = direction * (spring_force - repulsion_force);
466
467 state_i.force += force;
468 state_j.force -= force;
469 }
470 }
471 }
472 }
473 }
474}
std::vector< CollectionGroup > m_collections
SpatialField distance(const glm::vec3 &anchor, float radius, DistanceMetric metric=DistanceMetric::EUCLIDEAN)
Normalized distance from an anchor point using the specified metric.

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: