Add the Lod object and supporting objects

This commit is contained in:
James Seibel
2020-09-25 09:09:43 -05:00
parent 73592971d3
commit e116047bc8
3 changed files with 203 additions and 0 deletions
@@ -0,0 +1,137 @@
package backsun.lod.objects;
import java.awt.Color;
/**
* This object contains position
* and color data for an LOD object.
*
* @author James Seibel
* @version 09-25-2020
*/
public class LodChunk
{
// each Vec3 is the average location of
// 8th of the chunk.
public Vec3 top[];
public Vec3 bottom[];
/** */
public Color colors[];
public LodChunk()
{
top = new Vec3[4];
bottom = new Vec3[4];
colors = new Color[6];
}
public LodChunk(Vec3[] newTop, Vec3[] newBottom, Color newColors[])
{
top = newTop;
bottom = newBottom;
colors = newColors;
}
/**
* Similar to toString, but supports different delimiters,
* and has fewer overall characters ("top " is written as "t").
* <br>
* Exports data in the form "t", (top data), "b", (bottom data), "c", (rgb color data)
*/
public String toData(String delimiter, String endDelimiter)
{
String s = "";
s += "t";
for(int i = 0; i < top.length; i++)
{
s += top[i].toData(delimiter,delimiter);
if (i != top.length - 1)
{
// separate each item, except the
// last item
s += delimiter;
}
}
s += "b";
for(int i = 0; i < bottom.length; i++)
{
s += bottom[i].toData(delimiter,delimiter);
if (i != bottom.length - 1)
{
s += delimiter;
}
}
s += "c";
for(int i = 0; i < colors.length; i++)
{
s += colors[i].getRed() + delimiter + colors[i].getGreen() + delimiter + colors[i].getBlue();
if (i != colors.length - 1)
{
s += delimiter;
}
}
s += endDelimiter;
return s;
}
@Override
public String toString()
{
String s = "";
s += "top: ";
for(int i = 0; i < top.length; i++)
{
s += top[i].toString();
if (i != top.length - 1)
{
// separate each item, except the
// last item
s += " ";
}
}
s += "\n";
s += "bottom: ";
for(int i = 0; i < bottom.length; i++)
{
s += bottom[i].toString();
if (i != bottom.length - 1)
{
s += " ";
}
}
s += "\n";
s += "colors ";
for(int i = 0; i < colors.length; i++)
{
s += colors[i].getRed() + ", " + colors[i].getGreen() + ", " + colors[i].getBlue();
if (i != colors.length - 1)
{
s += " ";
}
}
return s;
}
}
@@ -0,0 +1,30 @@
package backsun.lod.objects;
/**
* Position: NE, SE, SW, NW
* <br>
* Color: TOP, N, S, E, W, BOTTOM
*/
public enum Pos
{
// used for position
NE(0),
SE(1),
SW(2),
NW(3),
// used for colors
TOP(0),
N(1),
S(2),
E(3),
W(4),
BOTTOM(5);
public final int index;
private Pos(int newValue)
{
index = newValue;
}
}
@@ -0,0 +1,36 @@
package backsun.lod.objects;
/**
* @author James Seibel
* @version 09-25-2020
*/
public class Vec3
{
public short x = 0;
public short y = 0;
public short z = 0;
public Vec3(int newX, int newY, int newZ)
{
x = (short) newX;
y = (short) newY;
z = (short) newZ;
}
/**
* Exports data in the form:
* <br>
* x, y, z
*/
public String toData(String delimiter, String endDelimiter)
{
return x + delimiter + y + delimiter + z + endDelimiter;
}
@Override
public String toString()
{
return "x: " + x + " y: " + y + " z: " + z;
}
}