use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.
the class ConvexPlaneCollisionAlgorithm method processCollision.
@Override
public void processCollision(Collidable body0, Collidable body1, DispatcherInfo dispatchInfo, ManifoldResult resultOut) {
if (manifoldPtr == null) {
return;
}
Transform tmpTrans = new Transform();
Collidable convexObj = isSwapped ? body1 : body0;
Collidable planeObj = isSwapped ? body0 : body1;
ConvexShape convexShape = (ConvexShape) convexObj.shape();
StaticPlaneShape planeShape = (StaticPlaneShape) planeObj.shape();
boolean hasCollision = false;
v3 planeNormal = planeShape.getPlaneNormal(new v3());
float planeConstant = planeShape.getPlaneConstant();
Transform planeInConvex = new Transform();
convexObj.getWorldTransform(planeInConvex);
planeInConvex.inverse();
planeInConvex.mul(planeObj.getWorldTransform(tmpTrans));
Transform convexInPlaneTrans = new Transform();
convexInPlaneTrans.inverse(planeObj.getWorldTransform(tmpTrans));
convexInPlaneTrans.mul(convexObj.getWorldTransform(tmpTrans));
v3 tmp = new v3();
tmp.negate(planeNormal);
planeInConvex.basis.transform(tmp);
v3 vtx = convexShape.localGetSupportingVertex(tmp, new v3());
v3 vtxInPlane = new v3(vtx);
convexInPlaneTrans.transform(vtxInPlane);
float distance = (planeNormal.dot(vtxInPlane) - planeConstant);
v3 vtxInPlaneProjected = new v3();
tmp.scale(distance, planeNormal);
vtxInPlaneProjected.sub(vtxInPlane, tmp);
v3 vtxInPlaneWorld = new v3(vtxInPlaneProjected);
planeObj.getWorldTransform(tmpTrans).transform(vtxInPlaneWorld);
float breakingThresh = manifoldPtr.getContactBreakingThreshold();
hasCollision = distance < breakingThresh;
resultOut.setPersistentManifold(manifoldPtr);
if (hasCollision) {
// report a contact. internally this will be kept persistent, and contact reduction is done
v3 normalOnSurfaceB = new v3(planeNormal);
planeObj.getWorldTransform(tmpTrans).basis.transform(normalOnSurfaceB);
v3 pOnB = new v3(vtxInPlaneWorld);
resultOut.addContactPoint(normalOnSurfaceB, pOnB, distance, breakingThresh);
}
if (ownManifold) {
if (manifoldPtr.numContacts() != 0) {
resultOut.refreshContactPoints();
}
}
}
use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.
the class GhostObject method convexSweepTest.
public void convexSweepTest(ConvexShape castShape, Transform convexFromWorld, Transform convexToWorld, Collisions.ConvexResultCallback resultCallback, float allowedCcdPenetration) {
Transform convexFromTrans = new Transform();
Transform convexToTrans = new Transform();
convexFromTrans.set(convexFromWorld);
convexToTrans.set(convexToWorld);
v3 castShapeAabbMin = new v3();
v3 castShapeAabbMax = new v3();
// compute AABB that encompasses angular movement
v3 linVel = new v3();
v3 angVel = new v3();
TransformUtil.calculateVelocity(convexFromTrans, convexToTrans, 1f, linVel, angVel);
Transform R = new Transform();
R.setIdentity();
R.setRotation(convexFromTrans.getRotation(new Quat4f()));
castShape.calculateTemporalAabb(R, linVel, angVel, 1f, castShapeAabbMin, castShapeAabbMax);
Transform tmpTrans = new Transform();
// do a ray-shape query using convexCaster (CCD)
for (int i = 0; i < overlappingObjects.size(); i++) {
// return array[index];
Collidable collidable = overlappingObjects.get(i);
// only perform raycast if filterMask matches
if (resultCallback.needsCollision(collidable.broadphase)) {
// RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
v3 collisionObjectAabbMin = new v3();
v3 collisionObjectAabbMax = new v3();
collidable.shape().getAabb(collidable.getWorldTransform(tmpTrans), collisionObjectAabbMin, collisionObjectAabbMax);
AabbUtil2.aabbExpand(collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
// could use resultCallback.closestHitFraction, but needs testing
float[] hitLambda = { 1f };
v3 hitNormal = new v3();
if (AabbUtil2.rayAabb(convexFromWorld, convexToWorld, collisionObjectAabbMin, collisionObjectAabbMax, hitLambda, hitNormal)) {
Collisions.objectQuerySingle(castShape, convexFromTrans, convexToTrans, collidable, collidable.shape(), collidable.getWorldTransform(tmpTrans), resultCallback, allowedCcdPenetration);
}
}
}
}
use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.
the class CapsuleShape method calculateLocalInertia.
@Override
public void calculateLocalInertia(float mass, v3 inertia) {
// as an approximation, take the inertia of the box that bounds the spheres
Transform ident = new Transform();
ident.setIdentity();
float radius = getRadius();
v3 halfExtents = new v3();
halfExtents.set(radius, radius, radius);
VectorUtil.setCoord(halfExtents, upAxis, radius + getHalfHeight());
float margin = BulletGlobals.CONVEX_DISTANCE_MARGIN;
float lx = 2f * (halfExtents.x + margin);
float ly = 2f * (halfExtents.y + margin);
float lz = 2f * (halfExtents.z + margin);
float x2 = lx * lx;
float y2 = ly * ly;
float z2 = lz * lz;
float scaledmass = mass * 0.08333333f;
inertia.x = scaledmass * (y2 + z2);
inertia.y = scaledmass * (x2 + z2);
inertia.z = scaledmass * (x2 + y2);
}
use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.
the class CompoundShape method getChildTransform.
public Transform getChildTransform(int index, Transform out) {
// return array[index];
Transform t = children.get(index).transform;
out.set(t);
return out;
}
use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.
the class CollisionShape method getBoundingSphere.
public float getBoundingSphere(v3 center) {
v3 aabbMin = new v3(), aabbMax = new v3();
getAabb(new Transform().setIdentity(), aabbMin, aabbMax);
v3 tmp = new v3();
tmp.sub(aabbMax, aabbMin);
float radius = tmp.length() * 0.5f;
if (center != null) {
tmp.add(aabbMin, aabbMax);
center.scale(0.5f, tmp);
}
return radius;
}
Aggregations