Search in sources :

Example 21 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class IBlockForceProvider method getBlockForceInWorldSpace.

/**
 * The World space version of the force vector, calculated by default from the Ship space
 * vector, do not override unless you have a good reason to.
 */
@Nullable
default Vector3dc getBlockForceInWorldSpace(World world, BlockPos pos, IBlockState state, PhysicsObject physicsObject, double secondsToApply) {
    Vector3dc toReturn = getBlockForceInShipSpace(world, pos, state, physicsObject, secondsToApply);
    if (toReturn == null) {
        return null;
    }
    if (shouldLocalForceBeRotated(world, pos, state, secondsToApply)) {
        ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentTickTransform();
        Vector3d rotated = new Vector3d(toReturn);
        shipTransform.transformDirection(rotated, TransformType.SUBSPACE_TO_GLOBAL);
        return rotated;
    }
    return toReturn;
}
Also used : Vector3dc(org.joml.Vector3dc) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) Nullable(javax.annotation.Nullable)

Example 22 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysObjectRenderManager method renderDebugInfo.

/**
 * Renders bounding boxes for this ship's AABB and center of mass relative to the offset
 * (probably the negative player's position). Used in F3+D
 */
public void renderDebugInfo(double offsetX, double offsetY, double offsetZ) {
    GlStateManager.pushMatrix();
    AxisAlignedBB shipBB = parent.getShipBB().offset(offsetX, offsetY, offsetZ);
    ShipTransform renderTransform = parent.getShipTransformationManager().getRenderTransform();
    Vector3dc centerOfMass = parent.getShipData().getInertiaData().getGameTickCenterOfMass();
    Vector3d centerOfMassPos = new Vector3d(centerOfMass);
    parent.getShipTransformationManager().getRenderTransform().transformPosition(centerOfMassPos, TransformType.SUBSPACE_TO_GLOBAL);
    AxisAlignedBB centerOfMassBB = new AxisAlignedBB(JOML.toMinecraft(centerOfMassPos), JOML.toMinecraft(centerOfMassPos)).grow(.1).offset(offsetX, offsetY, offsetZ);
    GlStateManager.depthMask(false);
    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    GlStateManager.disableCull();
    GlStateManager.disableBlend();
    // Draw the bounding box for the ship.
    RenderGlobal.drawSelectionBoundingBox(shipBB, 1.0F, 1.0F, 1.0F, 1.0F);
    // region Render claimed chunks
    if (VSConfig.renderShipChunkClaimsInDebug) {
        GlStateManager.pushMatrix();
        GlStateManager.translate((float) renderTransform.getPosX() + offsetX, (float) renderTransform.getPosY() + offsetY, (float) renderTransform.getPosZ() + offsetZ);
        Vector3dc angles = renderTransform.getSubspaceToGlobal().getEulerAnglesZYX(new Vector3d());
        GlStateManager.rotate((float) Math.toDegrees(angles.z()), 0, 0, 1);
        GlStateManager.rotate((float) Math.toDegrees(angles.y()), 0, 1, 0);
        GlStateManager.rotate((float) Math.toDegrees(angles.x()), 1, 0, 0);
        for (ChunkPos claimedChunk : parent.getChunkClaim()) {
            AxisAlignedBB claimBB = new AxisAlignedBB(claimedChunk.getXStart() + .1, renderTransform.getCenterCoord().y() - 8 + 0.1, claimedChunk.getZStart() + .1, claimedChunk.getXEnd() + .9, renderTransform.getCenterCoord().y() + 8 - .1, claimedChunk.getZEnd() + .9);
            claimBB = claimBB.offset(-renderTransform.getCenterCoord().x(), -renderTransform.getCenterCoord().y(), -renderTransform.getCenterCoord().z());
            RenderGlobal.drawSelectionBoundingBox(claimBB, 0, 1.0F, 0, 1.0F);
        }
        GlStateManager.popMatrix();
    }
    // endregion
    // Draw the center of mass bounding box.
    GlStateManager.disableDepth();
    RenderGlobal.drawSelectionBoundingBox(centerOfMassBB, 0, 0, 1.0F, 1.0F);
    GlStateManager.enableDepth();
    GlStateManager.enableTexture2D();
    GlStateManager.enableLighting();
    GlStateManager.enableCull();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    // Draw a text box that shows the numerical value of the center of mass.
    String centerOfMassStr = "Center of Mass: " + (new Vector3d(centerOfMass)).toString(new DecimalFormat("############.##"));
    renderTextBox(centerOfMassStr, renderTransform.getPosX(), renderTransform.getPosY() + .5, renderTransform.getPosZ(), offsetX, offsetY, offsetZ);
    String massStr = String.format("Mass: %.2f", parent.getShipData().getInertiaData().getGameTickMass());
    renderTextBox(massStr, renderTransform.getPosX(), renderTransform.getPosY() + 1, renderTransform.getPosZ(), offsetX, offsetY, offsetZ);
    GlStateManager.popMatrix();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vector3dc(org.joml.Vector3dc) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) DecimalFormat(java.text.DecimalFormat) ChunkPos(net.minecraft.util.math.ChunkPos)

Example 23 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MainCommand method teleportShipToPosition.

