use of spacegraph.space3d.phys.shape.CollisionShape in project narchy by automenta.
the class ConvexTriangleCallback method processTriangle.
@Override
public void processTriangle(v3[] triangle, int partId, int triangleIndex) {
// just for debugging purposes
// printf("triangle %d",m_triangleCount++);
// aabb filter is already applied!
ci.intersecter1 = intersecter;
Collidable ob = triBody;
if (convexBody.shape().isConvex()) {
tm.init(triangle[0], triangle[1], triangle[2]);
tm.setMargin(collisionMarginTriangle);
CollisionShape tmpShape = ob.shape();
ob.internalSetTemporaryCollisionShape(tm);
CollisionAlgorithm colAlgo = ci.intersecter1.findAlgorithm(convexBody, triBody, manifoldPtr);
// this should use the btDispatcher, so the actual registered algorithm is used
// btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
resultOut.setShapeIdentifiers(-1, -1, partId, triangleIndex);
// cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
colAlgo.processCollision(convexBody, triBody, dispatchInfoPtr, resultOut);
// colAlgo.destroy();
Intersecter.freeCollisionAlgorithm(colAlgo);
ob.internalSetTemporaryCollisionShape(tmpShape);
}
}
use of spacegraph.space3d.phys.shape.CollisionShape in project narchy by automenta.
the class CompoundCollisionAlgorithm method init.
public void init(CollisionAlgorithmConstructionInfo ci, Collidable body0, Collidable body1, boolean isSwapped) {
super.init(ci);
this.isSwapped = isSwapped;
Collidable colObj = isSwapped ? body1 : body0;
Collidable otherObj = isSwapped ? body0 : body1;
assert (colObj.shape().isCompound());
CompoundShape compoundShape = (CompoundShape) colObj.shape();
int numChildren = compoundShape.getNumChildShapes();
int i;
// childCollisionAlgorithms.resize(numChildren);
for (i = 0; i < numChildren; i++) {
CollisionShape tmpShape = colObj.shape();
CollisionShape childShape = compoundShape.getChildShape(i);
colObj.internalSetTemporaryCollisionShape(childShape);
childCollisionAlgorithms.add(ci.intersecter1.findAlgorithm(colObj, otherObj));
colObj.internalSetTemporaryCollisionShape(tmpShape);
}
}
use of spacegraph.space3d.phys.shape.CollisionShape in project narchy by automenta.
the class CompoundCollisionAlgorithm method processCollision.
@Override
public void processCollision(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();
Transform orgInterpolationTrans = new Transform();
Transform newChildWorldTrans = new Transform();
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);
colObj.getInterpolationWorldTransform(orgInterpolationTrans);
compoundShape.getChildTransform(i, childTrans);
newChildWorldTrans.mul(orgTrans, childTrans);
colObj.transform(newChildWorldTrans);
colObj.setInterpolationWorldTransform(newChildWorldTrans);
// the contactpoint is still projected back using the original inverted worldtrans
CollisionShape tmpShape = colObj.shape();
colObj.internalSetTemporaryCollisionShape(childShape);
// return array[index];
childCollisionAlgorithms.get(i).processCollision(colObj, otherObj, dispatchInfo, resultOut);
// revert back
colObj.internalSetTemporaryCollisionShape(tmpShape);
colObj.transform(orgTrans);
colObj.setInterpolationWorldTransform(orgInterpolationTrans);
}
}
use of spacegraph.space3d.phys.shape.CollisionShape 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.shape.CollisionShape in project narchy by automenta.
the class ConvexTriangleCallback method setTimeStepAndCounters.
public void setTimeStepAndCounters(float collisionMarginTriangle, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
this.dispatchInfoPtr = dispatchInfo;
this.collisionMarginTriangle = collisionMarginTriangle;
this.resultOut = resultOut;
// recalc aabbs
Transform convexInTriangleSpace = new Transform();
triBody.getWorldTransform(convexInTriangleSpace);
convexInTriangleSpace.inverse();
convexInTriangleSpace.mul(convexBody.getWorldTransform(new Transform()));
CollisionShape convexShape = convexBody.shape();
// CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
convexShape.getAabb(convexInTriangleSpace, aabbMin, aabbMax);
float extraMargin = collisionMarginTriangle;
v3 extra = new v3();
extra.set(extraMargin, extraMargin, extraMargin);
aabbMax.add(extra);
aabbMin.sub(extra);
}
Aggregations