Search in sources :

Example 86 with Vector3d

use of org.joml.Vector3d in project lwjgl3-demos by LWJGL.

the class SpaceGame method shoot.

private void shoot() {
    boolean firstShot = false;
    for (int i = 0; i < projectilePositions.length; i++) {
        Vector3d projectilePosition = projectilePositions[i];
        Vector4f projectileVelocity = projectileVelocities[i];
        invViewProjMatrix.transformProject(tmp2.set(mouseX, -mouseY, 1.0f)).normalize();
        if (projectileVelocity.w <= 0.0f) {
            projectileVelocity.x = cam.linearVel.x + tmp2.x * shotVelocity;
            projectileVelocity.y = cam.linearVel.y + tmp2.y * shotVelocity;
            projectileVelocity.z = cam.linearVel.z + tmp2.z * shotVelocity;
            projectileVelocity.w = 0.01f;
            if (!firstShot) {
                projectilePosition.set(cam.right(tmp3)).mul(shotSeparation).add(cam.position);
                firstShot = true;
            } else {
                projectilePosition.set(cam.right(tmp3)).mul(-shotSeparation).add(cam.position);
                break;
            }
        }
    }
}
Also used : Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Example 87 with Vector3d

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

the class MixinMinecraft method rightClickBlockProxy.

/**
 * This mixin fixes slabs not placing correctly on ships.
 */
@Redirect(method = "rightClickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;processRightClickBlock(Lnet/minecraft/client/entity/EntityPlayerSP;Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/EnumHand;)Lnet/minecraft/util/EnumActionResult;"))
private EnumActionResult rightClickBlockProxy(PlayerControllerMP playerControllerMP, EntityPlayerSP player, WorldClient worldIn, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) {
    // Check if this is for a ship
    final Optional<ShipData> shipDataOptional = ValkyrienUtils.getShipManagingBlock(worldIn, pos);
    if (shipDataOptional.isPresent()) {
        // This ray trace was in the ship, we're going to have to mess with the hit vector
        final ShipData shipData = shipDataOptional.get();
        final ShipTransform shipTransform = shipData.getShipTransform();
        // Put the hit vector in ship coordinates
        final Vector3d hitVecInLocal = JOML.convert(vec);
        shipTransform.transformPosition(hitVecInLocal, TransformType.GLOBAL_TO_SUBSPACE);
        final Vec3d moddedHitVec = JOML.toMinecraft(hitVecInLocal);
        return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, moddedHitVec, hand);
    }
    return playerControllerMP.processRightClickBlock(player, worldIn, pos, direction, vec, hand);
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Vec3d(net.minecraft.util.math.Vec3d) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 88 with Vector3d

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

the class MixinWorldClient method doVoidFogParticles.

/**
 * Adds torch particles to ships.
 * @author Tri0de
 */
