java中contact方法_Java ContactListener.endContact方法代码示例

import org.jbox2d.callbacks.ContactListener; //导入方法依赖的package包/类

public void update(ContactListener listener) {

oldManifold.set(m_manifold);

// Re-enable this contact.

m_flags |= ENABLED_FLAG;

boolean touching = false;

boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;

boolean sensorA = m_fixtureA.isSensor();

boolean sensorB = m_fixtureB.isSensor();

boolean sensor = sensorA || sensorB;

Body bodyA = m_fixtureA.getBody();

Body bodyB = m_fixtureB.getBody();

Transform xfA = bodyA.getTransform();

Transform xfB = bodyB.getTransform();

// log.debug("TransformA: "+xfA);

// log.debug("TransformB: "+xfB);

if (sensor) {

Shape shapeA = m_fixtureA.getShape();

Shape shapeB = m_fixtureB.getShape();

touching = pool.getCollision().testOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB);

// Sensors don't generate manifolds.

m_manifold.pointCount = 0;

} else {

evaluate(m_manifold, xfA, xfB);

touching = m_manifold.pointCount > 0;

// Match old contact ids to new contact ids and copy the

// stored impulses to warm start the solver.

for (int i = 0; i < m_manifold.pointCount; ++i) {

ManifoldPoint mp2 = m_manifold.points[i];

mp2.normalImpulse = 0.0f;

mp2.tangentImpulse = 0.0f;

ContactID id2 = mp2.id;

for (int j = 0; j < oldManifold.pointCount; ++j) {

ManifoldPoint mp1 = oldManifold.points[j];

if (mp1.id.isEqual(id2)) {

mp2.normalImpulse = mp1.normalImpulse;

mp2.tangentImpulse = mp1.tangentImpulse;

break;

}

}

}

if (touching != wasTouching) {

bodyA.setAwake(true);

bodyB.setAwake(true);

}

}

if (touching) {

m_flags |= TOUCHING_FLAG;

} else {

m_flags &= ~TOUCHING_FLAG;

}

if (listener == null) {

return;

}

if (wasTouching == false && touching == true) {

listener.beginContact(this);

}

if (wasTouching == true && touching == false) {

listener.endContact(this);

}

if (sensor == false && touching) {

listener.preSolve(this, oldManifold);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值