Search in sources :

Example 1 with Rectangle

use of com.builtbroken.mc.imp.transform.region.Rectangle 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 2 with Rectangle

use of com.builtbroken.mc.imp.transform.region.Rectangle 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)

Example 3 with Rectangle

use of com.builtbroken.mc.imp.transform.region.Rectangle in project Engine by VoltzEngine-Project.

the class RectangleTest method testIsWithin.

/**
     * Checks if the basic version of the point bounding box check is working
     */
public void testIsWithin() {
    Rectangle rect = new Rectangle(new Point(0, 0), new Point(2, 2));
    List<Point> points_inside = new LinkedList();
    points_inside.add(rect.cornerA());
    points_inside.add(rect.cornerB());
    points_inside.add(rect.cornerC());
    points_inside.add(rect.cornerD());
    points_inside.add(new Point(1, 1));
    List<Point> points_outside = new LinkedList();
    points_outside.add(new Point(-1, -1));
    points_outside.add(new Point(0, -1));
    points_outside.add(new Point(-1, 0));
    points_outside.add(new Point(3, 0));
    points_outside.add(new Point(0, 3));
    for (int i = 0; i < 4; i++) {
        //First two runs are inside checks
        boolean inside = i <= 1;
        boolean rotated = (i == 1 || i == 3);
        List<Point> l = inside ? points_inside : points_outside;
        for (Point vec : l) {
            boolean flag = !rotated ? rect.isWithin(vec) : rect.isWithin_rotated(vec);
            //Debug for when the checks fail and we need to know why
            if (flag != inside) {
                System.out.println("===   Debug   ===");
                if (!rotated) {
                    System.out.println("isWithinX: " + (vec.x() >= rect.min().x() && vec.x() <= rect.max().x()));
                    System.out.println("isWithinY: " + (vec.y() >= rect.min().y() && vec.y() <= rect.max().y()));
                } else {
                    double ab = new Triangle(rect.cornerA(), rect.cornerB(), vec).getArea();
                    double bc = new Triangle(rect.cornerB(), rect.cornerC(), vec).getArea();
                    double cd = new Triangle(rect.cornerC(), rect.cornerD(), vec).getArea();
                    double da = new Triangle(rect.cornerD(), rect.cornerA(), vec).getArea();
                    System.out.println("TriABP Area: " + ab);
                    System.out.println("TriBCP Area: " + bc);
                    System.out.println("TriCBP Area: " + cd);
                    System.out.println("TriDAP Area: " + da);
                    System.out.println("Total Area:  " + (ab + bc + cd + da));
                    System.out.println("Rect Area:   " + rect.getArea());
                }
                System.out.println("==================");
                //Failure message
                String msg = "Failed for ";
                msg += (!rotated ? "Normal Test " : "Rotated Test ");
                msg += vec + " ";
                msg += (inside ? " should be inside the rect!" : " should be outside the rect!");
                fail(msg);
            }
        }
    }
}
Also used : Rectangle(com.builtbroken.mc.imp.transform.region.Rectangle) Triangle(com.builtbroken.mc.imp.transform.region.Triangle) Point(com.builtbroken.mc.imp.transform.vector.Point) LinkedList(java.util.LinkedList) Point(com.builtbroken.mc.imp.transform.vector.Point)

Aggregations

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