MCPcopy Create free account
hub / github.com/aardappel/lobster / ComputeDepth

Method ComputeDepth

dev/include/Box2D/Particle/b2ParticleSystem.cpp:1692–1798  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1690}
1691
1692void b2ParticleSystem::ComputeDepth()
1693{
1694 b2ParticleContact* contactGroups = (b2ParticleContact*) m_world->
1695 m_stackAllocator.Allocate(sizeof(b2ParticleContact) * m_contactBuffer.GetCount());
1696 int32 contactGroupsCount = 0;
1697 for (int32 k = 0; k < m_contactBuffer.GetCount(); k++)
1698 {
1699 const b2ParticleContact& contact = m_contactBuffer[k];
1700 int32 a = contact.GetIndexA();
1701 int32 b = contact.GetIndexB();
1702 const b2ParticleGroup* groupA = m_groupBuffer[a];
1703 const b2ParticleGroup* groupB = m_groupBuffer[b];
1704 if (groupA && groupA == groupB &&
1705 (groupA->m_groupFlags & b2_particleGroupNeedsUpdateDepth))
1706 {
1707 contactGroups[contactGroupsCount++] = contact;
1708 }
1709 }
1710 b2ParticleGroup** groupsToUpdate = (b2ParticleGroup**) m_world->
1711 m_stackAllocator.Allocate(sizeof(b2ParticleGroup*) * m_groupCount);
1712 int32 groupsToUpdateCount = 0;
1713 for (b2ParticleGroup* group = m_groupList; group; group = group->GetNext())
1714 {
1715 if (group->m_groupFlags & b2_particleGroupNeedsUpdateDepth)
1716 {
1717 groupsToUpdate[groupsToUpdateCount++] = group;
1718 SetGroupFlags(group,
1719 group->m_groupFlags &
1720 ~b2_particleGroupNeedsUpdateDepth);
1721 for (int32 i = group->m_firstIndex; i < group->m_lastIndex; i++)
1722 {
1723 m_accumulationBuffer[i] = 0;
1724 }
1725 }
1726 }
1727 // Compute sum of weight of contacts except between different groups.
1728 for (int32 k = 0; k < contactGroupsCount; k++)
1729 {
1730 const b2ParticleContact& contact = contactGroups[k];
1731 int32 a = contact.GetIndexA();
1732 int32 b = contact.GetIndexB();
1733 float32 w = contact.GetWeight();
1734 m_accumulationBuffer[a] += w;
1735 m_accumulationBuffer[b] += w;
1736 }
1737 b2Assert(m_depthBuffer);
1738 for (int32 i = 0; i < groupsToUpdateCount; i++)
1739 {
1740 const b2ParticleGroup* group = groupsToUpdate[i];
1741 for (int32 i = group->m_firstIndex; i < group->m_lastIndex; i++)
1742 {
1743 float32 w = m_accumulationBuffer[i];
1744 m_depthBuffer[i] = w < 0.8f ? 0 : b2_maxFloat;
1745 }
1746 }
1747 // The number of iterations is equal to particle number from the deepest
1748 // particle to the nearest surface particle, and in general it is smaller
1749 // than sqrt of total particle number.

Callers

nothing calls this directly

Calls 7

GetIndexAMethod · 0.80
GetIndexBMethod · 0.80
GetWeightMethod · 0.80
AllocateMethod · 0.45
GetCountMethod · 0.45
GetNextMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected