Search in sources :

Example 1 with Polygon

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

the class CallRunnerClient method getRenderBoundingBox.

public static AxisAlignedBB getRenderBoundingBox(TileEntity tile) {
    AxisAlignedBB toReturn = tile.getRenderBoundingBox();
    //    	System.out.println("running");
    BlockPos pos = tile.getPos();
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(Minecraft.getMinecraft().theWorld, pos);
    if (wrapper != null) {
        Polygon inWorldPoly = new Polygon(toReturn, wrapper.wrapping.coordTransform.lToWTransform);
        return inWorldPoly.getEnclosedAABB();
    }
    return toReturn;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) BlockPos(net.minecraft.util.math.BlockPos) Polygon(ValkyrienWarfareBase.Collision.Polygon)

Example 2 with Polygon

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

the class CallRunner method onGetEntitiesInAABBexcluding.

public static List<Entity> onGetEntitiesInAABBexcluding(World world, @Nullable Entity entityIn, AxisAlignedBB boundingBox, @Nullable Predicate<? super Entity> predicate) {
    if ((boundingBox.maxX - boundingBox.minX) * (boundingBox.maxZ - boundingBox.minZ) > 1000000D) {
        return new ArrayList();
    }
    //Prevents the players item pickup AABB from merging with a PhysicsWrapperEntity AABB
    if (entityIn instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityIn;
        if (player.isRiding() && !player.getRidingEntity().isDead && player.getRidingEntity() instanceof PhysicsWrapperEntity) {
            AxisAlignedBB axisalignedbb = player.getEntityBoundingBox().union(player.getRidingEntity().getEntityBoundingBox()).expand(1.0D, 0.0D, 1.0D);
            if (boundingBox.equals(axisalignedbb)) {
                boundingBox = player.getEntityBoundingBox().expand(1.0D, 0.5D, 1.0D);
            }
        }
    }
    List toReturn = world.getEntitiesInAABBexcluding(entityIn, boundingBox, predicate);
    BlockPos pos = new BlockPos((boundingBox.minX + boundingBox.maxX) / 2D, (boundingBox.minY + boundingBox.maxY) / 2D, (boundingBox.minZ + boundingBox.maxZ) / 2D);
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(world, pos);
    if (wrapper != null) {
        Polygon poly = new Polygon(boundingBox, wrapper.wrapping.coordTransform.lToWTransform);
        boundingBox = poly.getEnclosedAABB().contract(.3D);
        toReturn.addAll(world.getEntitiesInAABBexcluding(entityIn, boundingBox, predicate));
    }
    return toReturn;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ArrayList(java.util.ArrayList) PlayerList(net.minecraft.server.management.PlayerList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) Polygon(ValkyrienWarfareBase.Collision.Polygon) EntityPolygon(ValkyrienWarfareBase.Collision.EntityPolygon)

Example 3 with Polygon

use of ValkyrienWarfareBase.Collision.Polygon 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 4 with Polygon

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

the class WorldPhysicsCollider method handleLikelyCollision.

//Tests two block positions directly against each other, and figures out whether a collision is occuring or not
private boolean handleLikelyCollision(BlockPos inWorldPos, BlockPos inLocalPos, IBlockState inWorldState, IBlockState inLocalState) {
    // System.out.println("Handling a likely collision");
    AxisAlignedBB inLocalBB = new AxisAlignedBB(inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inLocalPos.getX() + 1, inLocalPos.getY() + 1, inLocalPos.getZ() + 1);
    AxisAlignedBB inGlobalBB = new AxisAlignedBB(inWorldPos.getX(), inWorldPos.getY(), inWorldPos.getZ(), inWorldPos.getX() + 1, inWorldPos.getY() + 1, inWorldPos.getZ() + 1);
    //This changes the box bounding box to the real bounding box, not sure if this is better or worse for this mod
    //		List<AxisAlignedBB> colBB = worldObj.getCollisionBoxes(inLocalBB);
    //		inLocalBB = colBB.get(0);
    Polygon shipInWorld = new Polygon(inLocalBB, parent.coordTransform.lToWTransform);
    Polygon worldPoly = new Polygon(inGlobalBB);
    PhysPolygonCollider collider = new PhysPolygonCollider(shipInWorld, worldPoly, parent.coordTransform.normals);
    if (!collider.seperated) {
        return handleActualCollision(collider, inWorldPos, inLocalPos, inWorldState, inLocalState);
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Polygon(ValkyrienWarfareBase.Collision.Polygon) PhysPolygonCollider(ValkyrienWarfareBase.Collision.PhysPolygonCollider)

Example 5 with Polygon

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

the class PhysicsWrapperEntity method updatePassenger.

@Override
public void updatePassenger(Entity passenger) {
    Vector inLocal = wrapping.getLocalPositionForEntity(passenger);
    if (inLocal != null) {
        Vector newEntityPosition = new Vector(inLocal);
        float f = passenger.width / 2.0F;
        float f1 = passenger.height;
        AxisAlignedBB inLocalAABB = new AxisAlignedBB(newEntityPosition.X - (double) f, newEntityPosition.Y, newEntityPosition.Z - (double) f, newEntityPosition.X + (double) f, newEntityPosition.Y + (double) f1, newEntityPosition.Z + (double) f);
        wrapping.coordTransform.fromLocalToGlobal(newEntityPosition);
        passenger.setPosition(newEntityPosition.X, newEntityPosition.Y, newEntityPosition.Z);
        Polygon entityBBPoly = new Polygon(inLocalAABB, wrapping.coordTransform.lToWTransform);
        AxisAlignedBB newEntityBB = entityBBPoly.getEnclosedAABB();
        passenger.setEntityBoundingBox(newEntityBB);
        if (passenger instanceof EntityMountingWeaponBase) {
            passenger.onUpdate();
            for (Entity e : passenger.riddenByEntities) {
                if (wrapping.isEntityFixed(e)) {
                    Vector inLocalAgain = wrapping.getLocalPositionForEntity(e);
                    if (inLocalAgain != null) {
                        Vector newEntityPositionAgain = new Vector(inLocalAgain);
                        wrapping.coordTransform.fromLocalToGlobal(newEntityPositionAgain);
                        e.setPosition(newEntityPositionAgain.X, newEntityPositionAgain.Y, newEntityPositionAgain.Z);
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Polygon(ValkyrienWarfareBase.Collision.Polygon) Vector(ValkyrienWarfareBase.API.Vector) EntityMountingWeaponBase(ValkyrienWarfareCombat.Entity.EntityMountingWeaponBase)

Aggregations

Polygon (ValkyrienWarfareBase.Collision.Polygon)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)3 BlockPos (net.minecraft.util.math.BlockPos)3 Vector (ValkyrienWarfareBase.API.Vector)2 EntityPolygon (ValkyrienWarfareBase.Collision.EntityPolygon)2 PhysPolygonCollider (ValkyrienWarfareBase.Collision.PhysPolygonCollider)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PlayerList (net.minecraft.server.management.PlayerList)2 PhysCollisionObject (ValkyrienWarfareBase.Collision.PhysCollisionObject)1 PhysicsCalculationsOrbital (ValkyrienWarfareBase.Physics.PhysicsCalculationsOrbital)1 EntityMountingWeaponBase (ValkyrienWarfareCombat.Entity.EntityMountingWeaponBase)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1