use of spacegraph.space3d.phys.shape.ConcaveShape in project narchy by automenta.
the class ConvexConcaveCollisionAlgorithm method calculateTimeOfImpact.
@Override
public float calculateTimeOfImpact(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
v3 tmp = new v3();
Collidable convexbody = isSwapped ? body1 : body0;
Collidable triBody = isSwapped ? body0 : body1;
// quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)
// only perform CCD above a certain threshold, this prevents blocking on the long run
// because object in a blocked ccd state (hitfraction<1) get their linear velocity halved each frame...
tmp.sub(convexbody.getInterpolationWorldTransform(new Transform()), convexbody.getWorldTransform(new Transform()));
float squareMot0 = tmp.lengthSquared();
if (squareMot0 < convexbody.getCcdSquareMotionThreshold()) {
return 1f;
}
Transform tmpTrans = new Transform();
// const btVector3& from = convexbody->m_worldTransform.getOrigin();
// btVector3 to = convexbody->m_interpolationWorldTransform.getOrigin();
// todo: only do if the motion exceeds the 'radius'
Transform triInv = triBody.getWorldTransform(new Transform());
triInv.inverse();
Transform convexFromLocal = new Transform();
convexFromLocal.mul(triInv, convexbody.getWorldTransform(tmpTrans));
Transform convexToLocal = new Transform();
convexToLocal.mul(triInv, convexbody.getInterpolationWorldTransform(tmpTrans));
if (triBody.shape().isConcave()) {
v3 rayAabbMin = new v3(convexFromLocal);
VectorUtil.setMin(rayAabbMin, convexToLocal);
v3 rayAabbMax = new v3(convexFromLocal);
VectorUtil.setMax(rayAabbMax, convexToLocal);
float ccdRadius0 = convexbody.getCcdSweptSphereRadius();
tmp.set(ccdRadius0, ccdRadius0, ccdRadius0);
rayAabbMin.sub(tmp);
rayAabbMax.add(tmp);
// is this available?
float curHitFraction = 1f;
LocalTriangleSphereCastCallback raycastCallback = new LocalTriangleSphereCastCallback(convexFromLocal, convexToLocal, convexbody.getCcdSweptSphereRadius(), curHitFraction);
raycastCallback.hitFraction = convexbody.getHitFraction();
Collidable concavebody = triBody;
ConcaveShape triangleMesh = (ConcaveShape) concavebody.shape();
if (triangleMesh != null) {
triangleMesh.processAllTriangles(raycastCallback, rayAabbMin, rayAabbMax);
}
if (raycastCallback.hitFraction < convexbody.getHitFraction()) {
convexbody.setHitFraction(raycastCallback.hitFraction);
return raycastCallback.hitFraction;
}
}
return 1f;
}
use of spacegraph.space3d.phys.shape.ConcaveShape in project narchy by automenta.
the class ConvexConcaveCollisionAlgorithm method processCollision.
@Override
public void processCollision(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
Collidable convexBody = isSwapped ? body1 : body0;
Collidable triBody = isSwapped ? body0 : body1;
if (triBody.shape().isConcave()) {
Collidable triOb = triBody;
ConcaveShape concaveShape = (ConcaveShape) triOb.shape();
if (convexBody.shape().isConvex()) {
float collisionMarginTriangle = concaveShape.getMargin();
resultOut.setPersistentManifold(btConvexTriangleCallback.manifoldPtr);
btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle, dispatchInfo, resultOut);
// Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
// m_dispatcher->clearManifold(m_btConvexTriangleCallback.m_manifoldPtr);
btConvexTriangleCallback.manifoldPtr.setBodies(convexBody, triBody);
concaveShape.processAllTriangles(btConvexTriangleCallback, btConvexTriangleCallback.getAabbMin(new v3()), btConvexTriangleCallback.getAabbMax(new v3()));
resultOut.refreshContactPoints();
}
}
}
Aggregations