use of spacegraph.space3d.phys.Collidable in project narchy by automenta.
the class CompoundCollisionAlgorithm method calculateTimeOfImpact.
@Override
public float calculateTimeOfImpact(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
Collidable colObj = isSwapped ? body1 : body0;
Collidable otherObj = isSwapped ? body0 : body1;
assert (colObj.shape().isCompound());
CompoundShape compoundShape = (CompoundShape) colObj.shape();
// We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
// If both proxies are Compound, we will deal with that directly, by performing sequential/parallel tree traversals
// given Proxy0 and Proxy1, if both have a tree, Tree0 and Tree1, this means:
// determine overlapping nodes of Proxy1 using Proxy0 AABB against Tree1
// then use each overlapping node AABB against Tree0
// and vise versa.
Transform tmpTrans = new Transform();
Transform orgTrans = new Transform();
Transform childTrans = new Transform();
float hitFraction = 1f;
int numChildren = childCollisionAlgorithms.size();
int i;
for (i = 0; i < numChildren; i++) {
// temporarily exchange parent btCollisionShape with childShape, and recurse
CollisionShape childShape = compoundShape.getChildShape(i);
// backup
colObj.getWorldTransform(orgTrans);
compoundShape.getChildTransform(i, childTrans);
// btTransform newChildWorldTrans = orgTrans*childTrans ;
tmpTrans.set(orgTrans);
tmpTrans.mul(childTrans);
colObj.transform(tmpTrans);
CollisionShape tmpShape = colObj.shape();
colObj.internalSetTemporaryCollisionShape(childShape);
// return array[index];
float frac = childCollisionAlgorithms.get(i).calculateTimeOfImpact(colObj, otherObj, dispatchInfo, resultOut);
if (frac < hitFraction) {
hitFraction = frac;
}
// revert back
colObj.internalSetTemporaryCollisionShape(tmpShape);
colObj.transform(orgTrans);
}
return hitFraction;
}
use of spacegraph.space3d.phys.Collidable 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();
}
}
}
use of spacegraph.space3d.phys.Collidable in project narchy by automenta.
the class ConvexPlaneCollisionAlgorithm method init.
public void init(PersistentManifold mf, CollisionAlgorithmConstructionInfo ci, Collidable col0, Collidable col1, boolean isSwapped) {
super.init(ci);
this.ownManifold = false;
this.manifoldPtr = mf;
this.isSwapped = isSwapped;
Collidable convexObj = isSwapped ? col1 : col0;
Collidable planeObj = isSwapped ? col0 : col1;
if (manifoldPtr == null && intersecter.needsCollision(convexObj, planeObj)) {
manifoldPtr = intersecter.getNewManifold(convexObj, planeObj);
ownManifold = true;
}
}
use of spacegraph.space3d.phys.Collidable in project narchy by automenta.
the class DefaultNearCallback method handleCollision.
@Override
public void handleCollision(BroadphasePair collisionPair, DefaultIntersecter dispatcher, DispatcherInfo dispatchInfo) {
Collidable colObj0 = collisionPair.pProxy0.data;
Collidable colObj1 = collisionPair.pProxy1.data;
if (dispatcher.needsCollision(colObj0, colObj1)) {
// dispatcher will keep algorithms persistent in the collision pair
if (collisionPair.algorithm == null) {
collisionPair.algorithm = dispatcher.findAlgorithm(colObj0, colObj1);
}
if (collisionPair.algorithm != null) {
// ManifoldResult contactPointResult = new ManifoldResult(colObj0, colObj1);
contactPointResult.init(colObj0, colObj1);
if (dispatchInfo.dispatchFunc == DispatchFunc.DISPATCH_DISCRETE) {
// discrete collision detection query
collisionPair.algorithm.processCollision(colObj0, colObj1, dispatchInfo, contactPointResult);
} else {
// continuous collision detection query, time of impact (toi)
float toi = collisionPair.algorithm.calculateTimeOfImpact(colObj0, colObj1, dispatchInfo, contactPointResult);
if (dispatchInfo.timeOfImpact > toi) {
dispatchInfo.timeOfImpact = toi;
}
}
}
}
}
use of spacegraph.space3d.phys.Collidable in project narchy by automenta.
the class GhostObject method addOverlappingObjectInternal.
/**
* This method is mainly for expert/internal use only.
*/
public void addOverlappingObjectInternal(Broadphasing otherProxy, Broadphasing thisProxy) {
Collidable otherObject = otherProxy.data;
assert (otherObject != null);
// if this linearSearch becomes too slow (too many overlapping objects) we should add a more appropriate data structure
int index = overlappingObjects.indexOf(otherObject);
if (index == -1) {
// not found
overlappingObjects.add(otherObject);
}
}
Aggregations