Search in sources :

Example 46 with Transform

use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.

the class OrbMouse method mouseGrabOn.

private ClosestRay mouseGrabOn() {
    if (pickConstraint == null && pickedBody != null) {
        pickedBody.setActivationState(Collidable.DISABLE_DEACTIVATION);
        Body3D body = pickedBody;
        v3 pickPos = new v3(rayCallback.hitPointWorld);
        Transform tmpTrans = body.transform;
        tmpTrans.inverse();
        v3 localPivot = new v3(pickPos);
        tmpTrans.transform(localPivot);
        Point2PointConstraint p2p = new Point2PointConstraint(body, localPivot);
        p2p.impulseClamp = 3f;
        // save mouse position for dragging
        gOldPickingPos.set(rayCallback.rayToWorld);
        v3 eyePos = new v3(space.camPos);
        v3 tmp = new v3();
        tmp.sub(pickPos, eyePos);
        gOldPickingDist = tmp.length();
        // very weak constraint for picking
        p2p.tau = 0.1f;
        space.dyn.addConstraint(p2p);
        pickConstraint = p2p;
    // body.setActivationState(Collidable.DISABLE_DEACTIVATION);
    // v3 pickPos = v(rayCallback.hitPointWorld);
    // 
    // Transform tmpTrans = body.getCenterOfMassTransform(new Transform());
    // tmpTrans.inverse();
    // v3 localPivot = v(pickPos);
    // tmpTrans.transform(localPivot);
    // // save mouse position for dragging
    // gOldPickingPos.set(rayCallback.rayToWorld);
    // v3 eyePos = v(space.camPos);
    // v3 tmp = v();
    // tmp.sub(pickPos, eyePos);
    // gOldPickingDist = tmp.length();
    // 
    // 
    // // other exclusions?
    // if (!(body.isStaticObject() || body.isKinematicObject())) {
    // pickedBody = body;
    // 
    // 
    // Point2PointConstraint p2p = new Point2PointConstraint(body, localPivot);
    // space.dyn.addConstraint(p2p);
    // pickConstraint = p2p;
    // 
    // // very weak constraint for picking
    // p2p.tau = 0.02f;
    // } else {
    // if (directDrag == null) {
    // directDrag = body;
    // 
    // }
    // }
    }
    return rayCallback;
// }
}
Also used : Point2PointConstraint(spacegraph.space3d.phys.constraint.Point2PointConstraint) Body3D(spacegraph.space3d.phys.Body3D) Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 47 with Transform

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

Example 48 with Transform

use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.

the class Dbvt method collideTT.

public static void collideTT(Node root0, Transform xform0, Node root1, Transform xform1, ICollide policy) {
    Transform xform = new Transform();
    xform.inverse(xform0);
    xform.mul(xform1);
    collideTT(root0, root1, xform, policy);
}
Also used : Transform(spacegraph.space3d.phys.math.Transform)

Example 49 with Transform

use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.

the class Collisions method convexSweepTest.

/**
 * convexTest performs a swept convex cast on all objects in the {@link Collisions}, and calls the resultCallback
 * This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
 */
public void convexSweepTest(ConvexShape castShape, Transform convexFromWorld, Transform convexToWorld, ConvexResultCallback resultCallback) {
    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 R = new Transform();
    v3 collisionObjectAabbMin = new v3();
    v3 collisionObjectAabbMax = new v3();
    float[] hitLambda = new float[1];
    // go over all objects, and if the ray intersects their aabb + cast shape aabb,
    // do a ray-shape query using convexCaster (CCD)
    v3 hitNormal = new v3();
    List<Collidable> collidables = collidables();
    for (int i = 0, collidablesSize = collidables.size(); i < collidablesSize; i++) {
        Collidable collidable = collidables.get(i);
        // only perform raycast if filterMask matches
        if (resultCallback.needsCollision(collidable.broadphase)) {
            // RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
            Transform S = collidable.transform;
            CollisionShape shape = collidable.shape();
            shape.getAabb(S, collisionObjectAabbMin, collisionObjectAabbMax);
            AabbUtil2.aabbExpand(collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
            // could use resultCallback.closestHitFraction, but needs testing
            hitLambda[0] = 1f;
            // may not be necessary
            hitNormal.zero();
            if (AabbUtil2.rayAabb(convexFromWorld, convexToWorld, collisionObjectAabbMin, collisionObjectAabbMax, hitLambda, hitNormal)) {
                objectQuerySingle(castShape, convexFromTrans, convexToTrans, collidable, shape, S, resultCallback, dispatchInfo.allowedCcdPenetration);
            }
        }
    }
}
Also used : Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3) Quat4f(spacegraph.util.math.Quat4f)

Example 50 with Transform

use of spacegraph.space3d.phys.math.Transform in project narchy by automenta.

