I'm trying to creat an axis aligned bounding box (aabb) and would like to get the min and max values of all my vertice coordinates.
I'm reading from an obj file to get the vertex coordinates, the print out would be a list of x,y,z coordinates in float numbers.
float xVertices;
float yVertices;
float zVertices;
private void getObjVertices(String fileName)
{
BufferedReader meshReader = null;
try
{
meshReader = new BufferedReader(new FileReader(fileName));
String line;
while((line = meshReader.readLine()) != null)
{
String[] tokens = line.split(" ");
tokens = Util.RemoveEmptyStrings(tokens);
if(tokens.length == 0 || tokens[0].equals("#") ||
tokens[0].equals("vt") || tokens[0].equals("vn") || tokens[0].equals("f"))
continue;
else if(tokens[0].equals("v"))
{
xVertices = Float.parseFloat(tokens[1]);
yVertices = Float.parseFloat(tokens[2]);
zVertices = Float.parseFloat(tokens[3]);
System.out.println("xVertices:" + xVertices);
System.out.println("yVertices:" + yVertices);
System.out.println("zVertices:" + zVertices);
// get min/max x,y,z values, calculatre width, height, depth
}
}
meshReader.close();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
What I would like to achieve is to get all xVertices, yVertices, zVertices and find out which number in each axis is greates and which is smallest.
With this information I would be able to create the collider.. has someone an idea how I can calclate greates and smallest numbers in my code?
Thanks for any help in advance!