Search in sources :

Example 1 with NestedBoolean

use of ValkyrienWarfareBase.PhysCollision.BlockRammingManager.NestedBoolean 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)1 PhysCollisionObject (ValkyrienWarfareBase.Collision.PhysCollisionObject)1 NestedBoolean (ValkyrienWarfareBase.PhysCollision.BlockRammingManager.NestedBoolean)1