public World(Vec2 gravity, IWorldPool pool, BroadPhase broadPhase) { this.pool = pool; m_destructionListener = null; m_debugDraw = null; m_bodyList = null; m_jointList = null; m_bodyCount = 0; m_jointCount = 0; m_warmStarting = true; m_continuousPhysics = true; m_subStepping = false; m_stepComplete = true; m_allowSleep = true; m_gravity.set(gravity); m_flags = CLEAR_FORCES; m_inv_dt0 = 0f; m_contactManager = new ContactManager(this, broadPhase); m_profile = new Profile(); m_particleSystem = new ParticleSystem(this); initializeRegisters(); }
public void joinParticleGroups(ParticleGroup groupA, ParticleGroup groupB) { assert (groupA != groupB); RotateBuffer(groupB.m_firstIndex, groupB.m_lastIndex, m_count); assert (groupB.m_lastIndex == m_count); RotateBuffer(groupA.m_firstIndex, groupA.m_lastIndex, groupB.m_firstIndex); assert (groupA.m_lastIndex == groupB.m_firstIndex); updateContacts(true); if ((particleFlags & k_pairFlags) != 0) { for (int k = 0; k < m_contactCount; k++) { diagram.generate(getParticleStride() / 2); JoinParticleGroupsCallback callback = new JoinParticleGroupsCallback(); callback.system = this; groupA.m_lastIndex = groupB.m_lastIndex; groupB.m_firstIndex = groupB.m_lastIndex; destroyParticleGroup(groupB); computeDepthForGroup(groupA);
int i = proxy.index; Vec2 pos = m_positionBuffer.data[i]; proxy.tag = computeTag(m_inverseDiameter * pos.x, m_inverseDiameter * pos.y); for (int i = 0; i < m_proxyCount; i++) { Proxy a = m_proxyBuffer[i]; long rightTag = computeRelativeTag(a.tag, 1, 0); for (int j = i + 1; j < m_proxyCount; j++) { Proxy b = m_proxyBuffer[j]; break; addContact(a.index, b.index); long bottomLeftTag = computeRelativeTag(a.tag, -1, 1); for (; c_index < m_proxyCount; c_index++) { Proxy c = m_proxyBuffer[c_index]; long bottomRightTag = computeRelativeTag(a.tag, 1, 1); break; addContact(a.index, b.index);
public void queryAABB(ParticleQueryCallback callback, final AABB aabb) { if (m_proxyCount == 0) { return; } final float lowerBoundX = aabb.lowerBound.x; final float lowerBoundY = aabb.lowerBound.y; final float upperBoundX = aabb.upperBound.x; final float upperBoundY = aabb.upperBound.y; int firstProxy = lowerBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * lowerBoundX, m_inverseDiameter * lowerBoundY)); int lastProxy = upperBound(m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * upperBoundX, m_inverseDiameter * upperBoundY)); for (int proxy = firstProxy; proxy < lastProxy; ++proxy) { int i = m_proxyBuffer[proxy].index; final Vec2 p = m_positionBuffer.data[i]; if (lowerBoundX < p.x && p.x < upperBoundX && lowerBoundY < p.y && p.y < upperBoundY) { if (!callback.reportParticle(i)) { break; } } } }
public ParticleGroup createParticleGroup(ParticleGroupDef groupDef) { float stride = getParticleStride(); final Transform identity = tempTransform; identity.setIdentity(); Vec2.crossToOutUnsafe(groupDef.angularVelocity, p, particleDef.velocity); particleDef.velocity.addLocal(groupDef.linearVelocity); createParticle(particleDef); updateContacts(true); if ((groupDef.flags & k_pairFlags) != 0) { for (int k = 0; k < m_contactCount; k++) { computeDepthForGroup(group);
system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter av.x = vx; av.y = vy; final float particleMass = system.getParticleMass(); final float ax = particleMass * (av.x - vx); final float ay = particleMass * (av.y - vy);
system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter float invAm = (system.m_flagsBuffer.data[a] & ParticleType.b2_wallParticle) != 0 ? 0 : system .getParticleInvMass(); final float rpx = ap.x - bp.x; final float rpy = ap.y - bp.y;
public void destroyParticlesInGroup(ParticleGroup group, boolean callDestructionListener) { for (int i = group.m_firstIndex; i < group.m_lastIndex; i++) { destroyParticle(i, callDestructionListener); } }
/** * Compute the kinetic energy that can be lost by damping force * * @return */ public float computeParticleCollisionEnergy() { return m_particleSystem.computeParticleCollisionEnergy(); } }
/** * Create a particle group whose properties have been defined. No reference to the definition is * retained. * * @warning This function is locked during callbacks. */ public ParticleGroup createParticleGroup(ParticleGroupDef def) { assert (isLocked() == false); if (isLocked()) { return null; } ParticleGroup g = m_particleSystem.createParticleGroup(def); return g; }
/** * Create a particle whose properties have been defined. No reference to the definition is * retained. A simulation step must occur before it's possible to interact with a newly created * particle. For example, DestroyParticleInShape() will not destroy a particle until Step() has * been called. * * @warning This function is locked during callbacks. * @return the index of the particle. */ public int createParticle(ParticleDef def) { assert (isLocked() == false); if (isLocked()) { return 0; } int p = m_particleSystem.createParticle(def); return p; }
lowerBound( m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * MathUtils.min(point1.x, point2.x) - 1, m_inverseDiameter * MathUtils.min(point1.y, point2.y) - 1)); int lastProxy = upperBound( m_proxyBuffer, m_proxyCount, computeTag(m_inverseDiameter * MathUtils.max(point1.x, point2.x) + 1, m_inverseDiameter * MathUtils.max(point1.y, point2.y) + 1)); float fraction = 1;
public ParticleGroup createParticleGroup(ParticleGroupDef groupDef) { float stride = getParticleStride(); final Transform identity = tempTransform; identity.setIdentity(); Vec2.crossToOutUnsafe(groupDef.angularVelocity, p, particleDef.velocity); particleDef.velocity.addLocal(groupDef.linearVelocity); createParticle(particleDef); updateContacts(true); if ((groupDef.flags & k_pairFlags) != 0) { for (int k = 0; k < m_contactCount; k++) { computeDepthForGroup(group);
system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter av.x = vx; av.y = vy; final float particleMass = system.getParticleMass(); final float ax = particleMass * (av.x - vx); final float ay = particleMass * (av.y - vy);
system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter system.m_proxyBuffer, system.m_proxyCount, computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter float invAm = (system.m_flagsBuffer.data[a] & ParticleType.b2_wallParticle) != 0 ? 0 : system .getParticleInvMass(); final float rpx = ap.x - bp.x; final float rpy = ap.y - bp.y;
/** * Destroy a particle. The particle is removed after the next step. * * @param Index of the particle to destroy. * @param Whether to call the destruction listener just before the particle is destroyed. */ public void destroyParticle(int index, boolean callDestructionListener) { m_particleSystem.destroyParticle(index, callDestructionListener); }
/** * Compute the kinetic energy that can be lost by damping force * * @return */ public float computeParticleCollisionEnergy() { return m_particleSystem.computeParticleCollisionEnergy(); } }
/** * Create a particle group whose properties have been defined. No reference to the definition is * retained. * * @warning This function is locked during callbacks. */ public ParticleGroup createParticleGroup(ParticleGroupDef def) { assert (isLocked() == false); if (isLocked()) { return null; } ParticleGroup g = m_particleSystem.createParticleGroup(def); return g; }
/** * Create a particle whose properties have been defined. No reference to the definition is * retained. A simulation step must occur before it's possible to interact with a newly created * particle. For example, DestroyParticleInShape() will not destroy a particle until Step() has * been called. * * @warning This function is locked during callbacks. * @return the index of the particle. */ public int createParticle(ParticleDef def) { assert (isLocked() == false); if (isLocked()) { return 0; } int p = m_particleSystem.createParticle(def); return p; }
public void joinParticleGroups(ParticleGroup groupA, ParticleGroup groupB) { assert (groupA != groupB); RotateBuffer(groupB.m_firstIndex, groupB.m_lastIndex, m_count); assert (groupB.m_lastIndex == m_count); RotateBuffer(groupA.m_firstIndex, groupA.m_lastIndex, groupB.m_firstIndex); assert (groupA.m_lastIndex == groupB.m_firstIndex); updateContacts(true); if ((particleFlags & k_pairFlags) != 0) { for (int k = 0; k < m_contactCount; k++) { diagram.generate(getParticleStride() / 2); JoinParticleGroupsCallback callback = new JoinParticleGroupsCallback(); callback.system = this; groupA.m_lastIndex = groupB.m_lastIndex; groupB.m_firstIndex = groupB.m_lastIndex; destroyParticleGroup(groupB); computeDepthForGroup(groupA);