Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.49 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package mygame;
  6.  
  7. //import java.util.Map;
  8.  
  9. import com.jme3.asset.AssetManager;
  10. import com.jme3.terrain.heightmap.AbstractHeightMap;
  11. import java.util.ArrayList;
  12.  
  13. import com.jme3.material.Material;
  14. import com.jme3.math.Vector2f;
  15.  
  16. import com.jme3.math.Vector3f;
  17. import com.jme3.math.Vector4f;
  18. import com.jme3.scene.Geometry;
  19. import com.jme3.scene.Mesh;
  20. import com.jme3.scene.Node;
  21. import java.util.Random;
  22.  
  23. import com.jme3.scene.VertexBuffer.Type;
  24. import com.jme3.terrain.heightmap.ImageBasedHeightMap;
  25. import com.jme3.texture.Texture;
  26. import com.jme3.util.BufferUtils;
  27. import jme3tools.converters.ImageToAwt;
  28.  
  29.  
  30.  
  31. /**
  32.  *
  33.  * @author nerminba
  34.  */
  35. public class Map extends Node
  36. {
  37.         
  38.         AbstractHeightMap heightmap = null;
  39.         
  40.         public static float DEFAULT_BLOCK_SIZE = 0.5f;
  41.         
  42.     int lengthX = 256;
  43.     int lengthY = 125;
  44.     int lengthZ = 256;
  45.     int mapCells[][][] = new int[lengthX][lengthY][lengthZ];
  46.         int lightCells[][][] = new int[lengthX][lengthY][lengthZ];
  47.     Mesh mapmesh = new Mesh();
  48.         
  49.     int rightFace = 0;
  50.     int leftFace = 1;
  51.     int topFace = 2;
  52.     int bottomFace = 3;
  53.     int frontFace = 4;
  54.     int backFace = 5;
  55.     
  56.     ArrayList<Vector3f> vertices = new ArrayList<Vector3f>(); // points
  57.     ArrayList<Vector3f> normals = new ArrayList<Vector3f>(); // normals
  58.     ArrayList<Vector2f> texCoord = new ArrayList<Vector2f>(); // tex cords
  59.     ArrayList<Integer> indexes = new ArrayList<Integer>(); // indexes
  60.         
  61.         
  62.         ArrayList<Vector4f> verticesColor = new ArrayList<Vector4f>();
  63.         
  64.     //String matDefName = "Common/MatDefs/Misc/ShowNormals.j3md";
  65.     //String matDefName = "Common/MatDefs/Light/Lighting.j3md";
  66.         String matDefName = "Common/MatDefs/Misc/Unshaded.j3md";
  67.  
  68.     float bsize = 1; // block size
  69.  
  70.         
  71.     // Texture coordinates
  72.     Vector2f [] texCoord2 = new Vector2f[4];
  73.         
  74.         //
  75.         AssetManager assetManager;
  76.         
  77.         public Map(AssetManager assetManager)
  78.         {
  79.                 this.assetManager = assetManager;
  80.                 Texture heightMapImage = assetManager.loadTexture("Textures/heightmap.jpg");
  81.             heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, false, 0));
  82.                 heightmap.load();
  83.                 testHeightMap();
  84.                 loadMapData();
  85.                 //addRandomCells();
  86.                 //initMyMap();
  87.                 //cleanEdgeCells();
  88.                 //castDownTheLight();
  89.                 build();
  90.         }
  91.         
  92.         private void testHeightMap()
  93.         {
  94.                 /*
  95.                 for(int x = 0; x < lengthX; x++ ) 
  96.                 {
  97.                         for (int z = 0; z < lengthZ; z++) 
  98.                         {
  99.                                 System.out.print("; ");
  100.                                 System.out.print("x: "+x+" z:"+z+" ->"+heightmap.getTrueHeightAtPoint(x, z));
  101.                         }
  102.                         System.out.print("\n");
  103.                 }
  104.                 */
  105.         }
  106.         
  107.         public void initMyMap()
  108.         {
  109.                 for (int z = 0; z < lengthZ; z++) {
  110.                         for(int x = 0; x < lengthX; x++ ) {
  111.                                 for (int y = 0; y < lengthY; y++) {
  112.                     mapCells[x][y][z] = 1;
  113.                 }
  114.             }
  115.         }
  116.         }
  117.         
  118.     private void loadMapData()
  119.         {
  120.                 for (int z = 0; z < lengthZ; z++) {
  121.                         for(int x = 0; x < lengthX; x++ ) {
  122.                                 for (int y = 0; y < (heightmap.getTrueHeightAtPoint(x, z)*0.08f); y++) {
  123.                                         /*
  124.                                         System.out.print("x: "+x+" ");
  125.                                         System.out.print("y: "+y+" ");
  126.                                         System.out.print("z: "+z+"\n");
  127.                                         */
  128.                     mapCells[x][y][z] = 1;
  129.                 }
  130.             }
  131.         }
  132.     }
  133.         
  134.         public void cleanEdgeCells()
  135.         {
  136.                 for (int x = 0; x < lengthX; x++) {
  137.                         for (int y = 0; y < lengthY; y++) {
  138.                                 mapCells[x][y][0] = 0;
  139.                                 mapCells[x][y][lengthZ-1] = 0;
  140.                                 mapCells[x][2][1] = 0;
  141.                                 mapCells[x][2][2] = 0;
  142.                         }
  143.                 }
  144.  
  145.                 for (int z = 0; z < lengthZ; z++) {
  146.                         for (int y = 0; y < lengthY; y++) {
  147.                                 mapCells[0][y][z] = 0;
  148.                                 mapCells[lengthX-1][y][z] = 0;
  149.                         }
  150.                 }
  151.                 
  152.                 
  153.         }
  154.         
  155.         public void initLightCells()
  156.         {
  157.                 for (int z = 0;  z < lengthZ;  z++)     
  158.                 {
  159.                         for (int x = 0;  x < lengthX;  x++)     
  160.                         {
  161.                                 for (int y = 0;  y < lengthY;  y++)     
  162.                                 {
  163.                                         lightCells[x][y][z] = 0;
  164.                                 }
  165.                         }
  166.                 }
  167.         }
  168.         
  169.         public void castDownTheLight()
  170.         {
  171.                 initLightCells();
  172.                 for (int z = 0;  z < lengthZ;  z++)     
  173.                 {
  174.                         for (int x = 0;  x < lengthX;  x++)     
  175.                         {
  176.                                 for (int y = 0;  y < lengthY;  y++)     
  177.                                 {
  178.                                         if(mapCells[x][y][z] == 1)
  179.                                         {
  180.                                                 break;
  181.                                         }
  182.                                         lightCells[x][y][z] = 1;
  183.                                 }
  184.                         }
  185.                 }
  186.         }
  187.         
  188.         public void addRandomCells()
  189.         {
  190.         Random r = new Random();
  191.         byte blocktype;
  192.                 
  193.         for (int y = 0;  y < lengthY;  y++)     {
  194.             for (int z = 0;  z < lengthZ;  z++) {
  195.                                 for (int x = 0;  x < lengthX;  x++)     {
  196.                     blocktype = 1; // default
  197.                     //if(y < 3) blocktype = 1; // base
  198.                     if(mapCells[x][y][z] == 1)
  199.                                         {
  200.                                                 if(r.nextInt(15) == 0) 
  201.                                                 { 
  202.                                                          blocktype = 0;
  203.                                                 }
  204.                                                 mapCells[x][y][z] = blocktype;
  205.                                         }
  206.                                         //System.out.print("mapCells["+x+"]["+y+"]["+z+"]:"+mapCells[x][y][z]+"\n");
  207.                                 }
  208.             }
  209.         }
  210.         }
  211.         
  212.         public void build()
  213.         {
  214.                 for (int z = 0;  z < lengthZ;  z++)     {
  215.                         for (int x = 0;  x < lengthX;  x++)     {
  216.                                 for (int y = 0;  y < lengthY;  y++)     {
  217.                                         if(mapCells[x][y][z] == 1)
  218.                                         {
  219.                                                 createWalls(checkSix(x,y,z), 0.0f+(x), 0.0f+(y), 0.0f+(z));
  220.                                         }
  221.                                 }
  222.                         }
  223.                 }
  224.                 
  225.                 
  226.                 /*
  227.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  228.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  229.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  230.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  231.                 
  232.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  233.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  234.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  235.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  236.                 
  237.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  238.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  239.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  240.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  241.                 
  242.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  243.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  244.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  245.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  246.                 
  247.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  248.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  249.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  250.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  251.                 
  252.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  253.                 verticesColor.add(new Vector4f(.1f, .1f, .1f, 1f));
  254.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  255.                 verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  256.                 */
  257.                 Vector4f[] c4 = verticesColor.toArray(new Vector4f[verticesColor.size()]);
  258.                 
  259.         int colorIndex = 0;
  260.                 float[] colorArray = new float[verticesColor.size()*4];
  261.         //Set custom RGBA value for each Vertex. Values range from 0.0f to 1.0f
  262.         for(int i = 0; i < verticesColor.size(); i++){
  263.            // Red value (is increased by .2 on each next vertex here)
  264.            colorArray[colorIndex++]= c4[i].x; //0.1f+(.2f*i);
  265.            // Green value (is reduced by .2 on each next vertex)
  266.            colorArray[colorIndex++]= c4[i].y; //0.9f-(0.2f*i);
  267.            // Blue value (remains the same in our case)
  268.            colorArray[colorIndex++]= c4[i].z;
  269.            // Alpha value (no transparency set here)
  270.            colorArray[colorIndex++]= c4[i].w;
  271.         }
  272.                 
  273.                 
  274.         Vector3f[] v3 = vertices.toArray(new Vector3f[vertices.size()]);
  275.                 /*Vector4f[] c4 = verticesColor.toArray(new Vector4f[verticesColor.size()]);*/
  276.         Vector3f[] n3 = normals.toArray(new Vector3f[normals.size()]);
  277.         Vector2f[] v2 = texCoord.toArray(new Vector2f[texCoord.size()]);
  278.         int indx[] = convertIntegers(indexes);
  279.  
  280.         mapmesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(v3));
  281.         mapmesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(n3));
  282.         mapmesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(v2));
  283.         mapmesh.setBuffer(Type.Index,    1, BufferUtils.createIntBuffer(indx));
  284.                 mapmesh.setBuffer(Type.Color, 4, colorArray);
  285.                 
  286.                 //System.out.print("test: "+c4[0].w);
  287.                 
  288.         mapmesh.updateBound();
  289.                 
  290.         // Creating a geometry, and apply a single color material to it
  291.         Geometry levelGeom = new Geometry("OurMesh", mapmesh);
  292.         Material mat1 = new Material(assetManager, matDefName);
  293.                 mat1.setTexture("ColorMap", assetManager.loadTexture("Textures/grass.png"));
  294.         mat1.setBoolean("VertexColor", true);
  295.                 
  296.                 levelGeom.setMaterial(mat1);
  297.                 this.attachChild(levelGeom);
  298.         }
  299.         
  300.         
  301.     private void createWalls(int faces[], float x, float y, float z)
  302.     {
  303.                 int verticesSize = vertices.size();
  304.                 float halfbsize = bsize/2;
  305.                 float bx, by, bz;
  306.                 bx = x * bsize;
  307.                 by = y * bsize;
  308.                 bz = z * bsize;
  309.                 
  310.                 for (int i = 0; i < faces.length; i++) {
  311.                         //System.out.print("face["+i+"]: "+faces[i]+"\n");
  312.                 }
  313.  
  314.                 Vector3f pa = new Vector3f(bx-halfbsize, by-halfbsize, bz+halfbsize);
  315.                 Vector3f pb = new Vector3f(bx+halfbsize, by-halfbsize, bz+halfbsize);
  316.                 Vector3f pc = new Vector3f(bx-halfbsize, by+halfbsize, bz+halfbsize);
  317.                 Vector3f pd = new Vector3f(bx+halfbsize, by+halfbsize, bz+halfbsize);
  318.  
  319.                 Vector3f pe = new Vector3f(bx-halfbsize, by-halfbsize, bz-halfbsize);
  320.                 Vector3f pf = new Vector3f(bx+halfbsize, by-halfbsize, bz-halfbsize);
  321.                 Vector3f pg = new Vector3f(bx-halfbsize, by+halfbsize, bz-halfbsize);
  322.                 Vector3f ph = new Vector3f(bx+halfbsize, by+halfbsize, bz-halfbsize);
  323.  
  324.                 Vector3f normalUp = new Vector3f(0, 1, 0);
  325.                 Vector3f normalDown = new Vector3f(0, -1, 0);
  326.                 Vector3f normalRight = new Vector3f(1, 0, 0);
  327.                 Vector3f normalLeft = new Vector3f(-1, 0, 0);
  328.                 Vector3f normalFront = new Vector3f(0, 0, 1);
  329.                 Vector3f normalBack = new Vector3f(0, 0, -1);
  330.  
  331.                 Vector2f t1 = new Vector2f(0, 0);
  332.                 Vector2f t2 = new Vector2f(1.0f, 0);
  333.                 Vector2f t3 = new Vector2f(0, 1.0f);
  334.                 Vector2f t4 = new Vector2f(1.0f, 1.0f);
  335.  
  336.                 //Vector2f top1 = new Vector2f(0.5f, 0.5f);
  337.                 //Vector2f top2 = new Vector2f(1.0f, 0.5f);
  338.                 //Vector2f top3 = new Vector2f(0.5f, 1.0f);
  339.                 //Vector2f top4 = new Vector2f(1.0f, 1.0f);
  340.  
  341.  
  342.                 // x = +
  343.                 if(faces[rightFace] == 1)
  344.                 {
  345.                         vertices.add(pb);
  346.                         vertices.add(pf);
  347.                         vertices.add(pd);
  348.                         vertices.add(ph);
  349.                         normals.add(normalRight);
  350.                         normals.add(normalRight);
  351.                         normals.add(normalRight);
  352.                         normals.add(normalRight);
  353.                         texCoord.add(t1);
  354.                         texCoord.add(t2);
  355.                         texCoord.add(t3);
  356.                         texCoord.add(t4);
  357.                         indexes.add(verticesSize+2);
  358.                         indexes.add(verticesSize+0);
  359.                         indexes.add(verticesSize+1);
  360.                         indexes.add(verticesSize+1);
  361.                         indexes.add(verticesSize+3);
  362.                         indexes.add(verticesSize+2);
  363.                         
  364.                         //vertex colors
  365.                         verticesColor.add(new Vector4f(.5f, .5f, .5f, 1f));
  366.                         verticesColor.add(new Vector4f(.5f, .5f, .5f, 1f));
  367.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  368.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  369.                 }
  370.  
  371.                 // x = -
  372.                 if(faces[leftFace] == 1)
  373.                 {
  374.                         verticesSize = vertices.size();
  375.  
  376.                         vertices.add(pe);
  377.                         vertices.add(pa);
  378.                         vertices.add(pg);
  379.                         vertices.add(pc);
  380.                         normals.add(normalLeft);
  381.                         normals.add(normalLeft);
  382.                         normals.add(normalLeft);
  383.                         normals.add(normalLeft);
  384.                         texCoord.add(t1);
  385.                         texCoord.add(t2);
  386.                         texCoord.add(t3);
  387.                         texCoord.add(t4);
  388.                         indexes.add(verticesSize+2);
  389.                         indexes.add(verticesSize+0);
  390.                         indexes.add(verticesSize+1);
  391.                         indexes.add(verticesSize+1);
  392.                         indexes.add(verticesSize+3);
  393.                         indexes.add(verticesSize+2);
  394.                         
  395.                         verticesColor.add(new Vector4f(.5f, .5f, .5f, 1f));
  396.                         verticesColor.add(new Vector4f(.5f, .5f, .5f, 1f));
  397.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  398.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  399.                 }
  400.                 //y = +
  401.                 if(faces[topFace] == 1)
  402.                 {
  403.                         verticesSize = vertices.size();
  404.  
  405.                         vertices.add(pc);
  406.                         vertices.add(pd);
  407.                         vertices.add(pg);
  408.                         vertices.add(ph);
  409.                         normals.add(normalUp);
  410.                         normals.add(normalUp);
  411.                         normals.add(normalUp);
  412.                         normals.add(normalUp);
  413.                         texCoord.add(t1);
  414.                         texCoord.add(t2);
  415.                         texCoord.add(t3);
  416.                         texCoord.add(t4);
  417.                         indexes.add(verticesSize+2);
  418.                         indexes.add(verticesSize+0);
  419.                         indexes.add(verticesSize+1);
  420.                         indexes.add(verticesSize+1);
  421.                         indexes.add(verticesSize+3);
  422.                         indexes.add(verticesSize+2);
  423.                         
  424.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  425.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  426.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  427.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  428.                 }
  429.                 //y = -
  430.                 if(faces[bottomFace] == 1)
  431.                 {
  432.                         verticesSize = vertices.size();
  433.                         
  434.                         vertices.add(pe);
  435.                         vertices.add(pf);
  436.                         vertices.add(pa);
  437.                         vertices.add(pb);
  438.                         normals.add(normalDown);
  439.                         normals.add(normalDown);
  440.                         normals.add(normalDown);
  441.                         normals.add(normalDown);
  442.                         texCoord.add(t1);
  443.                         texCoord.add(t2);
  444.                         texCoord.add(t3);
  445.                         texCoord.add(t4);
  446.                         indexes.add(verticesSize+2);
  447.                         indexes.add(verticesSize+0);
  448.                         indexes.add(verticesSize+1);
  449.                         indexes.add(verticesSize+1);
  450.                         indexes.add(verticesSize+3);
  451.                         indexes.add(verticesSize+2);
  452.                         
  453.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  454.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  455.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  456.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  457.                 }
  458.  
  459.                 if(faces[frontFace] == 1)
  460.                 {
  461.                         verticesSize = vertices.size();
  462.                         
  463.                         vertices.add(pa);
  464.                         vertices.add(pb);
  465.                         vertices.add(pc);
  466.                         vertices.add(pd);
  467.                         normals.add(normalFront);
  468.                         normals.add(normalFront);
  469.                         normals.add(normalFront);
  470.                         normals.add(normalFront);
  471.                         texCoord.add(t1);
  472.                         texCoord.add(t2);
  473.                         texCoord.add(t3);
  474.                         texCoord.add(t4);
  475.                         indexes.add(verticesSize+2);
  476.                         indexes.add(verticesSize+0);
  477.                         indexes.add(verticesSize+1);
  478.                         indexes.add(verticesSize+1);
  479.                         indexes.add(verticesSize+3);
  480.                         indexes.add(verticesSize+2);
  481.                         
  482.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  483.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  484.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  485.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  486.                 }
  487.  
  488.                 if(faces[backFace] == 1)
  489.                 {
  490.                         verticesSize = vertices.size();
  491.  
  492.                         vertices.add(pf);
  493.                         vertices.add(pe);
  494.                         vertices.add(ph);
  495.                         vertices.add(pg);
  496.                         normals.add(normalBack);
  497.                         normals.add(normalBack);
  498.                         normals.add(normalBack);
  499.                         normals.add(normalBack);
  500.                         texCoord.add(t1);
  501.                         texCoord.add(t2);
  502.                         texCoord.add(t3);
  503.                         texCoord.add(t4);
  504.                         indexes.add(verticesSize+2);
  505.                         indexes.add(verticesSize+0);
  506.                         indexes.add(verticesSize+1);
  507.                         indexes.add(verticesSize+1);
  508.                         indexes.add(verticesSize+3);
  509.                         indexes.add(verticesSize+2);
  510.                         
  511.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  512.                         verticesColor.add(new Vector4f(.25f, .25f, .25f, 1f));
  513.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  514.                         verticesColor.add(new Vector4f(1f, 1f, 1f, 1f));
  515.                 }
  516.         }
  517.         
  518.         private int[] checkSix(int x, int y, int z) 
  519.         {
  520.                 //System.out.println("checkSix: " + x + ", " + y + ", " + z);
  521.  
  522.                 int faces[] = new int[6];
  523.  
  524.                 for (int i = 0; i < faces.length; i++) {
  525.                         faces[i] = 1;
  526.                 }
  527.  
  528.                 // right face
  529.                 if (indexExists(lengthX, (x+1)))
  530.                 {
  531.                         if(mapCells[x+1][y][z] == 1){ faces[0] = 0; }
  532.                 }
  533.                 //System.out.println("right face: "+faces[0]);
  534.  
  535.                 // left face
  536.                 //int xD = x-1;
  537.                 if (indexExists(lengthX, x-1))
  538.                 {
  539.                         if(mapCells[x-1][y][z] == 1){ faces[1] = 0; }
  540.                 }
  541.                 //System.out.println("left face: "+faces[1]);
  542.  
  543.                 // top face
  544.                 if (indexExists(lengthY, y+1))
  545.                 {
  546.                         if(mapCells[x][y+1][z] == 1){ faces[2] = 0; }
  547.                 }
  548.                 //System.out.println("top face: "+faces[2]);
  549.  
  550.                 // bottom face
  551.                 if (indexExists(lengthY, y-1))
  552.                 {
  553.                         if(mapCells[x][y-1][z] == 1){ faces[3] = 0; }
  554.                 }
  555.                 //System.out.println("bottom face: "+faces[3]);
  556.                 // back face
  557.                 if (indexExists(lengthZ, z+1))
  558.                 {
  559.                         if(mapCells[x][y][z+1] == 1){ faces[4] = 0; }
  560.                 }
  561.                 //System.out.println("back face: "+faces[4]);
  562.                 // front face
  563.                 if (indexExists(lengthZ, z-1))
  564.                 {
  565.                         if(mapCells[x][y][z-1] == 1){ faces[5] = 0; }
  566.                 }
  567.                 //System.out.println("front face: "+faces[5]);
  568.                 return faces;
  569.         }
  570.  
  571.         public boolean indexExists(int size, int index) 
  572.         {
  573.                 boolean result = false;
  574.                 if (index >= 0 && index < size){
  575.                         result = true;
  576.                 }
  577.                 return result;
  578.         }
  579.         
  580.         public static int[] convertIntegers(ArrayList<Integer> integers)
  581.         {
  582.                 int[] ret = new int[integers.size()];
  583.                 for (int i=0; i < ret.length; i++)
  584.                 {
  585.                         ret[i] = integers.get(i).intValue();
  586.                 }
  587.                 return ret;
  588.         }
  589.                         
  590.     
  591. }
Add Comment
Please, Sign In to add comment