auto-indent
This commit is contained in:
@@ -12,30 +12,29 @@ import com.seibel.lod.wrappers.MinecraftWrapper;
|
||||
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3i;
|
||||
|
||||
/**
|
||||
* Similar to Minecraft's AxisAlignedBoundingBox.
|
||||
*
|
||||
* @author Leonardo Amato
|
||||
* @version 9-25-2021
|
||||
* @version 10-2-2021
|
||||
*/
|
||||
public class Box
|
||||
{
|
||||
|
||||
|
||||
public static final int ADJACENT_HEIGHT_INDEX = 0;
|
||||
public static final int ADJACENT_DEPTH_INDEX = 1;
|
||||
|
||||
|
||||
public static final int X = 0;
|
||||
public static final int Y = 1;
|
||||
public static final int Z = 2;
|
||||
|
||||
|
||||
public static final int MIN = 0;
|
||||
public static final int MAX = 1;
|
||||
|
||||
|
||||
public static final int VOID_FACE = 0;
|
||||
|
||||
|
||||
/** The six cardinal directions */
|
||||
public static final Direction[] DIRECTIONS = new Direction[]{
|
||||
Direction.UP,
|
||||
@@ -44,16 +43,16 @@ public class Box
|
||||
Direction.EAST,
|
||||
Direction.NORTH,
|
||||
Direction.SOUTH};
|
||||
|
||||
|
||||
/** North, South, East, West */
|
||||
public static final Direction[] ADJ_DIRECTIONS = new Direction[]{
|
||||
Direction.EAST,
|
||||
Direction.WEST,
|
||||
Direction.SOUTH,
|
||||
Direction.NORTH};
|
||||
|
||||
|
||||
/**
|
||||
* All the faces and vertex of a cube. This is used to extract the vertex of the column
|
||||
* All the faces and vertices of a cube. This is used to extract the vertex from the column
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static final Map<Direction, int[][]> DIRECTION_VERTEX_MAP = new HashMap<Direction, int[][]>()
|
||||
@@ -89,8 +88,8 @@ public class Box
|
||||
{1, 1, 0},
|
||||
{1, 0, 0}});
|
||||
}};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This indicate which position is invariable in the DIRECTION_VERTEX_MAP.
|
||||
* Is used to extract the vertex
|
||||
@@ -105,8 +104,8 @@ public class Box
|
||||
put(Direction.SOUTH, new int[]{Z, MAX});
|
||||
put(Direction.NORTH, new int[]{Z, MIN});
|
||||
}};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is a map from Direction to the relative normal vector
|
||||
* we are using this since i'm not sure if the getNormal create new object at every call
|
||||
@@ -120,7 +119,7 @@ public class Box
|
||||
put(Direction.SOUTH, Direction.SOUTH.getNormal());
|
||||
put(Direction.NORTH, Direction.NORTH.getNormal());
|
||||
}};
|
||||
|
||||
|
||||
/**
|
||||
* We use this index for all array that are going to
|
||||
*/
|
||||
@@ -133,7 +132,7 @@ public class Box
|
||||
put(Direction.SOUTH, 4);
|
||||
put(Direction.NORTH, 5);
|
||||
}};
|
||||
|
||||
|
||||
public static final Map<Direction, Integer> ADJ_DIRECTION_INDEX = new HashMap<Direction, Integer>()
|
||||
{{
|
||||
put(Direction.EAST, 0);
|
||||
@@ -145,7 +144,7 @@ public class Box
|
||||
public int[] boxOffset;
|
||||
/** holds the box's x, y, z width */
|
||||
public int[] boxWidth;
|
||||
|
||||
|
||||
/** Holds each direction's color */
|
||||
public int[] colorMap;
|
||||
/** The original color (before shading) of this box */
|
||||
@@ -153,20 +152,20 @@ public class Box
|
||||
/** */
|
||||
public Map<Direction, int[]> adjHeight;
|
||||
public Map<Direction, int[]> adjDepth;
|
||||
|
||||
|
||||
/** Holds if the given direction should be culled or not */
|
||||
public boolean[] culling;
|
||||
|
||||
|
||||
|
||||
|
||||
/** creates a empty box */
|
||||
@SuppressWarnings("serial")
|
||||
public Box()
|
||||
{
|
||||
boxOffset = new int[3];
|
||||
boxWidth = new int[3];
|
||||
|
||||
|
||||
colorMap = new int[6];
|
||||
|
||||
|
||||
// TODO what does the 32 represent?
|
||||
adjHeight = new HashMap<Direction, int[]>()
|
||||
{{
|
||||
@@ -182,11 +181,11 @@ public class Box
|
||||
put(Direction.SOUTH, new int[32]);
|
||||
put(Direction.NORTH, new int[32]);
|
||||
}};
|
||||
|
||||
|
||||
culling = new boolean[6];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the color of the columns
|
||||
* @param color color to add
|
||||
@@ -203,7 +202,7 @@ public class Box
|
||||
colorMap[DIRECTION_INDEX.get(direction)] = color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param direction of the face of which we want to get the color
|
||||
* @return color of the face
|
||||
@@ -219,22 +218,22 @@ public class Box
|
||||
return ColorUtil.applyShade(color, MinecraftWrapper.INSTANCE.getClientWorld().getShade(direction, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** clears this box, reseting everything to default values */
|
||||
public void reset()
|
||||
{
|
||||
Arrays.fill(boxWidth, 0);
|
||||
Arrays.fill(boxOffset, 0);
|
||||
Arrays.fill(colorMap, 0);
|
||||
|
||||
|
||||
for (Direction direction : ADJ_DIRECTIONS)
|
||||
{
|
||||
// TODO wouldn't we want to set all adjHeightAndDepth
|
||||
// to VOID_FACE regardless of the culled status?
|
||||
if (isCulled(direction))
|
||||
continue;
|
||||
|
||||
|
||||
for (int i = 0; i < adjHeight.get(direction).length; i++)
|
||||
{
|
||||
adjHeight.get(direction)[i] = VOID_FACE;
|
||||
@@ -242,7 +241,7 @@ public class Box
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** determine which faces should be culled */
|
||||
public void setUpCulling(int cullingDistance, BlockPos playerPos)
|
||||
{
|
||||
@@ -259,7 +258,7 @@ public class Box
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param direction direction that we want to check if it's culled
|
||||
* @return true if and only if the face of the direction is culled
|
||||
@@ -268,8 +267,8 @@ public class Box
|
||||
{
|
||||
return culling[DIRECTION_INDEX.get(direction)];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This method create all the shared face culling based on the adjacent data
|
||||
* @param adjData data adjacent to the column we are going to render
|
||||
@@ -284,7 +283,7 @@ public class Box
|
||||
{
|
||||
//if (isCulled(direction))
|
||||
// continue;
|
||||
|
||||
|
||||
long[] dataPoint = adjData.get(direction);
|
||||
if (dataPoint == null || DataPointUtil.isVoid(dataPoint[0]))
|
||||
{
|
||||
@@ -294,7 +293,7 @@ public class Box
|
||||
adjDepth.get(direction)[1] = VOID_FACE;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
int i;
|
||||
int faceToDraw = 0;
|
||||
boolean firstFace = true;
|
||||
@@ -304,20 +303,20 @@ public class Box
|
||||
for (i = 0; i < dataPoint.length; i++)
|
||||
{
|
||||
singleAdjDataPoint = dataPoint[i];
|
||||
|
||||
|
||||
if(DataPointUtil.isVoid(singleAdjDataPoint) || !DataPointUtil.doesItExist(singleAdjDataPoint))
|
||||
break;
|
||||
|
||||
|
||||
height = DataPointUtil.getHeight(singleAdjDataPoint);
|
||||
depth = DataPointUtil.getDepth(singleAdjDataPoint);
|
||||
|
||||
|
||||
if (depth <= maxY)
|
||||
{
|
||||
allAbove = false;
|
||||
if (height < minY)
|
||||
{
|
||||
// the adj data is lower than the current data
|
||||
|
||||
|
||||
if (firstFace)
|
||||
{
|
||||
adjHeight.get(direction)[0] = getMaxY();
|
||||
@@ -329,7 +328,7 @@ public class Box
|
||||
}
|
||||
faceToDraw++;
|
||||
toFinish = false;
|
||||
|
||||
|
||||
// break since all the other data will be lower
|
||||
break;
|
||||
}
|
||||
@@ -370,13 +369,13 @@ public class Box
|
||||
else
|
||||
{
|
||||
// if (depth > minY && height < maxY)
|
||||
|
||||
|
||||
// the adj data is contained in the current data
|
||||
if (firstFace)
|
||||
{
|
||||
adjHeight.get(direction)[0] = getMaxY();
|
||||
}
|
||||
|
||||
|
||||
adjDepth.get(direction)[faceToDraw] = height;
|
||||
faceToDraw++;
|
||||
adjHeight.get(direction)[faceToDraw] = depth;
|
||||
@@ -385,7 +384,7 @@ public class Box
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(allAbove)
|
||||
{
|
||||
adjHeight.get(direction)[0] = getMaxY();
|
||||
@@ -397,12 +396,12 @@ public class Box
|
||||
adjDepth.get(direction)[faceToDraw] = minY;
|
||||
faceToDraw++;
|
||||
}
|
||||
|
||||
|
||||
adjHeight.get(direction)[faceToDraw] = VOID_FACE;
|
||||
adjDepth.get(direction)[faceToDraw] = VOID_FACE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We use this method to set the various width of the column
|
||||
* @param xWidth
|
||||
@@ -415,7 +414,7 @@ public class Box
|
||||
boxWidth[Y] = yWidth;
|
||||
boxWidth[Z] = zWidth;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We use this method to set the various offset of the column
|
||||
* @param xOffset
|
||||
@@ -428,7 +427,7 @@ public class Box
|
||||
boxOffset[Y] = yOffset;
|
||||
boxOffset[Z] = zOffset;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method return the position of a face in the axis of the face
|
||||
* This is usefull for the face culling
|
||||
@@ -439,7 +438,7 @@ public class Box
|
||||
{
|
||||
return boxOffset[FACE_DIRECTION.get(direction)[0]] + boxWidth[FACE_DIRECTION.get(direction)[0]] * FACE_DIRECTION.get(direction)[1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns true if the given direction should be rendered.
|
||||
*/
|
||||
@@ -451,8 +450,8 @@ public class Box
|
||||
}
|
||||
return !(adjHeight.get(direction)[adjIndex] == VOID_FACE && adjDepth.get(direction)[adjIndex] == VOID_FACE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param direction direction of the face we want to render
|
||||
@@ -463,7 +462,7 @@ public class Box
|
||||
{
|
||||
return boxOffset[X] + boxWidth[X] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][X];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param direction direction of the face we want to render
|
||||
@@ -474,7 +473,7 @@ public class Box
|
||||
{
|
||||
return boxOffset[Y] + boxWidth[Y] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][Y];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param direction direction of the face we want to render
|
||||
@@ -502,7 +501,7 @@ public class Box
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param direction direction of the face we want to render
|
||||
@@ -513,37 +512,37 @@ public class Box
|
||||
{
|
||||
return boxOffset[Z] + boxWidth[Z] * DIRECTION_VERTEX_MAP.get(direction)[vertexIndex][Z];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int getMinX()
|
||||
{
|
||||
return boxOffset[X];
|
||||
}
|
||||
|
||||
|
||||
public int getMaxX()
|
||||
{
|
||||
return boxOffset[X] + boxWidth[X];
|
||||
}
|
||||
|
||||
|
||||
public int getMinY()
|
||||
{
|
||||
return boxOffset[Y];
|
||||
}
|
||||
|
||||
|
||||
public int getMaxY()
|
||||
{
|
||||
return boxOffset[Y] + boxWidth[Y];
|
||||
}
|
||||
|
||||
|
||||
public int getMinZ()
|
||||
{
|
||||
return boxOffset[Z];
|
||||
}
|
||||
|
||||
|
||||
public int getMaxZ()
|
||||
{
|
||||
return boxOffset[Z] + boxWidth[Z];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user