private static void teleportShipToPosition(final ShipData ship, final Vec3d position, final ICommandSender sender) {
    try {
        final World world = sender.getEntityWorld();
        final WorldServerShipManager shipManager = ValkyrienUtils.getServerShipManager(world);
        final PhysicsObject shipObject = shipManager.getPhysObjectFromUUID(ship.getUuid());
        // Create the new ship transform that moves the ship to this position
        final ShipTransform shipTransform = ship.getShipTransform();
        final ShipTransform newTransform = new ShipTransform(JOML.convert(position), shipTransform.getCenterCoord());
        if (shipObject != null) {
            // The ship already exists in the world, so we need to update the physics transform as well
            final PhysicsCalculations physicsCalculations = shipObject.getPhysicsCalculations();
            physicsCalculations.setForceToUseGameTransform(true);
            // Also update the transform in the ShipTransformationManager
            shipObject.setForceToUseShipDataTransform(true);
            shipObject.setTicksSinceShipTeleport(0);
        }
        // Update the ship transform of the ship data.
        ship.setPhysicsEnabled(false);
        ship.setPrevTickShipTransform(newTransform);
        ship.setShipTransform(newTransform);
        System.out.println(String.format("Teleporting ship %s to %s", ship.getName(), position.toString()));
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) World(net.minecraft.world.World) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) PhysicsCalculations(org.valkyrienskies.mod.common.physics.PhysicsCalculations) WorldServerShipManager(org.valkyrienskies.mod.common.ships.ship_world.WorldServerShipManager)

Example 24 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsCalculations method generatePhysicsTransform.

public void generatePhysicsTransform() {
    // Create a new physics transform.
    ShipTransform parentTransform = getParent().getShipData().getShipTransform();
    physRotation = parentTransform.getSubspaceToGlobal().getNormalizedRotation(new Quaterniond());
    physX = parentTransform.getPosX();
    physY = parentTransform.getPosY();
    physZ = parentTransform.getPosZ();
    physCenterOfMass = parentTransform.getCenterCoord();
    ShipTransform physicsTransform = new ShipTransform(physX, physY, physZ, physRotation, physCenterOfMass);
    getParent().getShipTransformationManager().setCurrentPhysicsTransform(physicsTransform);
    // We're doing this afterwards to prevent from prevPhysicsTransform being null.
    getParent().getShipTransformationManager().updatePreviousPhysicsTransform();
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Quaterniond(org.joml.Quaterniond)

Example 25 with ShipTransform

use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipCollisionTask method checkPosition.

public void checkPosition(int x, int y, int z, int positionHash) {
    if (!toTask.getParent().getChunkClaim().containsChunk(x >> 4, z >> 4)) {
        return;
    }
    final Chunk chunkIn = toTask.getParent().getChunkAt(x >> 4, z >> 4);
    y = Math.max(0, Math.min(y, 255));
    ExtendedBlockStorage storage = chunkIn.storageArrays[y >> 4];
    if (storage != null) {
        ITerrainOctreeProvider provider = (ITerrainOctreeProvider) storage.data;
        IBitOctree octree = provider.getSolidOctree();
        if (octree.get(x & 15, y & 15, z & 15)) {
            IBlockState inLocalState = chunkIn.getBlockState(x, y, z);
            inLocalPos.setPos(x, y, z);
            final ShipTransform shipTransform = toTask.getParent().getShipTransformationManager().getCurrentPhysicsTransform();
            final Vector3dc shipBlockInGlobal = shipTransform.transformPositionNew(temp0.set(inLocalPos.getX() + .5, inLocalPos.getY() + .5, inLocalPos.getZ() + .5), TransformType.SUBSPACE_TO_GLOBAL);
            final double distanceSq = shipBlockInGlobal.distanceSquared(mutablePos.getX() + .5, mutablePos.getY() + .5, mutablePos.getZ() + .5);
            // If it is less than sqrt(3) then collision is possible.
            if (distanceSq < 3) {
                CollisionInformationHolder holder = new CollisionInformationHolder(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inWorldState, inLocalState);
                collisionInformationGenerated.add(holder);
            }
        }
    }
}
Also used : Vector3dc(org.joml.Vector3dc) IBlockState(net.minecraft.block.state.IBlockState) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ITerrainOctreeProvider(org.valkyrienskies.mod.common.util.datastructures.ITerrainOctreeProvider) IBitOctree(org.valkyrienskies.mod.common.util.datastructures.IBitOctree) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage)

Aggregations

ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)32 Vector3d (org.joml.Vector3d)18 Vector3dc (org.joml.Vector3dc)15 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)9 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 World (net.minecraft.world.World)7 ShipData (org.valkyrienskies.mod.common.ships.ShipData)6 UUID (java.util.UUID)4 Nullable (javax.annotation.Nullable)4 BlockPos (net.minecraft.util.math.BlockPos)4 Vec3d (net.minecraft.util.math.Vec3d)4 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)4 IBlockState (net.minecraft.block.state.IBlockState)3 Entity (net.minecraft.entity.Entity)3 Chunk (net.minecraft.world.chunk.Chunk)3 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)3 DecimalFormat (java.text.DecimalFormat)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)2