Search in sources :

Example 1 with Point

use of com.builtbroken.mc.imp.transform.vector.Point in project Engine by VoltzEngine-Project.

the class TriangleTest method testAcuteTriangleAreas.

/**
     * Tests area method using 4 triangles in each section
     * of pos & neg relations. It also tests the order of the points
     * when constructing the triangle to ensure there are no ordering
     * issues with how the math is handled
     */
public void testAcuteTriangleAreas() {
    final double expectedArea = 2;
    //Using zero zero
    Point zeroZero = new Point();
    Point p1 = null;
    Point p2 = null;
    Triangle a, b, c;
    for (int i = 0; i < 4; i++) {
        switch(i) {
            case 0:
                //UP
                p1 = new Point(1, 2);
                p2 = new Point(-1, 2);
                break;
            case 2:
                //DOWN
                p1 = new Point(1, -2);
                p2 = new Point(-1, -2);
                break;
            case 3:
                //RIGHT
                p1 = new Point(2, 1);
                p2 = new Point(2, -1);
                break;
            case 4:
                //LEFT
                p1 = new Point(-2, 1);
                p2 = new Point(-2, -1);
                break;
        }
        a = new Triangle(zeroZero, p1, p2);
        b = new Triangle(p1, p2, zeroZero);
        c = new Triangle(p2, zeroZero, p1);
        assertEquals("Failed area check for A" + i, expectedArea, a.getArea());
        assertEquals("Failed area check for B" + i, expectedArea, b.getArea());
        assertEquals("Failed area check for C" + i, expectedArea, c.getArea());
    }
}
Also used : Triangle(com.builtbroken.mc.imp.transform.region.Triangle) Point(com.builtbroken.mc.imp.transform.vector.Point) Point(com.builtbroken.mc.imp.transform.vector.Point)

Example 2 with Point

use of com.builtbroken.mc.imp.transform.vector.Point in project ICBM-Classic by BuiltBrokenModding.

the class TileRadarStation method isPoweringTo.

