Search in sources :

Example 21 with Vector3dc

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

the class PlayerMovementData method readData.

/**
 * Reads the raw packet data from the data stream.
 */
public static PlayerMovementData readData(final PacketBuffer packetBuffer) {
    final boolean hasLastTouchShipId = packetBuffer.readBoolean();
    final UUID lastTouchedShipId = hasLastTouchShipId ? packetBuffer.readUniqueId() : null;
    final int ticksSinceTouchedLastShip = packetBuffer.readInt();
    final int ticksPartOfGround = packetBuffer.readInt();
    final Vector3dc playerPosInShip = JOML.readFromByteBuf(packetBuffer);
    final Vector3dc playerLookInShip = JOML.readFromByteBuf(packetBuffer);
    final boolean onGround = packetBuffer.readBoolean();
    return new PlayerMovementData(lastTouchedShipId, ticksSinceTouchedLastShip, ticksPartOfGround, playerPosInShip, playerLookInShip, onGround);
}
Also used : Vector3dc(org.joml.Vector3dc) UUID(java.util.UUID)

Example 22 with Vector3dc

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

the class BlockPhysicsDetails method getForceFromState.

/**
 * Assigns the output parameter of toSet to be the force Vector for the given IBlockState.
 */
static void getForceFromState(IBlockState state, BlockPos pos, World world, double secondsToApply, PhysicsObject obj, Vector3d toSet) {
    Block block = state.getBlock();
    if (block instanceof IBlockForceProvider) {
        Vector3dc forceVector = ((IBlockForceProvider) block).getBlockForceInWorldSpace(world, pos, state, obj, secondsToApply);
        if (forceVector == null) {
            toSet.zero();
        } else {
            toSet.x = forceVector.x();
            toSet.y = forceVector.y();
            toSet.z = forceVector.z();
        }
    }
}
Also used : Vector3dc(org.joml.Vector3dc) IBlockForceProvider(org.valkyrienskies.mod.common.block.IBlockForceProvider) Block(net.minecraft.block.Block)

Example 23 with Vector3dc

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

the class PhysicsCalculations method updatePhysCenterOfMass.

/**
 * Updates the physics center of mass to the game center of mass; does not do any transformation
 * updates on its own.
 */
private void updatePhysCenterOfMass() {
    Vector3dc gameTickCM = parent.getInertiaData().getGameTickCenterOfMass();
    if (!physCenterOfMass.equals(gameTickCM)) {
        Vector3d CMDif = gameTickCM.sub(physCenterOfMass, new Vector3d());
        getParent().getShipTransformationManager().getCurrentPhysicsTransform().transformDirection(CMDif, TransformType.SUBSPACE_TO_GLOBAL);
        physX += CMDif.x;
        physY += CMDif.y;
        physZ += CMDif.z;
        physCenterOfMass = gameTickCM;
    }
}
Also used : Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d)

Example 24 with Vector3dc

use of org.joml.Vector3dc 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 25 with Vector3dc

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

the class ValkyrienUtils method createNewShip.

/**
 * Creates a new ShipIndexedData based on the inputs provided by the physics infuser block.
 */
public ShipData createNewShip(World world, BlockPos physInfuserPos) {
    String name = NounListNameGenerator.getInstance().generateName();
    UUID shipID = UUID.randomUUID();
    // Create ship chunk claims
    VSChunkClaim chunkClaim = ValkyrienUtils.getShipChunkAllocator(world).allocateNextChunkClaim();
    Vector3dc centerOfMassInitial = VSMath.toVector3d(chunkClaim.getRegionCenter());
    Vector3dc shipPosInitial = VSMath.toVector3d(physInfuserPos);
    ShipTransform initial = new ShipTransform(shipPosInitial, centerOfMassInitial);
    AxisAlignedBB axisAlignedBB = new AxisAlignedBB(shipPosInitial.x(), shipPosInitial.y(), shipPosInitial.z(), shipPosInitial.x(), shipPosInitial.y(), shipPosInitial.z());
    return ShipData.createData(QueryableShipData.get(world).getAllShips(), name, chunkClaim, shipID, initial, axisAlignedBB);
}
Also used : Vector3dc(org.joml.Vector3dc) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) VSChunkClaim(org.valkyrienskies.mod.common.ships.chunk_claims.VSChunkClaim) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) UUID(java.util.UUID)

Aggregations

Vector3dc (org.joml.Vector3dc)51 Vector3d (org.joml.Vector3d)33 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)15 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)9 BlockPos (net.minecraft.util.math.BlockPos)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 Location (io.xol.chunkstories.api.Location)6 IBlockState (net.minecraft.block.state.IBlockState)6 World (net.minecraft.world.World)6 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)5 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)5 Entity (io.xol.chunkstories.api.entity.Entity)4 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)4 WorldClient (io.xol.chunkstories.api.world.WorldClient)4 CellData (io.xol.chunkstories.api.world.cell.CellData)4 Nullable (javax.annotation.Nullable)4 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)3 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 Block (net.minecraft.block.Block)3