Search in sources :

Example 6 with Quaternion

use of ValkyrienWarfareBase.Math.Quaternion in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunnerClient method onOrientCamera.

public static void onOrientCamera(EntityRenderer renderer, float partialTicks) {
    Entity entity = renderer.mc.getRenderViewEntity();
    BlockPos playerPos = new BlockPos(entity);
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(entity.worldObj, playerPos);
    if (wrapper != null) {
        Vector playerPosNew = new Vector(entity.posX, entity.posY, entity.posZ);
        RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, playerPosNew);
        entity.posX = entity.prevPosX = entity.lastTickPosX = playerPosNew.X;
        entity.posY = entity.prevPosY = entity.lastTickPosY = playerPosNew.Y;
        entity.posZ = entity.prevPosZ = entity.lastTickPosZ = playerPosNew.Z;
    }
    Vector eyeVector = new Vector(0, entity.getEyeHeight(), 0);
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        eyeVector.Y += .7D;
    }
    double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks;
    double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks;
    double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks;
    PhysicsWrapperEntity fixedOnto = ValkyrienWarfareMod.physicsManager.getShipFixedOnto(entity);
    //Probably overkill, but this should 100% fix the crash in issue #78
    if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
        Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
        double[] radians = orientationQuat.toRadians();
        float moddedPitch = (float) Math.toDegrees(radians[0]);
        float moddedYaw = (float) Math.toDegrees(radians[1]);
        float moddedRoll = (float) Math.toDegrees(radians[2]);
        double[] orientationMatrix = RotationMatrices.getRotationMatrix(moddedPitch, moddedYaw, moddedRoll);
        RotationMatrices.applyTransform(orientationMatrix, eyeVector);
        Vector playerPosition = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
        RotationMatrices.applyTransform(fixedOnto.wrapping.coordTransform.RlToWTransform, playerPosition);
        d0 = playerPosition.X;
        d1 = playerPosition.Y;
        d2 = playerPosition.Z;
    //			entity.posX = entity.prevPosX = entity.lastTickPosX = d0;
    //			entity.posY = entity.prevPosY = entity.lastTickPosY = d1;
    //			entity.posZ = entity.prevPosZ = entity.lastTickPosZ = d2;
    }
    d0 += eyeVector.X;
    d1 += eyeVector.Y;
    d2 += eyeVector.Z;
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        if (!renderer.mc.gameSettings.debugCamEnable) {
            //VW code starts here
            if (fixedOnto != null) {
                Vector playerPosInLocal = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
                playerPosInLocal.subtract(.5D, .6875, .5);
                playerPosInLocal.roundToWhole();
                BlockPos bedPos = new BlockPos(playerPosInLocal.X, playerPosInLocal.Y, playerPosInLocal.Z);
                IBlockState state = renderer.mc.theWorld.getBlockState(bedPos);
                Block block = state.getBlock();
                float angleYaw = 0;
                if (block != null && block.isBed(state, entity.worldObj, bedPos, entity)) {
                    angleYaw = (float) (block.getBedDirection(state, entity.worldObj, bedPos).getHorizontalIndex() * 90);
                    angleYaw += 180;
                }
                entity.rotationYaw = entity.prevRotationYaw = angleYaw;
                entity.rotationPitch = entity.prevRotationPitch = 0;
            } else {
                BlockPos blockpos = new BlockPos(entity);
                IBlockState iblockstate = renderer.mc.theWorld.getBlockState(blockpos);
                net.minecraftforge.client.ForgeHooksClient.orientBedCamera(renderer.mc.theWorld, 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 (renderer.mc.gameSettings.thirdPersonView > 0) {
        double d3 = (double) (renderer.thirdPersonDistancePrev + (4.0F - renderer.thirdPersonDistancePrev) * partialTicks);
        if (ClientPilotingManager.isPlayerPilotingShip()) {
            //TODO: Make this number scale with the Ship
            d3 = 15D;
        }
        if (renderer.mc.gameSettings.debugCamEnable) {
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
        } else {
            float f1 = entity.rotationYaw;
            float f2 = entity.rotationPitch;
            if (renderer.mc.gameSettings.thirdPersonView == 2) {
                f2 += 180.0F;
            }
            double d4 = (double) (-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
            double d5 = (double) (MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
            double d6 = (double) (-MathHelper.sin(f2 * 0.017453292F)) * d3;
            for (int i = 0; i < 8; ++i) {
                float f3 = (float) ((i & 1) * 2 - 1);
                float f4 = (float) ((i >> 1 & 1) * 2 - 1);
                float f5 = (float) ((i >> 2 & 1) * 2 - 1);
                f3 = f3 * 0.1F;
                f4 = f4 * 0.1F;
                f5 = f5 * 0.1F;
                RayTraceResult raytraceresult = CallRunnerClient.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().theWorld, 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), false, false, false, ClientPilotingManager.getPilotedWrapperEntity());
                if (raytraceresult != null) {
                    double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
                    if (d7 < d3) {
                        d3 = d7;
                    }
                }
            }
            if (renderer.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 (!renderer.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(renderer.mc.theWorld, entity, partialTicks);
        net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(renderer, 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 (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
        Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
        double[] radians = orientationQuat.toRadians();
        float moddedPitch = (float) Math.toDegrees(radians[0]);
        float moddedYaw = (float) Math.toDegrees(radians[1]);
        float moddedRoll = (float) Math.toDegrees(radians[2]);
        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) * (double) partialTicks + eyeVector.X;
    d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks + eyeVector.Y;
    d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks + eyeVector.Z;
    renderer.cloudFog = renderer.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) Quaternion(ValkyrienWarfareBase.Math.Quaternion) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) BlockPos(net.minecraft.util.math.BlockPos) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) Vector(ValkyrienWarfareBase.API.Vector)

Example 7 with Quaternion

use of ValkyrienWarfareBase.Math.Quaternion in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsCalculationsOrbital method applyAngularVelocity.

@Override
public void applyAngularVelocity() {
    if (!isOrbitalPhased) {
        super.applyAngularVelocity();
    } else {
        CoordTransformObject coordTrans = parent.coordTransform;
        double[] rotationChange = RotationMatrices.getRotationMatrix(setAngularVel.X, setAngularVel.Y, setAngularVel.Z, angularVelocity.length() * physTickSpeed);
        Quaternion faggot = Quaternion.QuaternionFromMatrix(RotationMatrices.getMatrixProduct(rotationChange, coordTrans.lToWRotation));
        double[] radians = faggot.toRadians();
        wrapperEnt.pitch = Double.isNaN(radians[0]) ? 0.0f : (float) Math.toDegrees(radians[0]);
        wrapperEnt.yaw = Double.isNaN(radians[1]) ? 0.0f : (float) Math.toDegrees(radians[1]);
        wrapperEnt.roll = Double.isNaN(radians[2]) ? 0.0f : (float) Math.toDegrees(radians[2]);
        coordTrans.updateAllTransforms();
    }
}
Also used : CoordTransformObject(ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject) Quaternion(ValkyrienWarfareBase.Math.Quaternion)

Aggregations

Quaternion (ValkyrienWarfareBase.Math.Quaternion)7 Vector (ValkyrienWarfareBase.API.Vector)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)4 CoordTransformObject (ValkyrienWarfareBase.PhysicsManagement.CoordTransformObject)2 RenderManagerOverride (ValkyrienWarfareCombat.Render.RenderManagerOverride)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 EnumSkyBlock (net.minecraft.world.EnumSkyBlock)1