Search in sources :

Example 31 with ShipTransform

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

the class SimpleEMATransformInterpolator method tickTransformInterpolator.

@Override
public void tickTransformInterpolator() {
    // First compute the new position
    Vector3dc curPos = new Vector3d(curTickTransform.getPosX(), curTickTransform.getPosY(), curTickTransform.getPosZ());
    // If the new center coord != current center coord, then offset the current position by the difference
    if (!latestReceivedTransform.getCenterCoord().equals(curTickTransform.getCenterCoord(), DOUBLE_EQUALS_THRESHOLD)) {
        // Add newCenter - oldCenter to the curPos
        Vector3d offset = latestReceivedTransform.getCenterCoord().sub(curTickTransform.getCenterCoord(), new Vector3d());
        curTickTransform.transformDirection(offset, TransformType.SUBSPACE_TO_GLOBAL);
        curPos = curPos.add(offset, new Vector3d());
    }
    Vector3dc latestDataPos = new Vector3d(latestReceivedTransform.getPosX(), latestReceivedTransform.getPosY(), latestReceivedTransform.getPosZ());
    Vector3dc newPos = curPos.lerp(latestDataPos, filterAlpha, new Vector3d());
    // Then compute the new rotation
    Quaterniondc curRot = curTickTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
    Quaterniondc latestDataRot = latestReceivedTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
    Quaterniondc newRot = curRot.slerp(latestDataRot, filterAlpha, new Quaterniond()).normalize();
    // Then create the new transform using the new position and rotation (and center coord)
    curTickTransform = new ShipTransform(newPos, newRot, latestReceivedTransform.getCenterCoord());
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)

Example 32 with ShipTransform

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

the class VSWorldPhysicsLoop method physicsTick.

private void physicsTick(double delta) {
    // Update the immutable ship list.
    immutableShipsList = ((IHasShipManager) hostWorld).getManager().getAllLoadedThreadSafe();
    // Run tasks queued to run on physics thread
    recurringTasks.forEach(t -> t.runTask(delta));
    taskQueue.forEach(Runnable::run);
    taskQueue.clear();
    // Make a sublist of physics objects to process physics on.
    List<PhysicsObject> physicsEntitiesToDoPhysics = new ArrayList<>();
    for (PhysicsObject physicsObject : immutableShipsList) {
        if (physicsObject.isPhysicsReady() && physicsObject.isPhysicsEnabled() && physicsObject.getCachedSurroundingChunks() != null) {
            physicsEntitiesToDoPhysics.add(physicsObject);
        }
    }
    // Finally, actually process the physics tick
    tickThePhysicsAndCollision(physicsEntitiesToDoPhysics, delta);
    // Send ship position update packets around 20 times a second
    final long currentTimeMillis = System.currentTimeMillis();
    final double secondsSinceLastPacket = (currentTimeMillis - lastPacketSendTime) / 1000.0;
    // Use .04 to guarantee we're always sending at least 20 packets per second
    if (secondsSinceLastPacket > .04) {
        // Update the last update time
        lastPacketSendTime = currentTimeMillis;
        try {
            // At the end, send the transform update packets
            final ShipTransformUpdateMessage shipTransformUpdateMessage = new ShipTransformUpdateMessage();
            final int dimensionID = hostWorld.provider.getDimension();
            shipTransformUpdateMessage.setDimensionID(dimensionID);
            for (final PhysicsObject physicsObject : immutableShipsList) {
                final UUID shipUUID = physicsObject.getUuid();
                final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
                final AxisAlignedBB shipBB = physicsObject.getPhysicsTransformAABB();
                shipTransformUpdateMessage.addData(shipUUID, shipTransform, shipBB);
            }
            ValkyrienSkiesMod.physWrapperTransformUpdateNetwork.sendToDimension(shipTransformUpdateMessage, shipTransformUpdateMessage.getDimensionID());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ShipTransformUpdateMessage(org.valkyrienskies.mod.common.network.ShipTransformUpdateMessage) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) IHasShipManager(org.valkyrienskies.mod.common.ships.ship_world.IHasShipManager)

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