use of org.jbox2d.dynamics.Body in project libgdx by libgdx.
the class RevoluteJoint method getJointAngle.
public float getJointAngle() {
final Body b1 = m_bodyA;
final Body b2 = m_bodyB;
return b2.m_sweep.a - b1.m_sweep.a - m_referenceAngle;
}
use of org.jbox2d.dynamics.Body in project libgdx by libgdx.
the class RevoluteJoint method getJointSpeed.
public float getJointSpeed() {
final Body b1 = m_bodyA;
final Body b2 = m_bodyB;
return b2.m_angularVelocity - b1.m_angularVelocity;
}
use of org.jbox2d.dynamics.Body in project libgdx by libgdx.
the class ParticleSystem method solvePressure.
void solvePressure(TimeStep step) {
// that means dimensionless density
for (int i = 0; i < m_count; i++) {
m_accumulationBuffer[i] = 0;
}
for (int k = 0; k < m_bodyContactCount; k++) {
ParticleBodyContact contact = m_bodyContactBuffer[k];
int a = contact.index;
float w = contact.weight;
m_accumulationBuffer[a] += w;
}
for (int k = 0; k < m_contactCount; k++) {
ParticleContact contact = m_contactBuffer[k];
int a = contact.indexA;
int b = contact.indexB;
float w = contact.weight;
m_accumulationBuffer[a] += w;
m_accumulationBuffer[b] += w;
}
// ignores powder particles
if ((m_allParticleFlags & k_noPressureFlags) != 0) {
for (int i = 0; i < m_count; i++) {
if ((m_flagsBuffer.data[i] & k_noPressureFlags) != 0) {
m_accumulationBuffer[i] = 0;
}
}
}
// calculates pressure as a linear function of density
float pressurePerWeight = m_pressureStrength * getCriticalPressure(step);
for (int i = 0; i < m_count; i++) {
float w = m_accumulationBuffer[i];
float h = pressurePerWeight * MathUtils.max(0.0f, MathUtils.min(w, Settings.maxParticleWeight) - Settings.minParticleWeight);
m_accumulationBuffer[i] = h;
}
// applies pressure between each particles in contact
float velocityPerPressure = step.dt / (m_density * m_particleDiameter);
for (int k = 0; k < m_bodyContactCount; k++) {
ParticleBodyContact contact = m_bodyContactBuffer[k];
int a = contact.index;
Body b = contact.body;
float w = contact.weight;
float m = contact.mass;
Vec2 n = contact.normal;
Vec2 p = m_positionBuffer.data[a];
float h = m_accumulationBuffer[a] + pressurePerWeight * w;
final Vec2 f = tempVec;
final float coef = velocityPerPressure * w * m * h;
f.x = coef * n.x;
f.y = coef * n.y;
final Vec2 velData = m_velocityBuffer.data[a];
final float particleInvMass = getParticleInvMass();
velData.x -= particleInvMass * f.x;
velData.y -= particleInvMass * f.y;
b.applyLinearImpulse(f, p, true);
}
for (int k = 0; k < m_contactCount; k++) {
ParticleContact contact = m_contactBuffer[k];
int a = contact.indexA;
int b = contact.indexB;
float w = contact.weight;
Vec2 n = contact.normal;
float h = m_accumulationBuffer[a] + m_accumulationBuffer[b];
final float fx = velocityPerPressure * w * h * n.x;
final float fy = velocityPerPressure * w * h * n.y;
final Vec2 velDataA = m_velocityBuffer.data[a];
final Vec2 velDataB = m_velocityBuffer.data[b];
velDataA.x -= fx;
velDataA.y -= fy;
velDataB.x += fx;
velDataB.y += fy;
}
}
use of org.jbox2d.dynamics.Body in project libgdx by libgdx.
the class ParticleSystem method solveDamping.
void solveDamping(TimeStep step) {
// reduces normal velocity of each contact
float damping = m_dampingStrength;
for (int k = 0; k < m_bodyContactCount; k++) {
final ParticleBodyContact contact = m_bodyContactBuffer[k];
int a = contact.index;
Body b = contact.body;
float w = contact.weight;
float m = contact.mass;
Vec2 n = contact.normal;
Vec2 p = m_positionBuffer.data[a];
final float tempX = p.x - b.m_sweep.c.x;
final float tempY = p.y - b.m_sweep.c.y;
final Vec2 velA = m_velocityBuffer.data[a];
// getLinearVelocityFromWorldPointToOut, with -= velA
float vx = -b.m_angularVelocity * tempY + b.m_linearVelocity.x - velA.x;
float vy = b.m_angularVelocity * tempX + b.m_linearVelocity.y - velA.y;
// done
float vn = vx * n.x + vy * n.y;
if (vn < 0) {
final Vec2 f = tempVec;
f.x = damping * w * m * vn * n.x;
f.y = damping * w * m * vn * n.y;
final float invMass = getParticleInvMass();
velA.x += invMass * f.x;
velA.y += invMass * f.y;
f.x = -f.x;
f.y = -f.y;
b.applyLinearImpulse(f, p, true);
}
}
for (int k = 0; k < m_contactCount; k++) {
final ParticleContact contact = m_contactBuffer[k];
int a = contact.indexA;
int b = contact.indexB;
float w = contact.weight;
Vec2 n = contact.normal;
final Vec2 velA = m_velocityBuffer.data[a];
final Vec2 velB = m_velocityBuffer.data[b];
final float vx = velB.x - velA.x;
final float vy = velB.y - velA.y;
float vn = vx * n.x + vy * n.y;
if (vn < 0) {
float fx = damping * w * vn * n.x;
float fy = damping * w * vn * n.y;
velA.x += fx;
velA.y += fy;
velB.x -= fx;
velB.y -= fy;
}
}
}
use of org.jbox2d.dynamics.Body in project libgdx by libgdx.
the class ParticleSystem method solvePowder.
void solvePowder(final TimeStep step) {
float powderStrength = m_powderStrength * getCriticalVelocity(step);
float minWeight = 1.0f - Settings.particleStride;
for (int k = 0; k < m_bodyContactCount; k++) {
final ParticleBodyContact contact = m_bodyContactBuffer[k];
int a = contact.index;
if ((m_flagsBuffer.data[a] & ParticleType.b2_powderParticle) != 0) {
float w = contact.weight;
if (w > minWeight) {
Body b = contact.body;
float m = contact.mass;
Vec2 p = m_positionBuffer.data[a];
Vec2 n = contact.normal;
final Vec2 f = tempVec;
final Vec2 va = m_velocityBuffer.data[a];
final float inter = powderStrength * m * (w - minWeight);
final float pInvMass = getParticleInvMass();
f.x = inter * n.x;
f.y = inter * n.y;
va.x -= pInvMass * f.x;
va.y -= pInvMass * f.y;
b.applyLinearImpulse(f, p, true);
}
}
}
for (int k = 0; k < m_contactCount; k++) {
final ParticleContact contact = m_contactBuffer[k];
if ((contact.flags & ParticleType.b2_powderParticle) != 0) {
float w = contact.weight;
if (w > minWeight) {
int a = contact.indexA;
int b = contact.indexB;
Vec2 n = contact.normal;
final Vec2 va = m_velocityBuffer.data[a];
final Vec2 vb = m_velocityBuffer.data[b];
final float inter = powderStrength * (w - minWeight);
final float fx = inter * n.x;
final float fy = inter * n.y;
va.x -= fx;
va.y -= fy;
vb.x += fx;
vb.y += fy;
}
}
}
}
Aggregations