Search in sources :

Example 1 with Quaternion

use of com.builtbroken.mc.imp.transform.rotation.Quaternion in project Engine by VoltzEngine-Project.

the class FXElectricBolt2 method split.

/**
	 * Slits a large segment into multiple smaller ones.
	 *
	 * @param splitAmount - The amount of splits
	 * @param offset      - The multiplier scale for the offset.
	 * @param splitChance - The chance of creating a split.
	 * @param splitLength - The length of each split.
	 * @param splitAngle  - The angle of the split.
	 */
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle) {
    /** Temporarily store old segments in a new array */
    List<BoltSegment> oldSegments = this.segments;
    this.segments = new ArrayList();
    /** Previous segment */
    BoltSegment prev = null;
    for (BoltSegment segment : oldSegments) {
        prev = segment.prev;
        /** Length of each subsegment */
        Pos subSegment = segment.difference.clone().multiply(1.0F / splitAmount);
        /**
			 * Creates an array of new bolt points. The first and last points of the bolts are the
			 * respected start and end points of the current segment.
			 */
        BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
        Pos startPoint = segment.start;
        newPoints[0] = segment.start;
        newPoints[splitAmount] = segment.end;
        /**
			 * Create bolt points.
			 */
        for (int i = 1; i < splitAmount; i++) {
            Pos newOffset = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
            Pos basePoint = startPoint.clone().add(subSegment.clone().multiply(i));
            newPoints[i] = new BoltPoint(basePoint, newOffset);
        }
        for (int i = 0; i < splitAmount; i++) {
            BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.alpha, segment.id * splitAmount + i, segment.splitID);
            next.prev = prev;
            if (prev != null) {
                prev.next = next;
            }
            if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
                IPos3D splitrot = next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360, next.difference));
                Pos diff = new Pos(next.difference.clone().transform(new Quaternion((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot))).multiply(splitLength);
                this.maxSplitID += 1;
                this.parentIDMap.put(this.maxSplitID, next.splitID);
                BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].base, newPoints[(i + 1)].offset.clone().add(diff)), segment.alpha / 2f, next.id, this.maxSplitID);
                split.prev = prev;
                this.segments.add(split);
            }
            prev = next;
            this.segments.add(next);
        }
        if (segment.next != null) {
            segment.next.prev = prev;
        }
    }
    this.segmentCount *= splitAmount;
}
Also used : IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Quaternion(com.builtbroken.mc.imp.transform.rotation.Quaternion)

Example 2 with Quaternion

use of com.builtbroken.mc.imp.transform.rotation.Quaternion in project Engine by VoltzEngine-Project.

the class FXElectricBolt method split.

/**
	 * Slits a large segment into multiple smaller ones.
	 *
	 * @param splitAmount - The amount of splits
	 * @param offset      - The multiplier multiply for the offset.
	 * @param splitChance - The chance of creating a split.
	 * @param splitLength - The length of each split.
	 * @param splitAngle  - The angle of the split.
	 */
