| OLD | NEW |
| 1 /******************************************************************************* | 1 /******************************************************************************* |
| 2 * Copyright (c) 2015, Daniel Murphy, Google | 2 * Copyright (c) 2015, Daniel Murphy, Google |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without modificati
on, | 5 * Redistribution and use in source and binary forms, with or without modificati
on, |
| 6 * are permitted provided that the following conditions are met: | 6 * are permitted provided that the following conditions are met: |
| 7 * * Redistributions of source code must retain the above copyright notice, | 7 * * Redistributions of source code must retain the above copyright notice, |
| 8 * this list of conditions and the following disclaimer. | 8 * this list of conditions and the following disclaimer. |
| 9 * * Redistributions in binary form must reproduce the above copyright notice, | 9 * * Redistributions in binary form must reproduce the above copyright notice, |
| 10 * this list of conditions and the following disclaimer in the documentation | 10 * this list of conditions and the following disclaimer in the documentation |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 int a = system.proxyBuffer[proxy].index; | 171 int a = system.proxyBuffer[proxy].index; |
| 172 Vector2 ap = system.positionBuffer.data[a]; | 172 Vector2 ap = system.positionBuffer.data[a]; |
| 173 if (aabblowerBoundx <= ap.x && | 173 if (aabblowerBoundx <= ap.x && |
| 174 ap.x <= aabbupperBoundx && | 174 ap.x <= aabbupperBoundx && |
| 175 aabblowerBoundy <= ap.y && | 175 aabblowerBoundy <= ap.y && |
| 176 ap.y <= aabbupperBoundy) { | 176 ap.y <= aabbupperBoundy) { |
| 177 double d; | 177 double d; |
| 178 final Vector2 n = _tempVec; | 178 final Vector2 n = _tempVec; |
| 179 d = fixture.computeDistance(ap, childIndex, n); | 179 d = fixture.computeDistance(ap, childIndex, n); |
| 180 if (d < system.particleDiameter) { | 180 if (d < system.particleDiameter) { |
| 181 double invAm = (system.flagsBuffer.data[a] & | 181 double invAm = |
| 182 ParticleType.b2_wallParticle) != | 182 (system.flagsBuffer.data[a] & ParticleType.b2_wallParticle) != 0 |
| 183 0 ? 0 : system.getParticleInvMass(); | 183 ? 0 |
| 184 : system.getParticleInvMass(); |
| 184 final double rpx = ap.x - bp.x; | 185 final double rpx = ap.x - bp.x; |
| 185 final double rpy = ap.y - bp.y; | 186 final double rpy = ap.y - bp.y; |
| 186 double rpn = rpx * n.y - rpy * n.x; | 187 double rpn = rpx * n.y - rpy * n.x; |
| 187 if (system.bodyContactCount >= system.bodyContactCapacity) { | 188 if (system.bodyContactCount >= system.bodyContactCapacity) { |
| 188 int oldCapacity = system.bodyContactCapacity; | 189 int oldCapacity = system.bodyContactCapacity; |
| 189 int newCapacity = system.bodyContactCount != 0 | 190 int newCapacity = system.bodyContactCount != 0 |
| 190 ? 2 * system.bodyContactCount | 191 ? 2 * system.bodyContactCount |
| 191 : Settings.minParticleBufferCapacity; | 192 : Settings.minParticleBufferCapacity; |
| 192 system.bodyContactBuffer = BufferUtils | 193 system.bodyContactBuffer = BufferUtils.reallocateBufferWithAlloc( |
| 193 .reallocateBufferWithAlloc(system.bodyContactBuffer, | 194 system.bodyContactBuffer, oldCapacity, newCapacity, |
| 194 oldCapacity, newCapacity, allocParticleBodyContact); | 195 allocParticleBodyContact); |
| 195 system.bodyContactCapacity = newCapacity; | 196 system.bodyContactCapacity = newCapacity; |
| 196 } | 197 } |
| 197 ParticleBodyContact contact = | 198 ParticleBodyContact contact = |
| 198 system.bodyContactBuffer[system.bodyContactCount]; | 199 system.bodyContactBuffer[system.bodyContactCount]; |
| 199 contact.index = a; | 200 contact.index = a; |
| 200 contact.body = b; | 201 contact.body = b; |
| 201 contact.weight = 1 - d * system.inverseDiameter; | 202 contact.weight = 1 - d * system.inverseDiameter; |
| 202 contact.normal.x = -n.x; | 203 contact.normal.x = -n.x; |
| 203 contact.normal.y = -n.y; | 204 contact.normal.y = -n.y; |
| 204 contact.mass = 1 / (invAm + invBm + invBI * rpn * rpn); | 205 contact.mass = 1 / (invAm + invBm + invBI * rpn * rpn); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 capacity = limitCapacity(capacity, colorBuffer.userSuppliedCapacity); | 564 capacity = limitCapacity(capacity, colorBuffer.userSuppliedCapacity); |
| 564 capacity = limitCapacity(capacity, userDataBuffer.userSuppliedCapacity); | 565 capacity = limitCapacity(capacity, userDataBuffer.userSuppliedCapacity); |
| 565 if (internalAllocatedCapacity < capacity) { | 566 if (internalAllocatedCapacity < capacity) { |
| 566 flagsBuffer.data = reallocateBufferInt( | 567 flagsBuffer.data = reallocateBufferInt( |
| 567 flagsBuffer, internalAllocatedCapacity, capacity, false); | 568 flagsBuffer, internalAllocatedCapacity, capacity, false); |
| 568 positionBuffer.data = reallocateBuffer( | 569 positionBuffer.data = reallocateBuffer( |
| 569 positionBuffer, internalAllocatedCapacity, capacity, false); | 570 positionBuffer, internalAllocatedCapacity, capacity, false); |
| 570 velocityBuffer.data = reallocateBuffer( | 571 velocityBuffer.data = reallocateBuffer( |
| 571 velocityBuffer, internalAllocatedCapacity, capacity, false); | 572 velocityBuffer, internalAllocatedCapacity, capacity, false); |
| 572 accumulationBuffer = BufferUtils.reallocateBufferFloat64Deferred( | 573 accumulationBuffer = BufferUtils.reallocateBufferFloat64Deferred( |
| 573 accumulationBuffer, 0, internalAllocatedCapacity, capacity, | 574 accumulationBuffer, 0, internalAllocatedCapacity, capacity, false); |
| 574 false); | |
| 575 accumulation2Buffer = BufferUtils.reallocateBufferWithAllocDeferred( | 575 accumulation2Buffer = BufferUtils.reallocateBufferWithAllocDeferred( |
| 576 accumulation2Buffer, 0, internalAllocatedCapacity, capacity, | 576 accumulation2Buffer, 0, internalAllocatedCapacity, capacity, true, |
| 577 true, allocVec2); | 577 allocVec2); |
| 578 depthBuffer = BufferUtils.reallocateBufferFloat64Deferred( | 578 depthBuffer = BufferUtils.reallocateBufferFloat64Deferred( |
| 579 depthBuffer, 0, internalAllocatedCapacity, capacity, true); | 579 depthBuffer, 0, internalAllocatedCapacity, capacity, true); |
| 580 colorBuffer.data = reallocateBuffer( | 580 colorBuffer.data = reallocateBuffer( |
| 581 colorBuffer, internalAllocatedCapacity, capacity, true); | 581 colorBuffer, internalAllocatedCapacity, capacity, true); |
| 582 groupBuffer = BufferUtils.reallocateBufferWithAllocDeferred( | 582 groupBuffer = BufferUtils.reallocateBufferWithAllocDeferred(groupBuffer, |
| 583 groupBuffer, 0, internalAllocatedCapacity, capacity, false, | 583 0, internalAllocatedCapacity, capacity, false, allocParticleGroup); |
| 584 allocParticleGroup); | |
| 585 userDataBuffer.data = reallocateBuffer( | 584 userDataBuffer.data = reallocateBuffer( |
| 586 userDataBuffer, internalAllocatedCapacity, capacity, true); | 585 userDataBuffer, internalAllocatedCapacity, capacity, true); |
| 587 internalAllocatedCapacity = capacity; | 586 internalAllocatedCapacity = capacity; |
| 588 } | 587 } |
| 589 } | 588 } |
| 590 if (count >= internalAllocatedCapacity) { | 589 if (count >= internalAllocatedCapacity) { |
| 591 return Settings.invalidParticleIndex; | 590 return Settings.invalidParticleIndex; |
| 592 } | 591 } |
| 593 int index = count++; | 592 int index = count++; |
| 594 flagsBuffer.data[index] = def.flags; | 593 flagsBuffer.data[index] = def.flags; |
| 595 positionBuffer.data[index].setFrom(def.position); | 594 positionBuffer.data[index].setFrom(def.position); |
| 596 // assertNotSamePosition(); | 595 // assertNotSamePosition(); |
| 597 velocityBuffer.data[index].setFrom(def.velocity); | 596 velocityBuffer.data[index].setFrom(def.velocity); |
| 598 groupBuffer[index] = null; | 597 groupBuffer[index] = null; |
| 599 if (depthBuffer != null) { | 598 if (depthBuffer != null) { |
| 600 depthBuffer[index] = 0.0; | 599 depthBuffer[index] = 0.0; |
| 601 } | 600 } |
| 602 if (colorBuffer.data != null || def.color != null) { | 601 if (colorBuffer.data != null || def.color != null) { |
| 603 colorBuffer.data = | 602 colorBuffer.data = |
| 604 requestParticleBuffer(colorBuffer.data, colorBuffer.allocClosure); | 603 requestParticleBuffer(colorBuffer.data, colorBuffer.allocClosure); |
| 605 colorBuffer.data[index].setParticleColor(def.color); | 604 colorBuffer.data[index].setParticleColor(def.color); |
| 606 } | 605 } |
| 607 if (userDataBuffer.data != null || def.userData != null) { | 606 if (userDataBuffer.data != null || def.userData != null) { |
| 608 userDataBuffer.data = requestParticleBuffer( | 607 userDataBuffer.data = requestParticleBuffer( |
| 609 userDataBuffer.data, userDataBuffer.allocClosure); | 608 userDataBuffer.data, userDataBuffer.allocClosure); |
| 610 userDataBuffer.data[index] = def.userData; | 609 userDataBuffer.data[index] = def.userData; |
| 611 } | 610 } |
| 612 if (proxyCount >= proxyCapacity) { | 611 if (proxyCount >= proxyCapacity) { |
| 613 int oldCapacity = proxyCapacity; | 612 int oldCapacity = proxyCapacity; |
| 614 int newCapacity = proxyCount != 0 | 613 int newCapacity = |
| 615 ? 2 * proxyCount | 614 proxyCount != 0 ? 2 * proxyCount : Settings.minParticleBufferCapacity; |
| 616 : Settings.minParticleBufferCapacity; | |
| 617 proxyBuffer = BufferUtils.reallocateBufferWithAlloc( | 615 proxyBuffer = BufferUtils.reallocateBufferWithAlloc( |
| 618 proxyBuffer, oldCapacity, newCapacity, allocPsProxy); | 616 proxyBuffer, oldCapacity, newCapacity, allocPsProxy); |
| 619 proxyCapacity = newCapacity; | 617 proxyCapacity = newCapacity; |
| 620 } | 618 } |
| 621 proxyBuffer[proxyCount++].index = index; | 619 proxyBuffer[proxyCount++].index = index; |
| 622 return index; | 620 return index; |
| 623 } | 621 } |
| 624 | 622 |
| 625 // reallocate a buffer | 623 // reallocate a buffer |
| 626 static List reallocateBuffer( | 624 static List reallocateBuffer( |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 contact.normal.y = invD * dy; | 1010 contact.normal.y = invD * dy; |
| 1013 contactCount++; | 1011 contactCount++; |
| 1014 } | 1012 } |
| 1015 } | 1013 } |
| 1016 | 1014 |
| 1017 void updateContacts(bool exceptZombie) { | 1015 void updateContacts(bool exceptZombie) { |
| 1018 for (int p = 0; p < proxyCount; p++) { | 1016 for (int p = 0; p < proxyCount; p++) { |
| 1019 PsProxy proxy = proxyBuffer[p]; | 1017 PsProxy proxy = proxyBuffer[p]; |
| 1020 int i = proxy.index; | 1018 int i = proxy.index; |
| 1021 Vector2 pos = positionBuffer.data[i]; | 1019 Vector2 pos = positionBuffer.data[i]; |
| 1022 proxy.tag = | 1020 proxy.tag = computeTag(inverseDiameter * pos.x, inverseDiameter * pos.y); |
| 1023 computeTag(inverseDiameter * pos.x, inverseDiameter * pos.y); | |
| 1024 } | 1021 } |
| 1025 BufferUtils.sort(proxyBuffer, 0, proxyCount); | 1022 BufferUtils.sort(proxyBuffer, 0, proxyCount); |
| 1026 contactCount = 0; | 1023 contactCount = 0; |
| 1027 int c_index = 0; | 1024 int c_index = 0; |
| 1028 for (int i = 0; i < proxyCount; i++) { | 1025 for (int i = 0; i < proxyCount; i++) { |
| 1029 PsProxy a = proxyBuffer[i]; | 1026 PsProxy a = proxyBuffer[i]; |
| 1030 int rightTag = computeRelativeTag(a.tag, 1, 0); | 1027 int rightTag = computeRelativeTag(a.tag, 1, 0); |
| 1031 for (int j = i + 1; j < proxyCount; j++) { | 1028 for (int j = i + 1; j < proxyCount; j++) { |
| 1032 PsProxy b = proxyBuffer[j]; | 1029 PsProxy b = proxyBuffer[j]; |
| 1033 if (rightTag < b.tag) { | 1030 if (rightTag < b.tag) { |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 final Vector2 vb = velocityBuffer.data[b]; | 1435 final Vector2 vb = velocityBuffer.data[b]; |
| 1439 va.x -= fx; | 1436 va.x -= fx; |
| 1440 va.y -= fy; | 1437 va.y -= fy; |
| 1441 vb.x += fx; | 1438 vb.x += fx; |
| 1442 vb.y += fy; | 1439 vb.y += fy; |
| 1443 } | 1440 } |
| 1444 } | 1441 } |
| 1445 } | 1442 } |
| 1446 | 1443 |
| 1447 void solveTensile(final TimeStep step) { | 1444 void solveTensile(final TimeStep step) { |
| 1448 accumulation2Buffer = | 1445 accumulation2Buffer = requestParticleBuffer(accumulation2Buffer, allocVec2); |
| 1449 requestParticleBuffer(accumulation2Buffer, allocVec2); | |
| 1450 for (int i = 0; i < count; i++) { | 1446 for (int i = 0; i < count; i++) { |
| 1451 accumulationBuffer[i] = 0.0; | 1447 accumulationBuffer[i] = 0.0; |
| 1452 accumulation2Buffer[i].setZero(); | 1448 accumulation2Buffer[i].setZero(); |
| 1453 } | 1449 } |
| 1454 for (int k = 0; k < contactCount; k++) { | 1450 for (int k = 0; k < contactCount; k++) { |
| 1455 final ParticleContact contact = contactBuffer[k]; | 1451 final ParticleContact contact = contactBuffer[k]; |
| 1456 if ((contact.flags & ParticleType.b2_tensileParticle) != 0) { | 1452 if ((contact.flags & ParticleType.b2_tensileParticle) != 0) { |
| 1457 int a = contact.indexA; | 1453 int a = contact.indexA; |
| 1458 int b = contact.indexB; | 1454 int b = contact.indexB; |
| 1459 double w = contact.weight; | 1455 double w = contact.weight; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 newIndices[i] = newCount; | 1662 newIndices[i] = newCount; |
| 1667 if (i != newCount) { | 1663 if (i != newCount) { |
| 1668 flagsBuffer.data[newCount] = flagsBuffer.data[i]; | 1664 flagsBuffer.data[newCount] = flagsBuffer.data[i]; |
| 1669 positionBuffer.data[newCount].setFrom(positionBuffer.data[i]); | 1665 positionBuffer.data[newCount].setFrom(positionBuffer.data[i]); |
| 1670 velocityBuffer.data[newCount].setFrom(velocityBuffer.data[i]); | 1666 velocityBuffer.data[newCount].setFrom(velocityBuffer.data[i]); |
| 1671 groupBuffer[newCount] = groupBuffer[i]; | 1667 groupBuffer[newCount] = groupBuffer[i]; |
| 1672 if (depthBuffer != null) { | 1668 if (depthBuffer != null) { |
| 1673 depthBuffer[newCount] = depthBuffer[i]; | 1669 depthBuffer[newCount] = depthBuffer[i]; |
| 1674 } | 1670 } |
| 1675 if (colorBuffer.data != null) { | 1671 if (colorBuffer.data != null) { |
| 1676 colorBuffer.data[newCount] | 1672 colorBuffer.data[newCount].setParticleColor(colorBuffer.data[i]); |
| 1677 .setParticleColor(colorBuffer.data[i]); | |
| 1678 } | 1673 } |
| 1679 if (userDataBuffer.data != null) { | 1674 if (userDataBuffer.data != null) { |
| 1680 userDataBuffer.data[newCount] = userDataBuffer.data[i]; | 1675 userDataBuffer.data[newCount] = userDataBuffer.data[i]; |
| 1681 } | 1676 } |
| 1682 } | 1677 } |
| 1683 newCount++; | 1678 newCount++; |
| 1684 } | 1679 } |
| 1685 } | 1680 } |
| 1686 | 1681 |
| 1687 // update proxies | 1682 // update proxies |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 return velocityBuffer.data; | 1977 return velocityBuffer.data; |
| 1983 } | 1978 } |
| 1984 | 1979 |
| 1985 List<ParticleColor> getParticleColorBuffer() { | 1980 List<ParticleColor> getParticleColorBuffer() { |
| 1986 colorBuffer.data = | 1981 colorBuffer.data = |
| 1987 requestParticleBuffer(colorBuffer.data, colorBuffer.allocClosure); | 1982 requestParticleBuffer(colorBuffer.data, colorBuffer.allocClosure); |
| 1988 return colorBuffer.data; | 1983 return colorBuffer.data; |
| 1989 } | 1984 } |
| 1990 | 1985 |
| 1991 List<Object> getParticleUserDataBuffer() { | 1986 List<Object> getParticleUserDataBuffer() { |
| 1992 userDataBuffer.data = requestParticleBuffer( | 1987 userDataBuffer.data = |
| 1993 userDataBuffer.data, userDataBuffer.allocClosure); | 1988 requestParticleBuffer(userDataBuffer.data, userDataBuffer.allocClosure); |
| 1994 return userDataBuffer.data; | 1989 return userDataBuffer.data; |
| 1995 } | 1990 } |
| 1996 | 1991 |
| 1997 int getParticleMaxCount() { | 1992 int getParticleMaxCount() { |
| 1998 return maxCount; | 1993 return maxCount; |
| 1999 } | 1994 } |
| 2000 | 1995 |
| 2001 void setParticleMaxCount(int count) { | 1996 void setParticleMaxCount(int count) { |
| 2002 assert(count <= count); | 1997 assert(count <= count); |
| 2003 maxCount = count; | 1998 maxCount = count; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2192 final double vx = vb.x - va.x; | 2187 final double vx = vb.x - va.x; |
| 2193 final double vy = vb.y - va.y; | 2188 final double vy = vb.y - va.y; |
| 2194 double vn = vx * n.x + vy * n.y; | 2189 double vn = vx * n.x + vy * n.y; |
| 2195 if (vn < 0) { | 2190 if (vn < 0) { |
| 2196 sum_v2 += vn * vn; | 2191 sum_v2 += vn * vn; |
| 2197 } | 2192 } |
| 2198 } | 2193 } |
| 2199 return 0.5 * getParticleMass() * sum_v2; | 2194 return 0.5 * getParticleMass() * sum_v2; |
| 2200 } | 2195 } |
| 2201 } | 2196 } |
| OLD | NEW |