本文整理汇总了Java中org.jbox2d.common.MathUtils.min方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.min方法的具体用法?Java MathUtils.min怎么用?Java MathUtils.min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jbox2d.common.MathUtils
的用法示例。
在下文中一共展示了MathUtils.min方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PulleyJoint
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* @param argWorldPool
* @param def
*/
public PulleyJoint(IWorldPool argWorldPool, PulleyJointDef def) {
super(argWorldPool, def);
m_groundAnchor1.set(def.groundAnchorA);
m_groundAnchor2.set(def.groundAnchorB);
m_localAnchor1.set(def.localAnchorA);
m_localAnchor2.set(def.localAnchorB);
assert (def.ratio != 0.0f);
m_ratio = def.ratio;
m_constant = def.lengthA + m_ratio * def.lengthB;
m_maxLength1 = MathUtils.min(def.maxLengthA, m_constant - m_ratio * MIN_PULLEY_LENGTH);
m_maxLength2 = MathUtils.min(def.maxLengthB, (m_constant - MIN_PULLEY_LENGTH) / m_ratio);
m_impulse = 0.0f;
m_limitImpulse1 = 0.0f;
m_limitImpulse2 = 0.0f;
}
示例2: PulleyJoint
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* @param argWorldPool
* @param def
*/
public PulleyJoint(WorldPool argWorldPool, PulleyJointDef def) {
super(argWorldPool, def);
m_groundAnchor1.set(def.groundAnchorA);
m_groundAnchor2.set(def.groundAnchorB);
m_localAnchor1.set(def.localAnchorA);
m_localAnchor2.set(def.localAnchorB);
assert (def.ratio != 0.0f);
m_ratio = def.ratio;
m_constant = def.lengthA + m_ratio * def.lengthB;
m_maxLength1 = MathUtils.min(def.maxLengthA, m_constant - m_ratio * MIN_PULLEY_LENGTH);
m_maxLength2 = MathUtils.min(def.maxLengthB, (m_constant - MIN_PULLEY_LENGTH) / m_ratio);
m_impulse = 0.0f;
m_limitImpulse1 = 0.0f;
m_limitImpulse2 = 0.0f;
}
示例3: computePolygonSeparation
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void computePolygonSeparation(EPAxis axis) {
axis.type = EPAxis.Type.UNKNOWN;
axis.index = -1;
axis.separation = -Float.MAX_VALUE;
perp.x = -m_normal.y;
perp.y = m_normal.x;
for (int i = 0; i < m_polygonB.count; ++i) {
Vec2 normalB = m_polygonB.normals[i];
Vec2 vB = m_polygonB.vertices[i];
n.x = -normalB.x;
n.y = -normalB.y;
// float s1 = Vec2.dot(n, temp.set(vB).subLocal(m_v1));
// float s2 = Vec2.dot(n, temp.set(vB).subLocal(m_v2));
float tempx = vB.x - m_v1.x;
float tempy = vB.y - m_v1.y;
float s1 = n.x * tempx + n.y * tempy;
tempx = vB.x - m_v2.x;
tempy = vB.y - m_v2.y;
float s2 = n.x * tempx + n.y * tempy;
float s = MathUtils.min(s1, s2);
if (s > m_radius) {
// No collision
axis.type = EPAxis.Type.EDGE_B;
axis.index = i;
axis.separation = s;
return;
}
// Adjacency
if (n.x * perp.x + n.y * perp.y >= 0.0f) {
if (Vec2.dot(temp.set(n).subLocal(m_upperLimit), m_normal) < -Settings.angularSlop) {
continue;
}
} else {
if (Vec2.dot(temp.set(n).subLocal(m_lowerLimit), m_normal) < -Settings.angularSlop) {
continue;
}
}
if (s > axis.separation) {
axis.type = EPAxis.Type.EDGE_B;
axis.index = i;
axis.separation = s;
}
}
}
示例4: joinParticleGroups
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
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);
int particleFlags = 0;
for (int i = groupA.m_firstIndex; i < groupB.m_lastIndex; i++) {
particleFlags |= m_flagsBuffer.data[i];
}
updateContacts(true);
if ((particleFlags & k_pairFlags) != 0) {
for (int k = 0; k < m_contactCount; k++) {
final ParticleContact contact = m_contactBuffer[k];
int a = contact.indexA;
int b = contact.indexB;
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (groupA.m_firstIndex <= a && a < groupA.m_lastIndex && groupB.m_firstIndex <= b
&& b < groupB.m_lastIndex) {
if (m_pairCount >= m_pairCapacity) {
int oldCapacity = m_pairCapacity;
int newCapacity =
m_pairCount != 0 ? 2 * m_pairCount : Settings.minParticleBufferCapacity;
m_pairBuffer =
BufferUtils.reallocateBuffer(Pair.class, m_pairBuffer, oldCapacity, newCapacity);
m_pairCapacity = newCapacity;
}
Pair pair = m_pairBuffer[m_pairCount];
pair.indexA = a;
pair.indexB = b;
pair.flags = contact.flags;
pair.strength = MathUtils.min(groupA.m_strength, groupB.m_strength);
pair.distance = MathUtils.distance(m_positionBuffer.data[a], m_positionBuffer.data[b]);
m_pairCount++;
}
}
}
if ((particleFlags & k_triadFlags) != 0) {
VoronoiDiagram diagram = new VoronoiDiagram(groupB.m_lastIndex - groupA.m_firstIndex);
for (int i = groupA.m_firstIndex; i < groupB.m_lastIndex; i++) {
if ((m_flagsBuffer.data[i] & ParticleType.b2_zombieParticle) == 0) {
diagram.addGenerator(m_positionBuffer.data[i], i);
}
}
diagram.generate(getParticleStride() / 2);
JoinParticleGroupsCallback callback = new JoinParticleGroupsCallback();
callback.system = this;
callback.groupA = groupA;
callback.groupB = groupB;
diagram.getNodes(callback);
}
for (int i = groupB.m_firstIndex; i < groupB.m_lastIndex; i++) {
m_groupBuffer[i] = groupA;
}
int groupFlags = groupA.m_groupFlags | groupB.m_groupFlags;
groupA.m_groupFlags = groupFlags;
groupA.m_lastIndex = groupB.m_lastIndex;
groupB.m_firstIndex = groupB.m_lastIndex;
destroyParticleGroup(groupB);
if ((groupFlags & ParticleGroupType.b2_solidParticleGroup) != 0) {
computeDepthForGroup(groupA);
}
}
示例5: raycast
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* @param callback
* @param point1
* @param point2
*/
public void raycast(ParticleRaycastCallback callback, final Vec2 point1, final Vec2 point2) {
if (m_proxyCount == 0) {
return;
}
int firstProxy =
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;
// solving the following equation:
// ((1-t)*point1+t*point2-position)^2=diameter^2
// where t is a potential fraction
final float vx = point2.x - point1.x;
final float vy = point2.y - point1.y;
float v2 = vx * vx + vy * vy;
if (v2 == 0) v2 = Float.MAX_VALUE;
for (int proxy = firstProxy; proxy < lastProxy; ++proxy) {
int i = m_proxyBuffer[proxy].index;
final Vec2 posI = m_positionBuffer.data[i];
final float px = point1.x - posI.x;
final float py = point1.y - posI.y;
float pv = px * vx + py * vy;
float p2 = px * px + py * py;
float determinant = pv * pv - v2 * (p2 - m_squaredDiameter);
if (determinant >= 0) {
float sqrtDeterminant = MathUtils.sqrt(determinant);
// find a solution between 0 and fraction
float t = (-pv - sqrtDeterminant) / v2;
if (t > fraction) {
continue;
}
if (t < 0) {
t = (-pv + sqrtDeterminant) / v2;
if (t < 0 || t > fraction) {
continue;
}
}
final Vec2 n = tempVec;
tempVec.x = px + t * vx;
tempVec.y = py + t * vy;
n.normalize();
final Vec2 point = tempVec2;
point.x = point1.x + t * vx;
point.y = point1.y + t * vy;
float f = callback.reportParticle(i, point, n, t);
fraction = MathUtils.min(fraction, f);
if (fraction <= 0) {
break;
}
}
}
}
示例6: callback
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void callback(int a, int b, int c) {
// Create a triad if it will contain particles from both groups.
int countA =
((a < groupB.m_firstIndex) ? 1 : 0) + ((b < groupB.m_firstIndex) ? 1 : 0)
+ ((c < groupB.m_firstIndex) ? 1 : 0);
if (countA > 0 && countA < 3) {
int af = system.m_flagsBuffer.data[a];
int bf = system.m_flagsBuffer.data[b];
int cf = system.m_flagsBuffer.data[c];
if ((af & bf & cf & k_triadFlags) != 0) {
final Vec2 pa = system.m_positionBuffer.data[a];
final Vec2 pb = system.m_positionBuffer.data[b];
final Vec2 pc = system.m_positionBuffer.data[c];
final float dabx = pa.x - pb.x;
final float daby = pa.y - pb.y;
final float dbcx = pb.x - pc.x;
final float dbcy = pb.y - pc.y;
final float dcax = pc.x - pa.x;
final float dcay = pc.y - pa.y;
float maxDistanceSquared = Settings.maxTriadDistanceSquared * system.m_squaredDiameter;
if (dabx * dabx + daby * daby < maxDistanceSquared
&& dbcx * dbcx + dbcy * dbcy < maxDistanceSquared
&& dcax * dcax + dcay * dcay < maxDistanceSquared) {
if (system.m_triadCount >= system.m_triadCapacity) {
int oldCapacity = system.m_triadCapacity;
int newCapacity =
system.m_triadCount != 0
? 2 * system.m_triadCount
: Settings.minParticleBufferCapacity;
system.m_triadBuffer =
BufferUtils.reallocateBuffer(Triad.class, system.m_triadBuffer, oldCapacity,
newCapacity);
system.m_triadCapacity = newCapacity;
}
Triad triad = system.m_triadBuffer[system.m_triadCount];
triad.indexA = a;
triad.indexB = b;
triad.indexC = c;
triad.flags = af | bf | cf;
triad.strength = MathUtils.min(groupA.m_strength, groupB.m_strength);
final float midPointx = (float) 1 / 3 * (pa.x + pb.x + pc.x);
final float midPointy = (float) 1 / 3 * (pa.y + pb.y + pc.y);
triad.pa.x = pa.x - midPointx;
triad.pa.y = pa.y - midPointy;
triad.pb.x = pb.x - midPointx;
triad.pb.y = pb.y - midPointy;
triad.pc.x = pc.x - midPointx;
triad.pc.y = pc.y - midPointy;
triad.ka = -(dcax * dabx + dcay * daby);
triad.kb = -(dabx * dbcx + daby * dbcy);
triad.kc = -(dbcx * dcax + dbcy * dcay);
triad.s = Vec2.cross(pa, pb) + Vec2.cross(pb, pc) + Vec2.cross(pc, pa);
system.m_triadCount++;
}
}
}
}
示例7: record
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void record(float value) {
longAvg = longAvg * (1 - LONG_FRACTION) + value * LONG_FRACTION;
shortAvg = shortAvg * (1 - SHORT_FRACTION) + value * SHORT_FRACTION;
min = MathUtils.min(value, min);
max = MathUtils.max(value, max);
}
示例8: solveVelocityConstraints
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public void solveVelocityConstraints(final SolverData data) {
Vec2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vec2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
// Cdot = dot(u, v + cross(w, r))
Vec2 vpA = pool.popVec2();
Vec2 vpB = pool.popVec2();
Vec2 temp = pool.popVec2();
Vec2.crossToOutUnsafe(wA, m_rA, vpA);
vpA.addLocal(vA);
Vec2.crossToOutUnsafe(wB, m_rB, vpB);
vpB.addLocal(vB);
float C = m_length - m_maxLength;
float Cdot = Vec2.dot(m_u, temp.set(vpB).subLocal(vpA));
// Predictive constraint.
if (C < 0.0f) {
Cdot += data.step.inv_dt * C;
}
float impulse = -m_mass * Cdot;
float oldImpulse = m_impulse;
m_impulse = MathUtils.min(0.0f, m_impulse + impulse);
impulse = m_impulse - oldImpulse;
float Px = impulse * m_u.x;
float Py = impulse * m_u.y;
vA.x -= m_invMassA * Px;
vA.y -= m_invMassA * Py;
wA -= m_invIA * (m_rA.x * Py - m_rA.y * Px);
vB.x += m_invMassB * Px;
vB.y += m_invMassB * Py;
wB += m_invIB * (m_rB.x * Py - m_rB.y * Px);
pool.pushVec2(3);
// data.velocities[m_indexA].v = vA;
data.velocities[m_indexA].w = wA;
// data.velocities[m_indexB].v = vB;
data.velocities[m_indexB].w = wB;
}
示例9: solvePositionConstraints
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Sequential solver.
*/
public final boolean solvePositionConstraints(float baumgarte){
float minSeparation = 0.0f;
for (int i = 0; i < m_constraintCount; ++i){
final ContactConstraint c = m_constraints[i];
final Body bodyA = c.bodyA;
final Body bodyB = c.bodyB;
final float invMassA = bodyA.m_mass * bodyA.m_invMass;
final float invIA = bodyA.m_mass * bodyA.m_invI;
final float invMassB = bodyB.m_mass * bodyB.m_invMass;
final float invIB = bodyB.m_mass * bodyB.m_invI;
// Solve normal constraints
for (int j = 0; j < c.pointCount; ++j){
final PositionSolverManifold psm = psolver;
psm.initialize(c, j);
final Vec2 normal = psm.normal;
final Vec2 point = psm.point;
final float separation = psm.separation;
rA.set(point).subLocal(bodyA.m_sweep.c);
rB.set(point).subLocal(bodyB.m_sweep.c);
// Track max constraint error.
minSeparation = MathUtils.min(minSeparation, separation);
// Prevent large corrections and allow slop.
final float C = MathUtils.clamp(baumgarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0f);
// Compute the effective mass.
final float rnA = Vec2.cross(rA, normal);
final float rnB = Vec2.cross(rB, normal);
final float K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;
// Compute normal impulse
final float impulse = K > 0.0f ? - C / K : 0.0f;
P.set(normal).mulLocal(impulse);
temp1.set(P).mulLocal(invMassA);
bodyA.m_sweep.c.subLocal(temp1);;
bodyA.m_sweep.a -= invIA * Vec2.cross(rA, P);
bodyA.synchronizeTransform();
temp1.set(P).mulLocal(invMassB);
bodyB.m_sweep.c.addLocal(temp1);
bodyB.m_sweep.a += invIB * Vec2.cross(rB, P);
bodyB.synchronizeTransform();
}
}
// We can't expect minSpeparation >= -linearSlop because we don't
// push the separation above -linearSlop.
return minSeparation >= -1.5f * Settings.linearSlop;
}
示例10: solve
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Perform one solver iteration. Returns true if converged.
* @param baumgarte
* @return
*/
public boolean solve(float baumgarte){
// Push out the toi body to provide clearance for further simulation.
float minSeparation = 0f;
for (int i = 0; i < m_count; ++i){
TOIConstraint c = m_constraints[i];
Body bodyA = c.bodyA;
Body bodyB = c.bodyB;
float massA = bodyA.m_mass;
float massB = bodyB.m_mass;
// Only the TOI body should move.
if (bodyA == m_toiBody){
massB = 0.0f;
}
else{
massA = 0.0f;
}
float invMassA = massA * bodyA.m_invMass;
float invIA = massA * bodyA.m_invI;
float invMassB = massB * bodyB.m_invMass;
float invIB = massB * bodyB.m_invI;
// Solve normal constraints
for (int j = 0; j < c.pointCount; ++j){
psm.initialize(c, j);
Vec2 normal = psm.normal;
Vec2 point = psm.point;
float separation = psm.separation;
rA.set(point).subLocal(bodyA.m_sweep.c);
rB.set(point).subLocal(bodyB.m_sweep.c);
// Track max constraint error.
minSeparation = MathUtils.min(minSeparation, separation);
// Prevent large corrections and allow slop.
float C = MathUtils.clamp(baumgarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0f);
// Compute the effective mass.
float rnA = Vec2.cross(rA, normal);
float rnB = Vec2.cross(rB, normal);
float K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;
// Compute normal impulse
float impulse = K > 0.0f ? - C / K : 0.0f;
P.set(normal).mulLocal(impulse);
temp.set(P).mulLocal(invMassA);
bodyA.m_sweep.c.subLocal(temp);
bodyA.m_sweep.a -= invIA * Vec2.cross(rA, P);
bodyA.synchronizeTransform();
temp.set(P).mulLocal(invMassB);
bodyB.m_sweep.c.addLocal(temp);
bodyB.m_sweep.a += invIB * Vec2.cross(rB, P);
bodyB.synchronizeTransform();
}
}
// We can't expect minSpeparation >= -_linearSlop because we don't
// push the separation above -_linearSlop.
return minSeparation >= -1.5f * Settings.linearSlop;
}
示例11: solveVelocityConstraints
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
@Override
public void solveVelocityConstraints(final SolverData data) {
Vector2 vA = data.velocities[m_indexA].v;
float wA = data.velocities[m_indexA].w;
Vector2 vB = data.velocities[m_indexB].v;
float wB = data.velocities[m_indexB].w;
// Cdot = dot(u, v + cross(w, r))
Vector2 vpA = pool.popVec2();
Vector2 vpB = pool.popVec2();
Vector2 temp = pool.popVec2();
Vector2.crossToOutUnsafe(wA, m_rA, vpA);
vpA.addLocal(vA);
Vector2.crossToOutUnsafe(wB, m_rB, vpB);
vpB.addLocal(vB);
float C = m_length - m_maxLength;
float Cdot = Vector2.dot(m_u, temp.set(vpB).subLocal(vpA));
// Predictive constraint.
if (C < 0.0f) {
Cdot += data.step.inv_dt * C;
}
float impulse = -m_mass * Cdot;
float oldImpulse = m_impulse;
m_impulse = MathUtils.min(0.0f, m_impulse + impulse);
impulse = m_impulse - oldImpulse;
float Px = impulse * m_u.x;
float Py = impulse * m_u.y;
vA.x -= m_invMassA * Px;
vA.y -= m_invMassA * Py;
wA -= m_invIA * (m_rA.x * Py - m_rA.y * Px);
vB.x += m_invMassB * Px;
vB.y += m_invMassB * Py;
wB += m_invIB * (m_rB.x * Py - m_rB.y * Px);
pool.pushVec2(3);
// data.velocities[m_indexA].v = vA;
data.velocities[m_indexA].w = wA;
// data.velocities[m_indexB].v = vB;
data.velocities[m_indexB].w = wB;
}
示例12: solvePositionConstraints
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Sequential solver.
*/
public final boolean solvePositionConstraints(float baumgarte){
float minSeparation = 0.0f;
for (int i = 0; i < m_constraintCount; ++i){
final ContactConstraint c = m_constraints[i];
final Body bodyA = c.bodyA;
final Body bodyB = c.bodyB;
final float invMassA = bodyA.m_mass * bodyA.m_invMass;
final float invIA = bodyA.m_mass * bodyA.m_invI;
final float invMassB = bodyB.m_mass * bodyB.m_invMass;
final float invIB = bodyB.m_mass * bodyB.m_invI;
// Solve normal constraints
for (int j = 0; j < c.pointCount; ++j){
final PositionSolverManifold psm = psolver;
psm.initialize(c, j);
final Vec2 normal = psm.normal;
final Vec2 point = psm.point;
final float separation = psm.separation;
rA.set(point).subLocal(bodyA.m_sweep.c);
rB.set(point).subLocal(bodyB.m_sweep.c);
// Track max constraint error.
minSeparation = MathUtils.min(minSeparation, separation);
// Prevent large corrections and allow slop.
final float C = MathUtils.clamp(baumgarte * (separation + Settings.linearSlop), -Settings.maxLinearCorrection, 0.0f);
// Compute the effective mass.
final float rnA = Vec2.cross(rA, normal);
final float rnB = Vec2.cross(rB, normal);
final float K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;
// Compute normal impulse
final float impulse = K > 0.0f ? - C / K : 0.0f;
P.set(normal).mulLocal(impulse);
temp1.set(P).mulLocal(invMassA);
bodyA.m_sweep.c.subLocal(temp1);
bodyA.m_sweep.a -= invIA * Vec2.cross(rA, P);
bodyA.synchronizeTransform();
temp1.set(P).mulLocal(invMassB);
bodyB.m_sweep.c.addLocal(temp1);
bodyB.m_sweep.a += invIB * Vec2.cross(rB, P);
bodyB.synchronizeTransform();
}
}
// We can't expect minSpeparation >= -linearSlop because we don't
// push the separation above -linearSlop.
return minSeparation >= -1.5f * Settings.linearSlop;
}
示例13: computePolygonSeparation
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
public void computePolygonSeparation(EPAxis axis) {
axis.type = EPAxis.Type.UNKNOWN;
axis.index = -1;
axis.separation = -Float.MAX_VALUE;
perp.x = -m_normal.y;
perp.y = m_normal.x;
for (int i = 0; i < m_polygonB.count; ++i) {
Vec2 normalB = m_polygonB.normals[i];
Vec2 vB = m_polygonB.vertices[i];
n.x = -normalB.x;
n.y = -normalB.y;
// float s1 = Vec2.dot(n, temp.set(vB).subLocal(m_v1));
// float s2 = Vec2.dot(n, temp.set(vB).subLocal(m_v2));
float tempx = vB.x - m_v1.x;
float tempy = vB.y - m_v1.y;
float s1 = n.x * tempx + n.y * tempy;
tempx = vB.x - m_v2.x;
tempy = vB.y - m_v2.y;
float s2 = n.x * tempx + n.y * tempy;
float s = MathUtils.min(s1, s2);
if (s > m_radius) {
// No collision
axis.type = EPAxis.Type.EDGE_B;
axis.index = i;
axis.separation = s;
return;
}
// Adjacency
if (n.x * perp.x + n.y * perp.y >= 0.0f) {
if (Vec2.dot(temp.set(n).subLocal(m_upperLimit), m_normal) < -Settings.angularSlop) {
continue;
}
} else {
if (Vec2.dot(temp.set(n).subLocal(m_lowerLimit), m_normal) < -Settings.angularSlop) {
continue;
}
}
if (s > axis.separation) {
axis.type = EPAxis.Type.EDGE_B;
axis.index = i;
axis.separation = s;
}
}
}
示例14: solvePositionConstraints
import org.jbox2d.common.MathUtils; //导入方法依赖的package包/类
/**
* Sequential solver.
*/
public final boolean solvePositionConstraints() {
float minSeparation = 0.0f;
for (int i = 0; i < m_count; ++i) {
ContactPositionConstraint pc = m_positionConstraints[i];
int indexA = pc.indexA;
int indexB = pc.indexB;
float mA = pc.invMassA;
float iA = pc.invIA;
Vec2 localCenterA = pc.localCenterA;
float mB = pc.invMassB;
float iB = pc.invIB;
Vec2 localCenterB = pc.localCenterB;
int pointCount = pc.pointCount;
Vec2 cA = m_positions[indexA].c;
float aA = m_positions[indexA].a;
Vec2 cB = m_positions[indexB].c;
float aB = m_positions[indexB].a;
// Solve normal constraints
for (int j = 0; j < pointCount; ++j) {
xfA.q.set(aA);
xfB.q.set(aB);
Rot.mulToOutUnsafe(xfA.q, localCenterA, xfA.p);
xfA.p.negateLocal().addLocal(cA);
Rot.mulToOutUnsafe(xfB.q, localCenterB, xfB.p);
xfB.p.negateLocal().addLocal(cB);
final PositionSolverManifold psm = psolver;
psm.initialize(pc, xfA, xfB, j);
final Vec2 normal = psm.normal;
final Vec2 point = psm.point;
final float separation = psm.separation;
rA.set(point).subLocal(cA);
rB.set(point).subLocal(cB);
// Track max constraint error.
minSeparation = MathUtils.min(minSeparation, separation);
// Prevent large corrections and allow slop.
final float C =
MathUtils.clamp(Settings.baumgarte * (separation + Settings.linearSlop),
-Settings.maxLinearCorrection, 0.0f);
// Compute the effective mass.
final float rnA = Vec2.cross(rA, normal);
final float rnB = Vec2.cross(rB, normal);
final float K = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
// Compute normal impulse
final float impulse = K > 0.0f ? -C / K : 0.0f;
P.set(normal).mulLocal(impulse);
cA.subLocal(temp.set(P).mulLocal(mA));
aA -= iA * Vec2.cross(rA, P);
cB.addLocal(temp.set(P).mulLocal(mB));
aB += iB * Vec2.cross(rB, P);
}
// m_positions[indexA].c.set(cA);
m_positions[indexA].a = aA;
// m_positions[indexB].c.set(cB);
m_positions[indexB].a = aB;
}
// We can't expect minSpeparation >= -linearSlop because we don't
// push the separation above -linearSlop.
return minSeparation >= -3.0f * Settings.linearSlop;
}