public void split(int splitAmount, double offset, float splitChance, float splitLength, float splitAngle) {
    if (!this.isCalculated) {
        /** Temporarily store old segments in a new array */
        ArrayList<BoltSegment> oldSegments = this.segments;
        this.segments = new ArrayList();
        /** Previous segment */
        BoltSegment prev = null;
        for (BoltSegment segment : oldSegments) {
            prev = segment.prevSegment;
            Pos subSegment = segment.difference.multiply(1.0F / splitAmount);
            /** Creates an array of new bolt points. The first and last points of the bolts are
				 * the respected start and end points of the current segment. */
            BoltPoint[] newPoints = new BoltPoint[splitAmount + 1];
            Pos startPoint = segment.startBolt.point;
            newPoints[0] = segment.startBolt;
            newPoints[splitAmount] = segment.endBolt;
            for (int i = 1; i < splitAmount; i++) {
                //Vector3 offsetVec = segment.difference.perpendicular().rotate(this.rand.nextFloat() * 360.0F, segment.difference).multiply((this.rand.nextFloat() - 0.5F) * offset);
                Pos offsetVec = new Pos(segment.difference.perpendicular().transform(new Quaternion(this.rand.nextFloat() * 360.0F, segment.difference))).multiply((this.rand.nextFloat() - 0.5F) * offset);
                Pos basepoint = startPoint.clone().add(subSegment.clone().multiply(i));
                newPoints[i] = new BoltPoint(basepoint, offsetVec);
            }
            for (int i = 0; i < splitAmount; i++) {
                BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.weight, segment.segmentID * splitAmount + i, segment.splitID);
                next.prevSegment = prev;
                if (prev != null) {
                    prev.nextSegment = next;
                }
                if ((i != 0) && (this.rand.nextFloat() < splitChance)) {
                    //Vector3 splitrot = next.difference.xCross().rotate(this.rand.nextFloat() * 360.0F, next.difference);
                    Pos splitrot = new Pos(next.difference.xCross().transform(new Quaternion(this.rand.nextFloat() * 360.0F, next.difference)));
                    //Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot).multiply(splitLength);
                    Pos diff = new Pos(next.difference.clone().transform(new Quaternion((this.rand.nextFloat() * 0.66F + 0.33F) * splitAngle, splitrot))).multiply(splitLength);
                    this.maxSplitID += 1;
                    this.splitparents.put(this.maxSplitID, next.splitID);
                    BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].basePoint, newPoints[(i + 1)].offSet.clone().add(diff)), segment.weight / 2.0F, next.segmentID, this.maxSplitID);
                    split.prevSegment = prev;
                    this.segments.add(split);
                }
                prev = next;
                this.segments.add(next);
            }
            if (segment.nextSegment != null) {
                segment.nextSegment.prevSegment = prev;
            }
        }
        this.segmentCount *= splitAmount;
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Quaternion(com.builtbroken.mc.imp.transform.rotation.Quaternion)

Example 3 with Quaternion

use of com.builtbroken.mc.imp.transform.rotation.Quaternion in project Engine by VoltzEngine-Project.

the class RenderItemOverlayUtility method renderTopOverlay.

public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z, float scale) {
    GL11.glPushMatrix();
    /** Render the Crafting Matrix */
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    boolean isLooking = false;
    MovingObjectPosition objectPosition = player.rayTrace(8, 1);
    if (objectPosition != null) {
        isLooking = objectPosition.blockX == tileEntity.xCoord && objectPosition.blockY == tileEntity.yCoord && objectPosition.blockZ == tileEntity.zCoord;
    }
    for (int i = 0; i < (matrixX * matrixZ); i++) {
        if (inventory[i] != null) {
            Pos translation = new Pos((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ))).add(-0.5);
            translation.multiply(0.85);
            GL11.glPushMatrix();
            GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
            RenderUtility.rotateBlockBasedOnDirection(dir);
            GL11.glTranslated(translation.x(), translation.y(), translation.z());
            GL11.glScalef(scale, scale, scale);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
            renderItem(tileEntity.getWorldObj(), ForgeDirection.UP, inventory[i], new Pos(0, 0, 0), 0, 4);
            GL11.glPopMatrix();
            if (isLooking) {
                GL11.glPushMatrix();
                GL11.glTranslated(x, y, z);
                int angle = WorldUtility.getAngleFromForgeDirection(WorldUtility.invertX(dir));
                RenderUtility.renderFloatingText("" + inventory[i].stackSize, new Pos(translation.transform(new Quaternion(angle, Pos.up))).add(0.5).add(new Pos(0, 0.3, 0)));
                GL11.glPopMatrix();
            }
        }
    }
    GL11.glPopMatrix();
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Quaternion(com.builtbroken.mc.imp.transform.rotation.Quaternion) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

Quaternion (com.builtbroken.mc.imp.transform.rotation.Quaternion)3 Pos (com.builtbroken.mc.imp.transform.vector.Pos)3 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1