Search in sources :

Example 41 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ShipPilot method processControlMessage.

public void processControlMessage(PilotControlsMessage message, EntityPlayerMP sender) {
    final double pilotYaw = -initialYaw - 90;
    // Linear velocity
    final Vector3d newTargetLinearVelocity = new Vector3d();
    if (message.airshipForward_KeyDown) {
        newTargetLinearVelocity.x += MAX_LINEAR_VELOCITY;
    }
    if (message.airshipBackward_KeyDown) {
        newTargetLinearVelocity.x -= MAX_LINEAR_VELOCITY;
    }
    if (message.airshipSprinting) {
        newTargetLinearVelocity.mul(2);
    }
    newTargetLinearVelocity.rotateAxis(Math.toRadians(pilotYaw), 0, 1, 0);
    // Angular velocity
    final Vector3d newTargetAngularVelocity = new Vector3d();
    if (message.airshipLeft_KeyDown) {
        newTargetAngularVelocity.y += MAX_ANGULAR_VELOCITY;
    }
    if (message.airshipRight_KeyDown) {
        newTargetAngularVelocity.y -= MAX_ANGULAR_VELOCITY;
    }
    // Update the target velocities
    targetLinearVelocity = newTargetLinearVelocity;
    targetAngularVelocity = newTargetAngularVelocity;
// Check if we need to stop piloting
}
Also used : Vector3d(org.joml.Vector3d)

Example 42 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemShipTracker method onItemRightClick.

public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) {
    if (!worldIn.isRemote) {
        final ItemStack heldItemStack = player.getHeldItem(hand);
        final NBTTagCompound stackTagCompound;
        if (heldItemStack.hasTagCompound()) {
            stackTagCompound = heldItemStack.stackTagCompound;
        } else {
            stackTagCompound = new NBTTagCompound();
        }
        if (stackTagCompound.hasKey(NBT_DATA_KEY)) {
            // Tell the player the ship location
            final UUID shipUUID = UUID.fromString(stackTagCompound.getString(NBT_DATA_KEY));
            final Optional<ShipData> shipDataOptional = ValkyrienUtils.getQueryableData(worldIn).getShip(shipUUID);
            if (shipDataOptional.isPresent()) {
                final ShipData shipData = shipDataOptional.get();
                final ShipTransform currentTransform = shipData.getShipTransform();
                final Vector3d shipPosition = new Vector3d(currentTransform.getPosX(), currentTransform.getPosY(), currentTransform.getPosZ());
                // Only print up to 2 digits after the decimal place
                final String shipPositionString = shipPosition.toString(new DecimalFormat("############.##"));
                player.sendMessage(new TextComponentString(String.format("The ship %s is currently at %s.", shipData.getName(), shipPositionString)));
            } else {
                player.sendMessage(new TextComponentString(String.format("No ship with UUID %s found! Maybe it was destroyed.", shipUUID.toString())));
            }
        } else {
            player.sendMessage(new TextComponentString("Not tracking any ships. Right click on a ship to track it."));
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) DecimalFormat(java.text.DecimalFormat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 43 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PlayerMovementDataGenerator method generatePlayerMovementDataForClient.

/**
 * Only works on the client.
 */
public static PlayerMovementData generatePlayerMovementDataForClient() {
    final EntityPlayerSP entityPlayer = Minecraft.getMinecraft().player;
    final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(entityPlayer);
    final ShipData lastTouchedShip = entityShipMovementData.getLastTouchedShip();
    final UUID lastTouchedShipId = lastTouchedShip != null ? lastTouchedShip.getUuid() : null;
    final Vector3d playerPosInLocal = new Vector3d(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ);
    final Vector3d playerLookInLocal = JOML.convert(entityPlayer.getLook(1));
    final boolean onGround = entityPlayer.onGround;
    if (lastTouchedShip != null) {
        final ShipTransform shipTransform = lastTouchedShip.getShipTransform();
        shipTransform.transformPosition(playerPosInLocal, TransformType.GLOBAL_TO_SUBSPACE);
        shipTransform.transformDirection(playerLookInLocal, TransformType.GLOBAL_TO_SUBSPACE);
    }
    return new PlayerMovementData(lastTouchedShipId, entityShipMovementData.getTicksSinceTouchedShip(), entityShipMovementData.getTicksPartOfGround(), playerPosInLocal, playerLookInLocal, onGround);
}
Also used : EntityShipMovementData(org.valkyrienskies.mod.common.entity.EntityShipMovementData) Vector3d(org.joml.Vector3d) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) ShipData(org.valkyrienskies.mod.common.ships.ShipData) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) UUID(java.util.UUID)

Example 44 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsCalculations method rawPhysTickPostCol.

public void rawPhysTickPostCol() {
    if (!isPhysicsBroken()) {
        // This wasn't implemented very well at all! Maybe in the future I'll try again.
        // enforceStaticFriction();
        integrateAngularVelocity();
        integrateLinearVelocity();
    } else {
        getParent().getShipData().setPhysicsEnabled(false);
        getLinearVelocity().zero();
        getAngularVelocity().zero();
    }
    // Keep track of the forced transform, if there is one
    final boolean forceToUseGameTransformLocalCopy = this.forceToUseGameTransform;
    // Reset the forced transform
    this.forceToUseGameTransform = false;
    if (forceToUseGameTransformLocalCopy) {
        // Reset the physics transform to be the game tick transform
        generatePhysicsTransform();
        // Reset angular and linear velocities
        angularVelocity.zero();
        linearVelocity.zero();
    }
    ShipTransform finalPhysTransform = new ShipTransform(physX, physY, physZ, physRotation, physCenterOfMass);
    getParent().getShipTransformationManager().updatePreviousPhysicsTransform();
    getParent().getShipTransformationManager().setCurrentPhysicsTransform(finalPhysTransform);
    // Save a copy of linear and angular velocity in parent's ShipData
    getParent().getShipData().getPhysicsData().setAngularVelocity(new Vector3d(angularVelocity));
    getParent().getShipData().getPhysicsData().setLinearVelocity(new Vector3d(linearVelocity));
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d)

Example 45 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsCalculations method convertTorqueToVelocity.

private void convertTorqueToVelocity() {
    Vector3d torqueTransformed = new Vector3d(torque);
    getPhysInvMOITensor().transform(torqueTransformed);
    getAngularVelocity().add(torqueTransformed.x, torqueTransformed.y, torqueTransformed.z);
    torque.zero();
}
Also used : Vector3d(org.joml.Vector3d)

Aggregations

Vector3d (org.joml.Vector3d)117 Vector3dc (org.joml.Vector3dc)33 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)20 BlockPos (net.minecraft.util.math.BlockPos)19 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)18 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 World (net.minecraft.world.World)9 ShipData (org.valkyrienskies.mod.common.ships.ShipData)9 WorldClient (io.xol.chunkstories.api.world.WorldClient)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)6 IBlockState (net.minecraft.block.state.IBlockState)6 Vec3d (net.minecraft.util.math.Vec3d)6 Vector3f (org.joml.Vector3f)6 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5