public boolean isPoweringTo(ForgeDirection side) {
    if (incomingMissiles.size() > 0) {
        if (this.emitAll) {
            return true;
        }
        for (EntityMissile incomingMissile : this.incomingMissiles) {
            Point position = incomingMissile.toPos().toVector2();
            ForgeDirection missileTravelDirection = ForgeDirection.UNKNOWN;
            double closest = -1;
            for (int i = 2; i < 6; i++) {
                double dist = position.distance(new Point(this.xCoord + ForgeDirection.getOrientation(i).offsetX, this.zCoord + ForgeDirection.getOrientation(i).offsetZ));
                if (dist < closest || closest < 0) {
                    missileTravelDirection = ForgeDirection.getOrientation(i);
                    closest = dist;
                }
            }
            if (missileTravelDirection.getOpposite() == side) {
                return true;
            }
        }
    }
    return false;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Point(com.builtbroken.mc.imp.transform.vector.Point) EntityMissile(icbm.classic.content.entity.EntityMissile) Point(com.builtbroken.mc.imp.transform.vector.Point)

Example 3 with Point

use of com.builtbroken.mc.imp.transform.vector.Point in project ICBM-Classic by BuiltBrokenModding.

the class GuiRadarStation method updateScreen.

@Override
public void updateScreen() {
    super.updateScreen();
    if (Mouse.isInsideWindow()) {
        if (Mouse.getEventButton() == -1) {
            this.mousePosition = new Point(Mouse.getEventX() * this.width / this.mc.displayWidth, this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1);
            float difference = TileRadarStation.MAX_DETECTION_RANGE / this.radarMapRadius;
            if (this.mousePosition.x() > this.radarCenter.x() - difference && this.mousePosition.x() < this.radarCenter.x() + difference && this.mousePosition.y() > this.radarCenter.y() - difference && this.mousePosition.y() < this.radarCenter.y() + difference) {
                // Calculate from the mouse position the relative position
                // on the grid
                int xDifference = (int) (this.mousePosition.x() - this.radarCenter.x());
                int yDifference = (int) (this.mousePosition.y() - this.radarCenter.y());
                int xBlockDistance = (int) (xDifference * this.radarMapRadius);
                int yBlockDistance = (int) (yDifference * this.radarMapRadius);
                this.mouseOverCoords = new Point(this.tileEntity.xCoord + xBlockDistance, this.tileEntity.zCoord - yBlockDistance);
            }
        }
    }
    if (!this.textFieldSafetyZone.isFocused()) {
        this.textFieldSafetyZone.setText(this.tileEntity.safetyRange + "");
    }
    if (!this.textFieldAlarmRange.isFocused()) {
        this.textFieldAlarmRange.setText(this.tileEntity.alarmRange + "");
    }
}
Also used : Point(com.builtbroken.mc.imp.transform.vector.Point) Point(com.builtbroken.mc.imp.transform.vector.Point)

Example 4 with Point

use of com.builtbroken.mc.imp.transform.vector.Point in project ICBM-Classic by BuiltBrokenModding.

the class GuiRadarStation method drawGuiContainerBackgroundLayer.

/** Draw the background layer for the GuiContainer (everything behind the items) */
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.containerPosX = (this.width - this.xSize) / 2;
    this.containerPosY = (this.height - this.ySize) / 2;
    this.drawTexturedModalRect(containerPosX, containerPosY, 0, 0, this.xSize, this.ySize);
    this.radarCenter = new Point(this.containerPosX + this.xSize / 3 - 10, this.containerPosY + this.ySize / 2 + 4);
    this.radarMapRadius = TileRadarStation.MAX_DETECTION_RANGE / 71f;
    this.info = "";
    this.info2 = "";
    if (this.tileEntity.hasPower()) {
        int range = 4;
        for (Entity entity : this.tileEntity.detectedEntities) {
            Point position = new Point(radarCenter.x() + (entity.posX - this.tileEntity.xCoord) / this.radarMapRadius, radarCenter.y() - (entity.posZ - this.tileEntity.zCoord) / this.radarMapRadius);
            if (entity instanceof EntityMissile) {
                if (this.tileEntity.isMissileGoingToHit((EntityMissile) entity)) {
                    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_RED_DOT);
                } else {
                    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_YELLOW_DOT);
                }
            } else {
                FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_YELLOW_DOT);
            }
            this.drawTexturedModalRect(position.xi(), position.yi(), 0, 0, 2, 2);
            // Hover Detection
            Point minPosition = position.clone();
            minPosition.add(-range);
            Point maxPosition = position.clone();
            maxPosition.add(range);
            if (new Rectangle(minPosition, maxPosition).isWithin(this.mousePosition)) {
                this.info = entity.getCommandSenderName();
                if (entity instanceof EntityPlayer) {
                    this.info = "ยง1" + this.info;
                }
                if (entity instanceof EntityMissile) {
                    if (((EntityMissile) entity).targetVector != null) {
                        this.info2 = "(" + ((EntityMissile) entity).targetVector.xi() + ", " + ((EntityMissile) entity).targetVector.zi() + ")";
                    }
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) Rectangle(com.builtbroken.mc.imp.transform.region.Rectangle) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Point(com.builtbroken.mc.imp.transform.vector.Point) Point(com.builtbroken.mc.imp.transform.vector.Point) EntityMissile(icbm.classic.content.entity.EntityMissile)

Example 5 with Point

use of com.builtbroken.mc.imp.transform.vector.Point in project Engine by VoltzEngine-Project.

the class RectangleTest method testArea.

/**
     * Checks too see if the area math is working :P
     */
public void testArea() {
    //For the hell of it
    Rectangle rect = new Rectangle(new Point(), new Point());
    assertEquals("Expected zero as both corners are zero zero", 0.0, rect.getArea());
    rect = new Rectangle(new Point(0, 1), new Point(0, 2));
    assertEquals("Expected zero as both corners are in a strait line", 0.0, rect.getArea());
    //Random are checks
    rect = new Rectangle(new Point(0, 0), new Point(2, 2));
    assertEquals("Expected an exact match for area check one", 4.0, rect.getArea());
    rect = new Rectangle(new Point(0, 0), new Point(-2, -2));
    assertEquals("Expected an exact match for area check two", 4.0, rect.getArea());
    rect = new Rectangle(new Point(-2, -2), new Point(2, 2));
    assertEquals("Expected an exact match for area check three", 16.0, rect.getArea());
    rect = new Rectangle(new Point(10, 20), new Point(-20, -10));
    assertEquals("Expected an exact match for area check four", 900.0, rect.getArea());
}
Also used : Rectangle(com.builtbroken.mc.imp.transform.region.Rectangle) Point(com.builtbroken.mc.imp.transform.vector.Point)

Aggregations

Point (com.builtbroken.mc.imp.transform.vector.Point)9 Triangle (com.builtbroken.mc.imp.transform.region.Triangle)5 Rectangle (com.builtbroken.mc.imp.transform.region.Rectangle)3 EntityMissile (icbm.classic.content.entity.EntityMissile)2 LinkedList (java.util.LinkedList)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1