use of spacegraph.space3d.phys.Collidable 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.Collidable in project narchy by automenta.
the class GhostPairCallback method addOverlappingPair.
@Override
public BroadphasePair addOverlappingPair(Broadphasing proxy0, Broadphasing proxy1) {
Collidable colObj0 = proxy0.data;
Collidable colObj1 = proxy1.data;
GhostObject ghost0 = GhostObject.upcast(colObj0);
GhostObject ghost1 = GhostObject.upcast(colObj1);
if (ghost0 != null) {
ghost0.addOverlappingObjectInternal(proxy1, proxy0);
}
if (ghost1 != null) {
ghost1.addOverlappingObjectInternal(proxy0, proxy1);
}
return null;
}
use of spacegraph.space3d.phys.Collidable in project narchy by automenta.
the class EdgeDirected method solve.
@Override
public void solve(Broadphase b, List<Collidable> objects, float timeStep) {
float a = attraction.floatValue();
for (int i = 0, objectsSize = objects.size(); i < objectsSize; i++) {
Collidable c = objects.get(i);
Spatial A = ((Spatial) c.data());
// TODO abstract the Edges as a feature to optionally add to a TermWidget, not just for ConceptWidgets
if (A instanceof SpaceWidget) {
((SpaceWidget<?>) A).edges().forEach(e -> {
float attraction = e.attraction;
if (attraction > 0) {
SimpleSpatial B = e.tgt();
if ((B.body != null)) {
attract(c, B.body, a * attraction, e.attractionDist);
}
}
});
}
}
super.solve(b, objects, timeStep);
}
use of spacegraph.space3d.phys.Collidable 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.Collidable 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;
}
Aggregations