Search in sources :

Example 51 with Vector3d

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

the class TileEntityCaptainsChair method processCalculationsForControlMessageAndApplyCalculations.

private void processCalculationsForControlMessageAndApplyCalculations(PhysicsObject controlledShip, PilotControlsMessage message, IBlockState state) {
    BlockPos chairPosition = getPos();
    if (controlledShip.isShipAligningToGrid()) {
        return;
    }
    double pilotPitch = 0D;
    double pilotYaw = ((BlockCaptainsChair) state.getBlock()).getChairYaw(state, chairPosition);
    double pilotRoll = 0D;
    Matrix3d pilotRotationMatrix = new Matrix3d();
    pilotRotationMatrix.rotateXYZ(Math.toRadians(pilotPitch), Math.toRadians(pilotYaw), Math.toRadians(pilotRoll));
    Vector3d playerDirection = new Vector3d(1, 0, 0);
    pilotRotationMatrix.transform(playerDirection);
    Vector3d upDirection = new Vector3d(0, 1, 0);
    Vector3d downDirection = new Vector3d(0, -1, 0);
    Vector3d idealAngularDirection = new Vector3d();
    Vector3d idealLinearVelocity = new Vector3d();
    Vector3d shipUp = new Vector3d(0, 1, 0);
    Vector3d shipUpPosIdeal = new Vector3d(0, 1, 0);
    if (message.airshipForward_KeyDown) {
        idealLinearVelocity.add(playerDirection);
    }
    if (message.airshipBackward_KeyDown) {
        idealLinearVelocity.sub(playerDirection);
    }
    controlledShip.getShipTransformationManager().getCurrentTickTransform().transformDirection(idealLinearVelocity, TransformType.SUBSPACE_TO_GLOBAL);
    controlledShip.getShipTransformationManager().getCurrentTickTransform().transformDirection(shipUp, TransformType.SUBSPACE_TO_GLOBAL);
    if (message.airshipUp_KeyDown) {
        idealLinearVelocity.add(upDirection.mul(.5, new Vector3d()));
    }
    if (message.airshipDown_KeyDown) {
        idealLinearVelocity.add(downDirection.mul(.5, new Vector3d()));
    }
    double sidePitch = 0;
    if (message.airshipRight_KeyDown) {
        idealAngularDirection.sub(shipUp);
        sidePitch -= 10;
    }
    if (message.airshipLeft_KeyDown) {
        idealAngularDirection.add(shipUp);
        sidePitch += 10;
    }
    Vector3d sidesRotationAxis = new Vector3d(playerDirection);
    controlledShip.getShipTransformationManager().getCurrentTickTransform().transformDirection(sidesRotationAxis, TransformType.SUBSPACE_TO_GLOBAL);
    AxisAngle4d rotationSidesTransform = new AxisAngle4d(Math.toRadians(sidePitch), sidesRotationAxis.x, sidesRotationAxis.y, sidesRotationAxis.z);
    rotationSidesTransform.transform(shipUpPosIdeal);
    idealAngularDirection.mul(2);
    // The vector that points in the direction of the normal of the plane that
    // contains shipUp and shipUpPos. This is our axis of rotation.
    Vector3d shipUpRotationVector = shipUp.cross(shipUpPosIdeal, new Vector3d());
    // This isnt quite right, but it handles the cases quite well.
    double shipUpTheta = shipUp.angle(shipUpPosIdeal) + Math.PI;
    shipUpRotationVector.mul(shipUpTheta);
    idealAngularDirection.add(shipUpRotationVector);
    idealLinearVelocity.mul(20);
    // Move the ship faster if the player holds the sprint key.
    if (message.airshipSprinting) {
        idealLinearVelocity.mul(2);
    }
    double lerpFactor = .2;
    Vector3d linearMomentumDif = controlledShip.getPhysicsCalculations().getLinearVelocity().sub(idealLinearVelocity, new Vector3d());
    Vector3d angularVelocityDif = controlledShip.getPhysicsCalculations().getAngularVelocity().sub(idealAngularDirection, new Vector3d());
    linearMomentumDif.mul(lerpFactor);
    angularVelocityDif.mul(lerpFactor);
    controlledShip.getPhysicsCalculations().getLinearVelocity().sub(linearMomentumDif);
    controlledShip.getPhysicsCalculations().getAngularVelocity().sub(angularVelocityDif);
}
Also used : Matrix3d(org.joml.Matrix3d) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) AxisAngle4d(org.joml.AxisAngle4d) BlockCaptainsChair(org.valkyrienskies.mod.common.block.BlockCaptainsChair)

Example 52 with Vector3d

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

the class ValkyrienNBTUtils method readVectorFromNBT.

public static Vector3d readVectorFromNBT(String name, NBTTagCompound compound) {
    Vector3d vector = new Vector3d();
    vector.x = compound.getDouble(name + "X");
    vector.y = compound.getDouble(name + "Y");
    vector.z = compound.getDouble(name + "Z");
    return vector;
}
Also used : Vector3d(org.joml.Vector3d)

Example 53 with Vector3d

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

the class TileEntityBoatChair method processControlMessage.

@Override
public void processControlMessage(PilotControlsMessage message, EntityPlayerMP sender) {
    final IBlockState state = getWorld().getBlockState(getPos());
    final double pilotYaw = ((BlockBoatChair) state.getBlock()).getChairYaw(state);
    // 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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Vector3d(org.joml.Vector3d) BlockBoatChair(org.valkyrienskies.mod.common.block.BlockBoatChair)

Example 54 with Vector3d

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

the class TileEntityBoatChair method getBlockForceInShipSpace.

@Nullable
public Vector3dc getBlockForceInShipSpace(World world, BlockPos pos, IBlockState state, PhysicsObject physicsObject, double secondsToApply) {
    // Don't add force if theres no pilot
    if (getPilotEntity() == null) {
        return null;
    }
    final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
    final Vector3dc idealLinearVelocity = shipTransform.transformDirectionNew(new Vector3d(targetLinearVelocity), TransformType.SUBSPACE_TO_GLOBAL);
    final Vector3dc currentLinearVelocity = physicsObject.getPhysicsCalculations().getLinearVelocity();
    final Vector3dc velocityDifference = idealLinearVelocity.sub(currentLinearVelocity, new Vector3d());
    final Vector3d resultingBlockForce = new Vector3d(velocityDifference);
    resultingBlockForce.mul(physicsObject.getInertiaData().getGameTickMass());
    resultingBlockForce.mul(secondsToApply);
    resultingBlockForce.mul(LINEAR_EMA_FILTER_CONSTANT);
    // Do not affect y axis
    resultingBlockForce.y = 0;
    return resultingBlockForce;
}
Also used : Vector3dc(org.joml.Vector3dc) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) Nullable(javax.annotation.Nullable)

Example 55 with Vector3d

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

the class TileEntityBoatChair method onStopTileUsage.

@Override
public void onStopTileUsage() {
    targetLinearVelocity = new Vector3d();
    targetAngularVelocity = new Vector3d();
}
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