the class Collisions method rayTestSingle.

public static void rayTestSingle(Transform rayFromTrans, Transform rayToTrans, Collidable collidable, CollisionShape collisionShape, Transform colObjWorldTransform, VoronoiSimplexSolver simplexSolver, RayResultCallback resultCallback) {
    if (collisionShape.isConvex()) {
        ConvexCast.CastResult castResult = new ConvexCast.CastResult();
        castResult.fraction = resultCallback.closestHitFraction;
        ConvexShape convexShape = (ConvexShape) collisionShape;
        // #define USE_SUBSIMPLEX_CONVEX_CAST 1
        // #ifdef USE_SUBSIMPLEX_CONVEX_CAST
        SubsimplexConvexCast convexCaster = new SubsimplexConvexCast(pointShape, convexShape, simplexSolver);
        if (convexCaster.calcTimeOfImpact(rayFromTrans, rayToTrans, colObjWorldTransform, colObjWorldTransform, castResult)) {
            // add hit
            if (castResult.normal.lengthSquared() > 0.0001f) {
                if (castResult.fraction < resultCallback.closestHitFraction) {
                    // #ifdef USE_SUBSIMPLEX_CONVEX_CAST
                    // rotate normal into worldspace
                    rayFromTrans.basis.transform(castResult.normal);
                    // #endif //USE_SUBSIMPLEX_CONVEX_CAST
                    castResult.normal.normalize();
                    LocalRayResult localRayResult = new LocalRayResult(collidable, null, castResult.normal, castResult.fraction);
                    boolean normalInWorldSpace = true;
                    resultCallback.addSingleResult(localRayResult, normalInWorldSpace);
                }
            }
        }
    } else {
        if (collisionShape.isConcave()) {
            if (collisionShape.getShapeType() == BroadphaseNativeType.TRIANGLE_MESH_SHAPE_PROXYTYPE) {
                // optimized version for BvhTriangleMeshShape
                BvhTriangleMeshShape triangleMesh = (BvhTriangleMeshShape) collisionShape;
                Transform worldTocollisionObject = new Transform();
                worldTocollisionObject.inverse(colObjWorldTransform);
                v3 rayFromLocal = new v3(rayFromTrans);
                worldTocollisionObject.transform(rayFromLocal);
                v3 rayToLocal = new v3(rayToTrans);
                worldTocollisionObject.transform(rayToLocal);
                BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collidable, triangleMesh);
                rcb.hitFraction = resultCallback.closestHitFraction;
                triangleMesh.performRaycast(rcb, rayFromLocal, rayToLocal);
            } else {
                ConcaveShape triangleMesh = (ConcaveShape) collisionShape;
                Transform worldTocollisionObject = new Transform();
                worldTocollisionObject.inverse(colObjWorldTransform);
                v3 rayFromLocal = new v3(rayFromTrans);
                worldTocollisionObject.transform(rayFromLocal);
                v3 rayToLocal = new v3(rayToTrans);
                worldTocollisionObject.transform(rayToLocal);
                BridgeTriangleRaycastCallback rcb = new BridgeTriangleRaycastCallback(rayFromLocal, rayToLocal, resultCallback, collidable, triangleMesh);
                rcb.hitFraction = resultCallback.closestHitFraction;
                v3 rayAabbMinLocal = new v3(rayFromLocal);
                VectorUtil.setMin(rayAabbMinLocal, rayToLocal);
                v3 rayAabbMaxLocal = new v3(rayFromLocal);
                VectorUtil.setMax(rayAabbMaxLocal, rayToLocal);
                triangleMesh.processAllTriangles(rcb, rayAabbMinLocal, rayAabbMaxLocal);
            }
        } else {
            // todo: use AABB tree or other BVH acceleration structure!
            if (collisionShape.isCompound()) {
                CompoundShape compoundShape = (CompoundShape) collisionShape;
                int i = 0;
                Transform childTrans = new Transform();
                for (i = 0; i < compoundShape.getNumChildShapes(); i++) {
                    compoundShape.getChildTransform(i, childTrans);
                    CollisionShape childCollisionShape = compoundShape.getChildShape(i);
                    Transform childWorldTrans = new Transform(colObjWorldTransform);
                    childWorldTrans.mul(childTrans);
                    // replace collision shape so that callback can determine the triangle
                    CollisionShape saveCollisionShape = collidable.shape();
                    collidable.internalSetTemporaryCollisionShape(childCollisionShape);
                    simplexSolver.reset();
                    rayTestSingle(rayFromTrans, rayToTrans, collidable, childCollisionShape, childWorldTrans, simplexSolver, resultCallback);
                    // restore
                    collidable.internalSetTemporaryCollisionShape(saveCollisionShape);
                }
            }
        }
    }
}
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