Search in sources :

Example 1 with PhysCollisionObject

use of ValkyrienWarfareBase.Collision.PhysCollisionObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipPhysicsCollider method doShipCollision.

public void doShipCollision(PhysicsObject toCollideWith) {
    //Don't process collision if either of them are phased
    if (toCollideWith.physicsProcessor instanceof PhysicsCalculationsOrbital) {
        if (((PhysicsCalculationsOrbital) toCollideWith.physicsProcessor).isOrbitalPhased) {
            return;
        }
    }
    if (parent.physicsProcessor instanceof PhysicsCalculationsOrbital) {
        if (((PhysicsCalculationsOrbital) parent.physicsProcessor).isOrbitalPhased) {
            return;
        }
    }
    AxisAlignedBB firstBB = parent.collisionBB;
    AxisAlignedBB secondBB = toCollideWith.collisionBB;
    AxisAlignedBB betweenBB = BigBastardMath.getBetweenAABB(firstBB, secondBB);
    Polygon betweenBBPoly = new Polygon(betweenBB, toCollideWith.coordTransform.wToLTransform);
    List<AxisAlignedBB> bbsInFirst = parent.worldObj.getCollisionBoxes(betweenBBPoly.getEnclosedAABB());
    if (bbsInFirst.isEmpty()) {
        return;
    }
    Vector[] axes = parent.coordTransform.getSeperatingAxisWithShip(toCollideWith);
    // RandomIterator.getRandomIteratorForList(bbsInFirst);
    Iterator<AxisAlignedBB> firstRandIter = bbsInFirst.iterator();
    while (firstRandIter.hasNext()) {
        AxisAlignedBB fromIter = firstRandIter.next();
        Polygon firstInWorld = new Polygon(fromIter, toCollideWith.coordTransform.lToWTransform);
        AxisAlignedBB inWorldAABB = firstInWorld.getEnclosedAABB();
        Polygon inShip2Poly = new Polygon(inWorldAABB, parent.coordTransform.wToLTransform);
        // This is correct
        List<AxisAlignedBB> bbsInSecond = parent.worldObj.getCollisionBoxes(inShip2Poly.getEnclosedAABB());
        // RandomIterator.getRandomIteratorForList(bbsInSecond);
        Iterator<AxisAlignedBB> secondRandIter = bbsInSecond.iterator();
        while (secondRandIter.hasNext()) {
            // System.out.println("test");
            Polygon secondInWorld = new Polygon(secondRandIter.next(), parent.coordTransform.lToWTransform);
            // Both of these are in WORLD coordinates
            Vector firstCenter = firstInWorld.getCenter();
            Vector secondCenter = secondInWorld.getCenter();
            Vector inBodyFirst = new Vector(firstCenter.X - parent.wrapper.posX, firstCenter.Y - parent.wrapper.posY, firstCenter.Z - parent.wrapper.posZ);
            Vector inBodySecond = new Vector(secondCenter.X - toCollideWith.wrapper.posX, secondCenter.Y - toCollideWith.wrapper.posY, secondCenter.Z - toCollideWith.wrapper.posZ);
            Vector velAtFirst = parent.physicsProcessor.getVelocityAtPoint(inBodyFirst);
            Vector velAtSecond = toCollideWith.physicsProcessor.getVelocityAtPoint(inBodySecond);
            velAtFirst.subtract(velAtSecond);
            PhysPolygonCollider polyCol = new PhysPolygonCollider(firstInWorld, secondInWorld, axes);
            if (!polyCol.seperated) {
                Vector speedAtPoint = velAtFirst;
                double xDot = Math.abs(speedAtPoint.X);
                double yDot = Math.abs(speedAtPoint.Y);
                double zDot = Math.abs(speedAtPoint.Z);
                PhysCollisionObject polyColObj = null;
                if (yDot > xDot && yDot > zDot) {
                    // Y speed is greatest
                    if (xDot > zDot) {
                        polyColObj = polyCol.collisions[2];
                    } else {
                        polyColObj = polyCol.collisions[0];
                    }
                } else {
                    if (xDot > zDot) {
                        // X speed is greatest
                        polyColObj = polyCol.collisions[1];
                    } else {
                        // Z speed is greatest
                        polyColObj = polyCol.collisions[1];
                    }
                }
                // PhysCollisionObject polyColObj = polyCol.collisions[1];
                if (polyColObj.penetrationDistance > axisTolerance || polyColObj.penetrationDistance < -axisTolerance) {
                    polyColObj = polyCol.collisions[polyCol.minDistanceIndex];
                }
                // PhysCollisionObject physCol = new PhysCollisionObject(firstInWorld,secondInWorld,polyColObj.axis);
                processCollisionAtPoint(toCollideWith, polyColObj);
                if (Math.abs(polyColObj.movMaxFixMin) > Math.abs(polyColObj.movMinFixMax)) {
                    for (Vector v : polyColObj.movable.vertices) {
                        if (v.dot(polyColObj.axis) == polyColObj.playerMinMax[1]) {
                            polyColObj.firstContactPoint = v;
                        }
                    }
                } else {
                    for (Vector v : polyColObj.movable.vertices) {
                        if (v.dot(polyColObj.axis) == polyColObj.playerMinMax[0]) {
                            polyColObj.firstContactPoint = v;
                        }
                    }
                }
                // physCol.firstContactPoint = physCol.getSecondContactPoint();
                processCollisionAtPoint(toCollideWith, polyColObj);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PhysicsCalculationsOrbital(ValkyrienWarfareBase.Physics.PhysicsCalculationsOrbital) PhysCollisionObject(ValkyrienWarfareBase.Collision.PhysCollisionObject) Polygon(ValkyrienWarfareBase.Collision.Polygon) Vector(ValkyrienWarfareBase.API.Vector) PhysPolygonCollider(ValkyrienWarfareBase.Collision.PhysPolygonCollider)

Example 2 with PhysCollisionObject

use of ValkyrienWarfareBase.Collision.PhysCollisionObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class WorldPhysicsCollider method handleActualCollision.

//Takes the collision data along all axes generated prior, and creates the ideal value that is to be followed
private boolean handleActualCollision(PhysPolygonCollider collider, BlockPos inWorldPos, BlockPos inLocalPos, IBlockState inWorldState, IBlockState inLocalState) {
    PhysCollisionObject toCollideWith = null;
    toCollideWith = collider.collisions[1];
    if (toCollideWith.penetrationDistance > axisTolerance || toCollideWith.penetrationDistance < -axisTolerance) {
        toCollideWith = collider.collisions[collider.minDistanceIndex];
    }
    NestedBoolean didBlockBreakInShip = new NestedBoolean(false);
    NestedBoolean didBlockBreakInWorld = new NestedBoolean(false);
    Vector positionInBody = collider.entity.getCenter();
    positionInBody.subtract(parent.wrapper.posX, parent.wrapper.posY, parent.wrapper.posZ);
    Vector velocityAtPoint = calculator.getVelocityAtPoint(positionInBody);
    double collisionSpeed = velocityAtPoint.dot(toCollideWith.axis);
    double impulseApplied = BlockRammingManager.processBlockRamming(parent.wrapper, collisionSpeed, inLocalState, inWorldState, inLocalPos, inWorldPos, didBlockBreakInShip, didBlockBreakInWorld);
    Vector[] collisionPoints = PolygonCollisionPointFinder.getPointsOfCollisionForPolygons(collider, toCollideWith, null);
    impulseApplied /= collisionPoints.length;
    for (Vector collisionPos : collisionPoints) {
        Vector inBody = collisionPos.getSubtraction(new Vector(parent.wrapper.posX, parent.wrapper.posY, parent.wrapper.posZ));
        inBody.multiply(-1D);
        Vector momentumAtPoint = calculator.getVelocityAtPoint(inBody);
        Vector axis = toCollideWith.axis;
        Vector offsetVector = toCollideWith.getResponse();
        calculateCollisionImpulseForce(inBody, momentumAtPoint, axis, offsetVector, didBlockBreakInShip.getValue(), didBlockBreakInWorld.getValue(), impulseApplied);
    }
    if (didBlockBreakInShip.getValue()) {
        worldObj.destroyBlock(inLocalPos, true);
    }
    if (didBlockBreakInWorld.getValue()) {
        worldObj.destroyBlock(inWorldPos, true);
        return true;
    }
    return false;
}
Also used : PhysCollisionObject(ValkyrienWarfareBase.Collision.PhysCollisionObject) Vector(ValkyrienWarfareBase.API.Vector) NestedBoolean(ValkyrienWarfareBase.PhysCollision.BlockRammingManager.NestedBoolean)

Aggregations

Vector (ValkyrienWarfareBase.API.Vector)2 PhysCollisionObject (ValkyrienWarfareBase.Collision.PhysCollisionObject)2 PhysPolygonCollider (ValkyrienWarfareBase.Collision.PhysPolygonCollider)1 Polygon (ValkyrienWarfareBase.Collision.Polygon)1 NestedBoolean (ValkyrienWarfareBase.PhysCollision.BlockRammingManager.NestedBoolean)1 PhysicsCalculationsOrbital (ValkyrienWarfareBase.Physics.PhysicsCalculationsOrbital)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1