ArrayList<Float> posBuffer = new ArrayList<>();
ArrayList<Float> uvBuffer = new ArrayList<>();
ArrayList<Float> norBuffer = new ArrayList<>();
ArrayList<Float> idBuffer = new ArrayList<>();
Matrix4f transMat = new Matrix4f();
Matrix4f rotMat = new Matrix4f();
Vector4f translatedVertex = new Vector4f();
Vector4f rotatedNormal = new Vector4f();
float[] temp = new float[9];
for(int row = 0; row < Map.chunkSize; row++) {
for(int col = 0; col < Map.chunkSize; col++) {
int x = xStart+col;
int y = yStart+row;
if(map.get(y, x) == Map.EMPTY){
/* Nothing to be added*/
continue;
}
ArrayList<Mesh> msh = new ArrayList<>();
int scan[] = map.scan(y, x);
float mRotation = 0f;
/* Set transform matrix for this piece of track */
transMat.setIdentity();
rotMat.setIdentity();
/* Translate by x,z coordinates */
transMat.translate(new Vector3f(y, 0, x));
int trackType = getTrackType(map.get(y, x), scan, map.scanRideable(y, x));
/* Populate msh list with right .obj meshes */
switch(trackType){
case EW_STRAIGHT:
mRotation -= 90f;
rotMat.rotate((float) Math.toRadians(mRotation), new Vector3f(0, 1, 0));
case NS_STRAIGHT:
//msh.add(trackStraight);
msh.add(objMeshes.get("res/mesh/track.obj"));
break;
case NSEW_CROSS:
//msh.add(trackXCrossing);
msh.add(objMeshes.get("res/mesh/track_x_cross.obj"));
break;
case NE_CURVE:
mRotation -= 90f;
case NW_CURVE:
mRotation -= 90f;
case SW_CURVE:
mRotation -= 90f;
rotMat.rotate((float) Math.toRadians(mRotation), new Vector3f(0, 1, 0));
case SE_CURVE:
//msh.add(track90Corner);
msh.add(objMeshes.get("res/mesh/track_90_corner.obj"));
break;
case WNE_CROSS:
mRotation -= 90f;
case SWN_CROSS:
mRotation -= 90f;
case ESW_CROSS:
mRotation -= 90f;
rotMat.rotate((float) Math.toRadians(mRotation), new Vector3f(0, 1, 0));
case NES_CROSS:
//msh.add(trackTCrossing);
msh.add(objMeshes.get("res/mesh/track_t_cross.obj"));
break;
case EW_STATION:
mRotation -= 90f;
rotMat.rotate((float) Math.toRadians(mRotation), new Vector3f(0, 1, 0));
case NS_STATION:
//msh.add(trackStraight);
//msh.add(station);
msh.add(objMeshes.get("res/mesh/track.obj"));
msh.add(objMeshes.get("res/mesh/station2.obj"));
if(rand.nextFloat() > 0.5f){
//msh.add(station_bin);
msh.add(objMeshes.get("res/mesh/station2_bin.obj"));
}
if(rand.nextFloat() > 0.5f){
//msh.add(station_bench);
msh.add(objMeshes.get("res/mesh/station2_bench.obj"));
}
if(rand.nextFloat() > 0.75f){
//msh.add(station_map);
msh.add(objMeshes.get("res/mesh/station2_map.obj"));
}
break;
case WNE_STATION:
mRotation -= 90f;
case SWN_STATION:
mRotation -= 90f;
case ESW_STATION:
mRotation -= 90f;
rotMat.rotate((float) Math.toRadians(mRotation), new Vector3f(0, 1, 0));
case NES_STATION:
//msh.add(trackTCrossing);
//msh.add(station);
msh.add(objMeshes.get("res/mesh/track_t_cross.obj"));
msh.add(objMeshes.get("res/mesh/station2.obj"));
if(rand.nextFloat() > 0.5f){
//msh.add(station_bin);
msh.add(objMeshes.get("res/mesh/station2_bin.obj"));
}
if(rand.nextFloat() > 0.5f){
//msh.add(station_bench);
msh.add(objMeshes.get("res/mesh/station2_bench.obj"));
}
if(rand.nextFloat() > 0.75f){
//msh.add(station_map);
msh.add(objMeshes.get("res/mesh/station2_map.obj"));
}
break;
case TREE:
transMat.translate(new Vector3f(((float)Math.random()-0.5f)*0.8f, 0, ((float)Math.random()-0.5f)*0.8f));
rotMat.rotate((float) Math.toRadians(Math.random()*360.0), new Vector3f(0, 1, 0));
msh.add(objMeshes.get("res/mesh/cactus_trunk.obj"));
if(rand.nextFloat() > 0.15f){
msh.add(objMeshes.get("res/mesh/cactus_branch1.obj"));
}
if(rand.nextFloat() > 0.15f){