@Overwrite
public void doVoidFogParticles(int posX, int posY, int posZ) {
    final int i = 32;
    final Random random = ThreadLocalRandom.current();
    ItemStack itemstack = this.mc.player.getHeldItemMainhand();
    boolean flag = this.mc.playerController.getCurrentGameType() == GameType.CREATIVE && !itemstack.isEmpty() && itemstack.getItem() == Item.getItemFromBlock(Blocks.BARRIER);
    BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
    final AxisAlignedBB shipDetectionBB = new AxisAlignedBB(posX - i, posY - i, posZ - i, posX + i, posY + i, posZ + i);
    final List<PhysicsObject> nearbyShipObjects = ValkyrienUtils.getPhysObjWorld(thisAsWorldClient).getPhysObjectsInAABB(shipDetectionBB);
    final Vector3d temp0 = new Vector3d();
    for (int j = 0; j < 667; ++j) {
        this.vs_showBarrierParticles(posX, posY, posZ, 16, random, flag, blockpos$mutableblockpos, nearbyShipObjects, temp0);
        this.vs_showBarrierParticles(posX, posY, posZ, 32, random, flag, blockpos$mutableblockpos, nearbyShipObjects, temp0);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 89 with Vector3d

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

the class MixinParticleManager method preAddEffect.

@Inject(method = "addEffect", at = @At("HEAD"), cancellable = true)
public void preAddEffect(Particle effect, CallbackInfo callbackInfoReturnable) {
    if (effect == null) {
        callbackInfoReturnable.cancel();
        return;
    }
    BlockPos pos = new BlockPos(effect.posX, effect.posY, effect.posZ);
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(effect.world, pos);
    if (physicsObject.isPresent()) {
        Vector3d posVec = new Vector3d(effect.posX, effect.posY, effect.posZ);
        Vector3d velocity = new Vector3d(effect.motionX, effect.motionY, effect.motionZ);
        physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(posVec, TransformType.SUBSPACE_TO_GLOBAL);
        physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformDirection(velocity, TransformType.SUBSPACE_TO_GLOBAL);
        effect.setPosition(posVec.x, posVec.y, posVec.z);
        effect.motionX = velocity.x;
        effect.motionY = velocity.y;
        effect.motionZ = velocity.z;
    }
}
Also used : Vector3d(org.joml.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 90 with Vector3d

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

the class MixinEntityRenderer method orientCamera.

@Inject(method = "orientCamera", at = @At("HEAD"), cancellable = true)
private void orientCamera(float partialTicks, CallbackInfo ci) {
    EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(mc.getRenderViewEntity());
    if (mountData.getMountedShip() == null) {
        // Do nothing. We don't want to mess with camera code unless we have to.
        return;
    } else {
        // Take over the camera orientation entirely. Don't let anything else touch it.
        ci.cancel();
    }
    Entity entity = this.mc.getRenderViewEntity();
    Vector3d eyeVector = new Vector3d(0, entity.getEyeHeight(), 0);
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        eyeVector.y += .7D;
    }
    double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
    double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks;
    double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
    // Probably overkill, but this should 100% fix the crash in issue #78
    if (mountData.isMounted() && mountData.getMountedShip().getShipRenderer().offsetPos != null) {
        final ShipTransform renderTransform = mountData.getMountedShip().getShipTransformationManager().getRenderTransform();
        renderTransform.transformDirection(eyeVector, TransformType.SUBSPACE_TO_GLOBAL);
        Vector3d playerPosition = JOML.convert(mountData.getMountPos());
        renderTransform.transformPosition(playerPosition, TransformType.SUBSPACE_TO_GLOBAL);
        d0 = playerPosition.x;
        d1 = playerPosition.y;
        d2 = playerPosition.z;
    }
    d0 += eyeVector.x;
    d1 += eyeVector.y;
    d2 += eyeVector.z;
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        if (!this.mc.gameSettings.debugCamEnable) {
            // VS code starts here
            if (mountData.isMounted()) {
                Vector3d playerPosInLocal = JOML.convert(mountData.getMountPos());
                playerPosInLocal.sub(.5D, .6875, .5);
                playerPosInLocal.round();
                BlockPos bedPos = new BlockPos(playerPosInLocal.x, playerPosInLocal.y, playerPosInLocal.z);
                IBlockState state = this.mc.world.getBlockState(bedPos);
                Block block = state.getBlock();
                float angleYaw = 0;
                if (block != null && block.isBed(state, entity.world, bedPos, entity)) {
                    angleYaw = block.getBedDirection(state, entity.world, bedPos).getHorizontalIndex() * 90;
                    angleYaw += 180;
                }
                entity.rotationYaw = entity.prevRotationYaw = angleYaw;
                entity.rotationPitch = entity.prevRotationPitch = 0;
            } else {
                BlockPos blockpos = new BlockPos(entity);
                IBlockState iblockstate = this.mc.world.getBlockState(blockpos);
                net.minecraftforge.client.ForgeHooksClient.orientBedCamera(this.mc.world, blockpos, iblockstate, entity);
                GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
                GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
            }
        }
    } else if (this.mc.gameSettings.thirdPersonView > 0) {
        double d3 = this.thirdPersonDistancePrev + (4.0F - this.thirdPersonDistancePrev) * partialTicks;
        IShipPilot shipPilot = (IShipPilot) Minecraft.getMinecraft().player;
        if (shipPilot.isPilotingShip()) {
            // TODO: Make this number scale with the Ship
            d3 = 15D;
        }
        if (this.mc.gameSettings.debugCamEnable) {
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
        } else {
            float f1 = entity.rotationYaw;
            float f2 = entity.rotationPitch;
            if (this.mc.gameSettings.thirdPersonView == 2) {
                f2 += 180.0F;
            }
            double d4 = -MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * d3;
            double d5 = MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * d3;
            double d6 = (-MathHelper.sin(f2 * 0.017453292F)) * d3;
            for (int i = 0; i < 8; ++i) {
                float f3 = (i & 1) * 2 - 1;
                float f4 = (i >> 1 & 1) * 2 - 1;
                float f5 = (i >> 2 & 1) * 2 - 1;
                f3 = f3 * 0.1F;
                f4 = f4 * 0.1F;
                f5 = f5 * 0.1F;
                IShipPilot pilot = (IShipPilot) Minecraft.getMinecraft().player;
                ((IWorldVS) this.mc.world).excludeShipFromRayTracer(((IShipPilot) this.mc.player).getPilotedShip());
                // RayTraceResult raytraceresult = EntityMoveInjectionMethods.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().world, new Vec3d(d0 + f3, d1 + f4, d2 + f5), new Vec3d(d0 - d4 + f3 + f5, d1 - d6 + f4, d2 - d5 + f5), false, false, false, pilot.getPilotedShip());
                RayTraceResult raytraceresult = mc.world.rayTraceBlocks(new Vec3d(d0 + (double) f3, d1 + (double) f4, d2 + (double) f5), new Vec3d(d0 - d4 + (double) f3 + (double) f5, d1 - d6 + (double) f4, d2 - d5 + (double) f5));
                ((IWorldVS) this.mc.world).unexcludeShipFromRayTracer(((IShipPilot) this.mc.player).getPilotedShip());
                if (raytraceresult != null) {
                    double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
                    if (d7 < d3) {
                        d3 = d7;
                    }
                }
            }
            if (this.mc.gameSettings.thirdPersonView == 2) {
                GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
            }
            GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
            GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
        }
    } else {
        GlStateManager.translate(0.0F, 0.0F, 0.05F);
    }
    if (!this.mc.gameSettings.debugCamEnable) {
        float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
        float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
        float roll = 0.0F;
        if (entity instanceof EntityAnimal) {
            EntityAnimal entityanimal = (EntityAnimal) entity;
            yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
        }
        IBlockState state = ActiveRenderInfo.getBlockStateAtEntityViewpoint(this.mc.world, entity, partialTicks);
        net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(EntityRenderer.class.cast(this), entity, state, partialTicks, yaw, pitch, roll);
        net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
        GlStateManager.rotate(event.getRoll(), 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(event.getPitch(), 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(event.getYaw(), 0.0F, 1.0F, 0.0F);
    }
    if (mountData.isMounted() && mountData.getMountedShip().getShipRenderer().offsetPos != null) {
        final ShipTransform renderTransform = mountData.getMountedShip().getShipTransformationManager().getRenderTransform();
        Quaterniond orientationQuat = renderTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
        Vector3dc radians = orientationQuat.getEulerAnglesXYZ(new Vector3d());
        float moddedPitch = (float) Math.toDegrees(radians.x());
        float moddedYaw = (float) Math.toDegrees(radians.y());
        float moddedRoll = (float) Math.toDegrees(radians.z());
        GlStateManager.rotate(-moddedRoll, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(-moddedYaw, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-moddedPitch, 1.0F, 0.0F, 0.0F);
    }
    GlStateManager.translate(-eyeVector.x, -eyeVector.y, -eyeVector.z);
    d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks + eyeVector.x;
    d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks + eyeVector.y;
    d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks + eyeVector.z;
    this.cloudFog = this.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
Also used : Entity(net.minecraft.entity.Entity) EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) IBlockState(net.minecraft.block.state.IBlockState) Quaterniond(org.joml.Quaterniond) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) Vector3dc(org.joml.Vector3dc) IShipPilot(org.valkyrienskies.mod.common.piloting.IShipPilot) Vector3d(org.joml.Vector3d) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityRenderer(net.minecraft.client.renderer.EntityRenderer)

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