Search in sources :

Example 16 with Transform

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();
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) ConvexShape(spacegraph.space3d.phys.shape.ConvexShape) StaticPlaneShape(spacegraph.space3d.phys.shape.StaticPlaneShape) Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 17 with Transform

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);
            }
        }
    }
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3) Quat4f(spacegraph.util.math.Quat4f)

Example 18 with Transform

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);
}
Also used : Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 19 with Transform

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;
}
Also used : Transform(spacegraph.space3d.phys.math.Transform)

Example 20 with Transform

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;
}
Also used : Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Aggregations

Transform (spacegraph.space3d.phys.math.Transform)56 spacegraph.util.math.v3 (spacegraph.util.math.v3)41 Matrix3f (spacegraph.util.math.Matrix3f)11 Collidable (spacegraph.space3d.phys.Collidable)6 Body3D (spacegraph.space3d.phys.Body3D)3 CollisionShape (spacegraph.space3d.phys.shape.CollisionShape)3 Quat4f (spacegraph.util.math.Quat4f)3 CompoundShape (spacegraph.space3d.phys.shape.CompoundShape)2 ConvexShape (spacegraph.space3d.phys.shape.ConvexShape)2 Surface (spacegraph.space2d.Surface)1 SimpleSpatial (spacegraph.space3d.SimpleSpatial)1 ManifoldPoint (spacegraph.space3d.phys.collision.narrow.ManifoldPoint)1 VoronoiSimplexSolver (spacegraph.space3d.phys.collision.narrow.VoronoiSimplexSolver)1 ContactConstraint (spacegraph.space3d.phys.constraint.ContactConstraint)1 Point2PointConstraint (spacegraph.space3d.phys.constraint.Point2PointConstraint)1 SolverConstraint (spacegraph.space3d.phys.constraint.SolverConstraint)1 TypedConstraint (spacegraph.space3d.phys.constraint.TypedConstraint)1 Generic6DofConstraint (spacegraph.space3d.phys.constraint.generic.Generic6DofConstraint)1 CapsuleShape (spacegraph.space3d.phys.shape.CapsuleShape)1 ConcaveShape (spacegraph.space3d.phys.shape.ConcaveShape)1