* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
*/\r
-\r
package com.jme3.terrain.geomipmap;\r
\r
import com.jme3.export.InputCapsule;\r
*/\r
public class LODGeomap extends BufferGeomap {\r
\r
- public LODGeomap() {}\r
+ public LODGeomap() {\r
+ }\r
\r
public LODGeomap(int size, FloatBuffer heightMap) {\r
- super(heightMap, null, size, size, 1);\r
- }\r
-\r
- public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center) {\r
- return this.createMesh(scale, tcScale, tcOffset, offsetAmount, totalSize, center, 1, false,false,false,false);\r
- }\r
-\r
- public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod){\r
- FloatBuffer pb = writeVertexArray(null, scale, center);\r
- FloatBuffer tb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);\r
- FloatBuffer nb = writeNormalArray(null, scale);\r
- IntBuffer ib = writeIndexArrayLodDiff(null, lod, rightLod, topLod, leftLod, bottomLod);\r
- Mesh m = new Mesh();\r
- m.setMode(Mode.TriangleStrip);\r
- m.setBuffer(Type.Position, 3, pb);\r
- m.setBuffer(Type.Normal, 3, nb);\r
- m.setBuffer(Type.TexCoord, 2, tb);\r
- m.setBuffer(Type.Index, 3, ib);\r
- m.setStatic();\r
- m.updateBound();\r
- return m;\r
- }\r
+ super(heightMap, null, size, size, 1);\r
+ }\r
\r
+ public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center) {\r
+ return this.createMesh(scale, tcScale, tcOffset, offsetAmount, totalSize, center, 1, false, false, false, false);\r
+ }\r
+\r
+ public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) {\r
+ FloatBuffer pb = writeVertexArray(null, scale, center);\r
+ FloatBuffer tb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);\r
+ FloatBuffer nb = writeNormalArray(null, scale);\r
+ IntBuffer ib = writeIndexArrayLodDiff(null, lod, rightLod, topLod, leftLod, bottomLod);\r
+ Mesh m = new Mesh();\r
+ m.setMode(Mode.TriangleStrip);\r
+ m.setBuffer(Type.Position, 3, pb);\r
+ m.setBuffer(Type.Normal, 3, nb);\r
+ m.setBuffer(Type.TexCoord, 2, tb);\r
+ m.setBuffer(Type.Index, 3, ib);\r
+ m.setStatic();\r
+ m.updateBound();\r
+ return m;\r
+ }\r
\r
protected void removeNormalBuffer() {\r
ndata = null;\r
}\r
\r
- public FloatBuffer writeTexCoordArray(FloatBuffer store, Vector2f offset, Vector2f scale, float offsetAmount, int totalSize){\r
- if (store!=null){\r
- if (store.remaining() < getWidth()*getHeight()*2)\r
- throw new BufferUnderflowException();\r
- }else{\r
- store = BufferUtils.createFloatBuffer(getWidth()*getHeight()*2);\r
- }\r
+ public FloatBuffer writeTexCoordArray(FloatBuffer store, Vector2f offset, Vector2f scale, float offsetAmount, int totalSize) {\r
+ if (store != null) {\r
+ if (store.remaining() < getWidth() * getHeight() * 2) {\r
+ throw new BufferUnderflowException();\r
+ }\r
+ } else {\r
+ store = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 2);\r
+ }\r
\r
- if (offset == null)\r
- offset = new Vector2f();\r
+ if (offset == null) {\r
+ offset = new Vector2f();\r
+ }\r
\r
- Vector2f tcStore = new Vector2f();\r
+ Vector2f tcStore = new Vector2f();\r
\r
- for (int y = 0; y < getHeight(); y++){\r
+ for (int y = 0; y < getHeight(); y++) {\r
\r
- for (int x = 0; x < getWidth(); x++){\r
- getUV(x,y,tcStore, offset, offsetAmount, totalSize);\r
- float tx = tcStore.x * scale.x;\r
- float ty = tcStore.y * scale.y;\r
- store.put( tx );\r
- store.put( ty );\r
- }\r
- }\r
+ for (int x = 0; x < getWidth(); x++) {\r
+ getUV(x, y, tcStore, offset, offsetAmount, totalSize);\r
+ float tx = tcStore.x * scale.x;\r
+ float ty = tcStore.y * scale.y;\r
+ store.put(tx);\r
+ store.put(ty);\r
+ }\r
+ }\r
\r
- return store;\r
- }\r
+ return store;\r
+ }\r
\r
- public Vector2f getUV(int x, int y, Vector2f store, Vector2f offset, float offsetAmount, int totalSize){\r
- float offsetX = offset.x + (offsetAmount * 1.0f);//stepScale.x);\r
+ public Vector2f getUV(int x, int y, Vector2f store, Vector2f offset, float offsetAmount, int totalSize) {\r
+ float offsetX = offset.x + (offsetAmount * 1.0f);//stepScale.x);\r
float offsetY = offset.y + (offsetAmount * 1.0f);//stepScale.z);\r
\r
- store.set( ( ((float)x)+offsetX) / (float)totalSize, // calculates percentage of texture here\r
- ( ((float)y)+offsetY) / (float)totalSize );\r
+ store.set((((float) x) + offsetX) / (float) totalSize, // calculates percentage of texture here\r
+ (((float) y) + offsetY) / (float) totalSize);\r
return store;\r
}\r
\r
- /**\r
- * Create the LOD index array that will seam its edges with its neighbour's LOD.\r
- * This is a scary method!!! It will break your mind.\r
- *\r
- * @param store to store the index buffer\r
- * @param lod level of detail of the mesh\r
- * @param rightLod LOD of the right neighbour\r
- * @param topLod LOD of the top neighbour\r
- * @param leftLod LOD of the left neighbour\r
- * @param bottomLod LOD of the bottom neighbour\r
- * @return the LOD-ified index buffer\r
- */\r
- public IntBuffer writeIndexArrayLodDiff(IntBuffer store, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod){\r
-\r
- IntBuffer buffer2 = store;\r
- int numIndexes = calculateNumIndexesLodDiff(lod);\r
- if (store == null)\r
- buffer2 = BufferUtils.createIntBuffer(numIndexes);\r
- VerboseIntBuffer buffer = new VerboseIntBuffer(buffer2);\r
-\r
-\r
- // generate center squares minus the edges\r
- //System.out.println("for (x="+lod+"; x<"+(getWidth()-(2*lod))+"; x+="+lod+")");\r
- //System.out.println(" for (z="+lod+"; z<"+(getWidth()-(1*lod))+"; z+="+lod+")");\r
- for (int r=lod; r<getWidth()-(2*lod); r+=lod) { // row\r
- int rowIdx = r*getWidth();\r
- int nextRowIdx = (r+1*lod)*getWidth();\r
- for (int c=lod; c<getWidth()-(1*lod); c+=lod) { // column\r
- int idx = rowIdx+c;\r
- buffer.put(idx);\r
- idx = nextRowIdx+c;\r
- buffer.put(idx);\r
- }\r
-\r
- // add degenerate triangles\r
- if (r < getWidth()-(3*lod)) {\r
- int idx = nextRowIdx+getWidth()-(1*lod)-1;\r
- buffer.put(idx);\r
- idx = nextRowIdx+(1*lod); // inset by 1\r
- buffer.put(idx);\r
- //System.out.println("");\r
- }\r
- }\r
- //System.out.println("\nright:");\r
-\r
- //int runningBufferCount = buffer.getCount();\r
- //System.out.println("buffer start: "+runningBufferCount);\r
-\r
-\r
- // right\r
- int br = getWidth()*(getWidth()-lod)-1-lod;\r
- buffer.put(br); // bottom right -1\r
- int corner = getWidth()*getWidth()-1;\r
- buffer.put(corner); // bottom right corner\r
- if (rightLod) { // if lower LOD\r
- for (int row=getWidth()-lod; row>=1+lod; row-=2*lod) {\r
- int idx = (row)*getWidth()-1-lod;\r
- buffer.put(idx);\r
- idx = (row-lod)*getWidth()-1;\r
- buffer.put(idx);\r
- if (row > lod+1) { //if not the last one\r
- idx = (row-lod)*getWidth()-1-lod;\r
- buffer.put(idx);\r
- idx = (row-lod)*getWidth()-1;\r
- buffer.put(idx);\r
- } else {\r
-\r
- }\r
- }\r
- } else {\r
- buffer.put(corner);//br+1);//degenerate to flip winding order\r
- for (int row=getWidth()-lod; row>lod; row-=lod) {\r
- int idx = row*getWidth()-1; // mult to get row\r
- buffer.put(idx);\r
- buffer.put(idx-lod);\r
- }\r
-\r
- }\r
-\r
- buffer.put(getWidth()-1);\r
-\r
-\r
- //System.out.println("\nbuffer right: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
-\r
- //System.out.println("\ntop:");\r
-\r
- // top (the order gets reversed here so the diagonals line up)\r
- if (topLod) { // if lower LOD\r
- if (rightLod)\r
- buffer.put(getWidth()-1);\r
- for (int col=getWidth()-1; col>=lod; col-=2*lod) {\r
- int idx = (lod*getWidth())+col-lod; // next row\r
- buffer.put(idx);\r
- idx = col-2*lod;\r
- buffer.put(idx);\r
- if (col > lod*2) { //if not the last one\r
- idx = (lod*getWidth())+col-2*lod;\r
- buffer.put(idx);\r
- idx = col-2*lod;\r
- buffer.put(idx);\r
- } else {\r
-\r
- }\r
- }\r
- } else {\r
- if (rightLod)\r
- buffer.put(getWidth()-1);\r
- for (int col=getWidth()-1-lod; col>0; col-=lod) {\r
- int idx = col + (lod*getWidth());\r
- buffer.put(idx);\r
- idx = col;\r
- buffer.put(idx);\r
- }\r
- buffer.put(0);\r
- }\r
- buffer.put(0);\r
-\r
- //System.out.println("\nbuffer top: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
- //System.out.println("\nleft:");\r
-\r
- // left\r
- if (leftLod) { // if lower LOD\r
- if (topLod)\r
- buffer.put(0);\r
- for (int row=0; row<getWidth()-lod; row+=2*lod) {\r
- int idx = (row+lod)*getWidth()+lod;\r
- buffer.put(idx);\r
- idx = (row+2*lod)*getWidth();\r
- buffer.put(idx);\r
- if (row < getWidth()-lod-2-1) { //if not the last one\r
- idx = (row+2*lod)*getWidth()+lod;\r
- buffer.put(idx);\r
- idx = (row+2*lod)*getWidth();\r
- buffer.put(idx);\r
- } else {\r
-\r
- }\r
- }\r
- } else {\r
- if (!topLod)\r
- buffer.put(0);\r
- //buffer.put(getWidth()+1); // degenerate\r
- //buffer.put(0); // degenerate winding-flip\r
- for (int row=lod; row<getWidth()-lod; row+=lod) {\r
- int idx = row*getWidth();\r
- buffer.put(idx);\r
- idx = row*getWidth()+lod;\r
- buffer.put(idx);\r
- }\r
-\r
- }\r
- buffer.put(getWidth()*(getWidth()-1));\r
-\r
-\r
- //System.out.println("\nbuffer left: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
- //if (true) return buffer.delegate;\r
- //System.out.println("\nbottom");\r
-\r
- // bottom\r
- if (bottomLod) { // if lower LOD\r
- if (leftLod)\r
- buffer.put(getWidth()*(getWidth()-1));\r
- // there was a slight bug here when really high LOD near maxLod\r
- // far right has extra index one row up and all the way to the right, need to skip last index entered\r
- // seemed to be fixed by making "getWidth()-1-2-lod" this: "getWidth()-1-2*lod", which seems more correct\r
- for (int col=0; col<getWidth()-lod; col+=2*lod) {\r
- int idx = getWidth()*(getWidth()-1-lod)+col+lod;\r
- buffer.put(idx);\r
- idx = getWidth()*(getWidth()-1)+col+2*lod;\r
- buffer.put(idx);\r
- if (col < getWidth()-1-2*lod) { //if not the last one\r
- idx = getWidth()*(getWidth()-1-lod)+col+2*lod;\r
- buffer.put(idx);\r
- idx = getWidth()*(getWidth()-1)+col+2*lod;\r
- buffer.put(idx);\r
- } else {\r
-\r
- }\r
- }\r
- } else {\r
- if (leftLod) {\r
- buffer.put(getWidth()*(getWidth()-1));\r
- }\r
- for (int col=lod; col<getWidth()-lod; col+=lod) {\r
- int idx = getWidth()*(getWidth()-1-lod) + col; // up\r
- buffer.put(idx);\r
- idx = getWidth()*(getWidth()-1) + col; // down\r
- buffer.put(idx);\r
- }\r
- //buffer.put(getWidth()*getWidth()-1-lod); // <-- THIS caused holes at the end!\r
- }\r
-\r
- buffer.put(getWidth()*getWidth()-1);\r
-\r
- //System.out.println("\nbuffer bottom: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
- //System.out.println("\nBuffer size: "+buffer.getCount());\r
-\r
- // fill in the rest of the buffer with degenerates, there should only be a couple\r
- for (int i=buffer.getCount(); i<numIndexes; i++)\r
- buffer.put(getWidth()*getWidth()-1);\r
-\r
- return buffer.delegate;\r
- }\r
-\r
- public IntBuffer writeIndexArrayLodVariable(IntBuffer store, int lod, int rightLod, int topLod, int leftLod, int bottomLod){\r
-\r
- IntBuffer buffer2 = store;\r
- int numIndexes = calculateNumIndexesLodDiff(lod);\r
- if (store == null)\r
- buffer2 = BufferUtils.createIntBuffer(numIndexes);\r
- VerboseIntBuffer buffer = new VerboseIntBuffer(buffer2);\r
-\r
-\r
- // generate center squares minus the edges\r
- //System.out.println("for (x="+lod+"; x<"+(getWidth()-(2*lod))+"; x+="+lod+")");\r
- //System.out.println(" for (z="+lod+"; z<"+(getWidth()-(1*lod))+"; z+="+lod+")");\r
- for (int r=lod; r<getWidth()-(2*lod); r+=lod) { // row\r
- int rowIdx = r*getWidth();\r
- int nextRowIdx = (r+1*lod)*getWidth();\r
- for (int c=lod; c<getWidth()-(1*lod); c+=lod) { // column\r
- int idx = rowIdx+c;\r
- buffer.put(idx);\r
- idx = nextRowIdx+c;\r
- buffer.put(idx);\r
- }\r
-\r
- // add degenerate triangles\r
- if (r < getWidth()-(3*lod)) {\r
- int idx = nextRowIdx+getWidth()-(1*lod)-1;\r
- buffer.put(idx);\r
- idx = nextRowIdx+(1*lod); // inset by 1\r
- buffer.put(idx);\r
- //System.out.println("");\r
- }\r
- }\r
- //System.out.println("\nright:");\r
-\r
- //int runningBufferCount = buffer.getCount();\r
- //System.out.println("buffer start: "+runningBufferCount);\r
-\r
-\r
- // right\r
- int br = getWidth()*(getWidth()-lod)-1-lod;\r
- buffer.put(br); // bottom right -1\r
- int corner = getWidth()*getWidth()-1;\r
- buffer.put(corner); // bottom right corner\r
- if (rightLod>lod) { // if lower LOD\r
+ /**\r
+ * Create the LOD index array that will seam its edges with its neighbour's LOD.\r
+ * This is a scary method!!! It will break your mind.\r
+ *\r
+ * @param store to store the index buffer\r
+ * @param lod level of detail of the mesh\r
+ * @param rightLod LOD of the right neighbour\r
+ * @param topLod LOD of the top neighbour\r
+ * @param leftLod LOD of the left neighbour\r
+ * @param bottomLod LOD of the bottom neighbour\r
+ * @return the LOD-ified index buffer\r
+ */\r
+ public IntBuffer writeIndexArrayLodDiff(IntBuffer store, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) {\r
+\r
+ IntBuffer buffer2 = store;\r
+ int numIndexes = calculateNumIndexesLodDiff(lod);\r
+ if (store == null) {\r
+ buffer2 = BufferUtils.createIntBuffer(numIndexes);\r
+ }\r
+ VerboseIntBuffer buffer = new VerboseIntBuffer(buffer2);\r
+\r
+\r
+ // generate center squares minus the edges\r
+ //System.out.println("for (x="+lod+"; x<"+(getWidth()-(2*lod))+"; x+="+lod+")");\r
+ //System.out.println(" for (z="+lod+"; z<"+(getWidth()-(1*lod))+"; z+="+lod+")");\r
+ for (int r = lod; r < getWidth() - (2 * lod); r += lod) { // row\r
+ int rowIdx = r * getWidth();\r
+ int nextRowIdx = (r + 1 * lod) * getWidth();\r
+ for (int c = lod; c < getWidth() - (1 * lod); c += lod) { // column\r
+ int idx = rowIdx + c;\r
+ buffer.put(idx);\r
+ idx = nextRowIdx + c;\r
+ buffer.put(idx);\r
+ }\r
+\r
+ // add degenerate triangles\r
+ if (r < getWidth() - (3 * lod)) {\r
+ int idx = nextRowIdx + getWidth() - (1 * lod) - 1;\r
+ buffer.put(idx);\r
+ idx = nextRowIdx + (1 * lod); // inset by 1\r
+ buffer.put(idx);\r
+ //System.out.println("");\r
+ }\r
+ }\r
+ //System.out.println("\nright:");\r
+\r
+ //int runningBufferCount = buffer.getCount();\r
+ //System.out.println("buffer start: "+runningBufferCount);\r
+\r
+\r
+ // right\r
+ int br = getWidth() * (getWidth() - lod) - 1 - lod;\r
+ buffer.put(br); // bottom right -1\r
+ int corner = getWidth() * getWidth() - 1;\r
+ buffer.put(corner); // bottom right corner\r
+ if (rightLod) { // if lower LOD\r
+ for (int row = getWidth() - lod; row >= 1 + lod; row -= 2 * lod) {\r
+ int idx = (row) * getWidth() - 1 - lod;\r
+ buffer.put(idx);\r
+ idx = (row - lod) * getWidth() - 1;\r
+ buffer.put(idx);\r
+ if (row > lod + 1) { //if not the last one\r
+ idx = (row - lod) * getWidth() - 1 - lod;\r
+ buffer.put(idx);\r
+ idx = (row - lod) * getWidth() - 1;\r
+ buffer.put(idx);\r
+ } else {\r
+ }\r
+ }\r
+ } else {\r
+ buffer.put(corner);//br+1);//degenerate to flip winding order\r
+ for (int row = getWidth() - lod; row > lod; row -= lod) {\r
+ int idx = row * getWidth() - 1; // mult to get row\r
+ buffer.put(idx);\r
+ buffer.put(idx - lod);\r
+ }\r
+\r
+ }\r
+\r
+ buffer.put(getWidth() - 1);\r
+\r
+\r
+ //System.out.println("\nbuffer right: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+\r
+ //System.out.println("\ntop:");\r
+\r
+ // top (the order gets reversed here so the diagonals line up)\r
+ if (topLod) { // if lower LOD\r
+ if (rightLod) {\r
+ buffer.put(getWidth() - 1);\r
+ }\r
+ for (int col = getWidth() - 1; col >= lod; col -= 2 * lod) {\r
+ int idx = (lod * getWidth()) + col - lod; // next row\r
+ buffer.put(idx);\r
+ idx = col - 2 * lod;\r
+ buffer.put(idx);\r
+ if (col > lod * 2) { //if not the last one\r
+ idx = (lod * getWidth()) + col - 2 * lod;\r
+ buffer.put(idx);\r
+ idx = col - 2 * lod;\r
+ buffer.put(idx);\r
+ } else {\r
+ }\r
+ }\r
+ } else {\r
+ if (rightLod) {\r
+ buffer.put(getWidth() - 1);\r
+ }\r
+ for (int col = getWidth() - 1 - lod; col > 0; col -= lod) {\r
+ int idx = col + (lod * getWidth());\r
+ buffer.put(idx);\r
+ idx = col;\r
+ buffer.put(idx);\r
+ }\r
+ buffer.put(0);\r
+ }\r
+ buffer.put(0);\r
+\r
+ //System.out.println("\nbuffer top: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+ //System.out.println("\nleft:");\r
+\r
+ // left\r
+ if (leftLod) { // if lower LOD\r
+ if (topLod) {\r
+ buffer.put(0);\r
+ }\r
+ for (int row = 0; row < getWidth() - lod; row += 2 * lod) {\r
+ int idx = (row + lod) * getWidth() + lod;\r
+ buffer.put(idx);\r
+ idx = (row + 2 * lod) * getWidth();\r
+ buffer.put(idx);\r
+ if (row < getWidth() - lod - 2 - 1) { //if not the last one\r
+ idx = (row + 2 * lod) * getWidth() + lod;\r
+ buffer.put(idx);\r
+ idx = (row + 2 * lod) * getWidth();\r
+ buffer.put(idx);\r
+ } else {\r
+ }\r
+ }\r
+ } else {\r
+ if (!topLod) {\r
+ buffer.put(0);\r
+ }\r
+ //buffer.put(getWidth()+1); // degenerate\r
+ //buffer.put(0); // degenerate winding-flip\r
+ for (int row = lod; row < getWidth() - lod; row += lod) {\r
+ int idx = row * getWidth();\r
+ buffer.put(idx);\r
+ idx = row * getWidth() + lod;\r
+ buffer.put(idx);\r
+ }\r
+\r
+ }\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+\r
+\r
+ //System.out.println("\nbuffer left: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+ //if (true) return buffer.delegate;\r
+ //System.out.println("\nbottom");\r
+\r
+ // bottom\r
+ if (bottomLod) { // if lower LOD\r
+ if (leftLod) {\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ }\r
+ // there was a slight bug here when really high LOD near maxLod\r
+ // far right has extra index one row up and all the way to the right, need to skip last index entered\r
+ // seemed to be fixed by making "getWidth()-1-2-lod" this: "getWidth()-1-2*lod", which seems more correct\r
+ for (int col = 0; col < getWidth() - lod; col += 2 * lod) {\r
+ int idx = getWidth() * (getWidth() - 1 - lod) + col + lod;\r
+ buffer.put(idx);\r
+ idx = getWidth() * (getWidth() - 1) + col + 2 * lod;\r
+ buffer.put(idx);\r
+ if (col < getWidth() - 1 - 2 * lod) { //if not the last one\r
+ idx = getWidth() * (getWidth() - 1 - lod) + col + 2 * lod;\r
+ buffer.put(idx);\r
+ idx = getWidth() * (getWidth() - 1) + col + 2 * lod;\r
+ buffer.put(idx);\r
+ } else {\r
+ }\r
+ }\r
+ } else {\r
+ if (leftLod) {\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ }\r
+ for (int col = lod; col < getWidth() - lod; col += lod) {\r
+ int idx = getWidth() * (getWidth() - 1 - lod) + col; // up\r
+ buffer.put(idx);\r
+ idx = getWidth() * (getWidth() - 1) + col; // down\r
+ buffer.put(idx);\r
+ }\r
+ //buffer.put(getWidth()*getWidth()-1-lod); // <-- THIS caused holes at the end!\r
+ }\r
+\r
+ buffer.put(getWidth() * getWidth() - 1);\r
+\r
+ //System.out.println("\nbuffer bottom: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+ //System.out.println("\nBuffer size: "+buffer.getCount());\r
+\r
+ // fill in the rest of the buffer with degenerates, there should only be a couple\r
+ for (int i = buffer.getCount(); i < numIndexes; i++) {\r
+ buffer.put(getWidth() * getWidth() - 1);\r
+ }\r
+\r
+ return buffer.delegate;\r
+ }\r
+\r
+ public IntBuffer writeIndexArrayLodVariable(IntBuffer store, int lod, int rightLod, int topLod, int leftLod, int bottomLod) {\r
+\r
+ IntBuffer buffer2 = store;\r
+ int numIndexes = calculateNumIndexesLodDiff(lod);\r
+ if (store == null) {\r
+ buffer2 = BufferUtils.createIntBuffer(numIndexes);\r
+ }\r
+ VerboseIntBuffer buffer = new VerboseIntBuffer(buffer2);\r
+\r
+\r
+ // generate center squares minus the edges\r
+ //System.out.println("for (x="+lod+"; x<"+(getWidth()-(2*lod))+"; x+="+lod+")");\r
+ //System.out.println(" for (z="+lod+"; z<"+(getWidth()-(1*lod))+"; z+="+lod+")");\r
+ for (int r = lod; r < getWidth() - (2 * lod); r += lod) { // row\r
+ int rowIdx = r * getWidth();\r
+ int nextRowIdx = (r + 1 * lod) * getWidth();\r
+ for (int c = lod; c < getWidth() - (1 * lod); c += lod) { // column\r
+ int idx = rowIdx + c;\r
+ buffer.put(idx);\r
+ idx = nextRowIdx + c;\r
+ buffer.put(idx);\r
+ }\r
+\r
+ // add degenerate triangles\r
+ if (r < getWidth() - (3 * lod)) {\r
+ int idx = nextRowIdx + getWidth() - (1 * lod) - 1;\r
+ buffer.put(idx);\r
+ idx = nextRowIdx + (1 * lod); // inset by 1\r
+ buffer.put(idx);\r
+ //System.out.println("");\r
+ }\r
+ }\r
+ //System.out.println("\nright:");\r
+\r
+ //int runningBufferCount = buffer.getCount();\r
+ //System.out.println("buffer start: "+runningBufferCount);\r
+\r
+\r
+ // right\r
+ int br = getWidth() * (getWidth() - lod) - 1 - lod;\r
+ buffer.put(br); // bottom right -1\r
+ int corner = getWidth() * getWidth() - 1;\r
+ buffer.put(corner); // bottom right corner\r
+ if (rightLod > lod) { // if lower LOD\r
int idx = corner;\r
- int it = (getWidth()-1)/rightLod; // iterations\r
- int lodDiff = rightLod/lod;\r
- for (int i=it; i>0; i--) { // for each lod level of the neighbour\r
- idx = getWidth()*(i*rightLod+1)-1;\r
- for (int j=1; j<=lodDiff; j++) { // for each section in that lod level\r
- int idxB = idx - (getWidth()*(j*lod)) - lod;\r
+ int it = (getWidth() - 1) / rightLod; // iterations\r
+ int lodDiff = rightLod / lod;\r
+ for (int i = it; i > 0; i--) { // for each lod level of the neighbour\r
+ idx = getWidth() * (i * rightLod + 1) - 1;\r
+ for (int j = 1; j <= lodDiff; j++) { // for each section in that lod level\r
+ int idxB = idx - (getWidth() * (j * lod)) - lod;\r
\r
if (j == lodDiff && i == 1) {// the last one\r
- buffer.put(getWidth()-1);\r
+ buffer.put(getWidth() - 1);\r
} else if (j == lodDiff) {\r
buffer.put(idxB);\r
- buffer.put(idxB+lod);\r
+ buffer.put(idxB + lod);\r
} else {\r
buffer.put(idxB);\r
buffer.put(idx);\r
}\r
}\r
// reset winding order\r
- buffer.put(getWidth()*(lod+1)-lod-1); // top-right +1row\r
- buffer.put(getWidth()-1);// top-right\r
-\r
- } else {\r
- buffer.put(corner);//br+1);//degenerate to flip winding order\r
- for (int row=getWidth()-lod; row>lod; row-=lod) {\r
- int idx = row*getWidth()-1; // mult to get row\r
- buffer.put(idx);\r
- buffer.put(idx-lod);\r
- }\r
- buffer.put(getWidth()-1);\r
- }\r
+ buffer.put(getWidth() * (lod + 1) - lod - 1); // top-right +1row\r
+ buffer.put(getWidth() - 1);// top-right\r
+\r
+ } else {\r
+ buffer.put(corner);//br+1);//degenerate to flip winding order\r
+ for (int row = getWidth() - lod; row > lod; row -= lod) {\r
+ int idx = row * getWidth() - 1; // mult to get row\r
+ buffer.put(idx);\r
+ buffer.put(idx - lod);\r
+ }\r
+ buffer.put(getWidth() - 1);\r
+ }\r
\r
\r
- //System.out.println("\nbuffer right: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
+ //System.out.println("\nbuffer right: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
\r
\r
- //System.out.println("\ntop:");\r
+ //System.out.println("\ntop:");\r
\r
- // top (the order gets reversed here so the diagonals line up)\r
- if (topLod>lod) { // if lower LOD\r
- if (rightLod>lod) {\r
+ // top (the order gets reversed here so the diagonals line up)\r
+ if (topLod > lod) { // if lower LOD\r
+ if (rightLod > lod) {\r
// need to flip winding order\r
- buffer.put(getWidth()-1);\r
- buffer.put(getWidth()*lod -1);\r
- buffer.put(getWidth()-1);\r
- }\r
- int idx = getWidth()-1;\r
- int it = (getWidth()-1)/topLod; // iterations\r
- int lodDiff = topLod/lod;\r
- for (int i=it; i>0; i--) { // for each lod level of the neighbour\r
- idx = (i*topLod);\r
- for (int j=1; j<=lodDiff; j++) { // for each section in that lod level\r
- int idxB = lod*getWidth() +(i*topLod) - (j*lod);\r
+ buffer.put(getWidth() - 1);\r
+ buffer.put(getWidth() * lod - 1);\r
+ buffer.put(getWidth() - 1);\r
+ }\r
+ int idx = getWidth() - 1;\r
+ int it = (getWidth() - 1) / topLod; // iterations\r
+ int lodDiff = topLod / lod;\r
+ for (int i = it; i > 0; i--) { // for each lod level of the neighbour\r
+ idx = (i * topLod);\r
+ for (int j = 1; j <= lodDiff; j++) { // for each section in that lod level\r
+ int idxB = lod * getWidth() + (i * topLod) - (j * lod);\r
\r
if (j == lodDiff && i == 1) {// the last one\r
buffer.put(0);\r
} else if (j == lodDiff) {\r
buffer.put(idxB);\r
- buffer.put(idx-topLod);\r
+ buffer.put(idx - topLod);\r
} else {\r
buffer.put(idxB);\r
buffer.put(idx);\r
}\r
}\r
}\r
- } else {\r
- if (rightLod>lod)\r
- buffer.put(getWidth()-1);\r
- for (int col=getWidth()-1-lod; col>0; col-=lod) {\r
- int idx = col + (lod*getWidth());\r
- buffer.put(idx);\r
- idx = col;\r
- buffer.put(idx);\r
- }\r
- buffer.put(0);\r
- }\r
- buffer.put(0);\r
-\r
- //System.out.println("\nbuffer top: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
- //System.out.println("\nleft:");\r
-\r
- // left\r
- if (leftLod>lod) { // if lower LOD\r
-\r
- int idx = 0;\r
- int it = (getWidth()-1)/leftLod; // iterations\r
- int lodDiff = leftLod/lod;\r
- for (int i=0; i<it; i++) { // for each lod level of the neighbour\r
- idx = getWidth()*(i*leftLod);\r
- for (int j=1; j<=lodDiff; j++) { // for each section in that lod level\r
- int idxB = idx +(getWidth()*(j*lod)) +lod;\r
-\r
- if (j == lodDiff && i == it-1) {// the last one\r
- buffer.put(getWidth()*getWidth() - getWidth());\r
+ } else {\r
+ if (rightLod > lod) {\r
+ buffer.put(getWidth() - 1);\r
+ }\r
+ for (int col = getWidth() - 1 - lod; col > 0; col -= lod) {\r
+ int idx = col + (lod * getWidth());\r
+ buffer.put(idx);\r
+ idx = col;\r
+ buffer.put(idx);\r
+ }\r
+ buffer.put(0);\r
+ }\r
+ buffer.put(0);\r
+\r
+ //System.out.println("\nbuffer top: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+ //System.out.println("\nleft:");\r
+\r
+ // left\r
+ if (leftLod > lod) { // if lower LOD\r
+\r
+ int idx = 0;\r
+ int it = (getWidth() - 1) / leftLod; // iterations\r
+ int lodDiff = leftLod / lod;\r
+ for (int i = 0; i < it; i++) { // for each lod level of the neighbour\r
+ idx = getWidth() * (i * leftLod);\r
+ for (int j = 1; j <= lodDiff; j++) { // for each section in that lod level\r
+ int idxB = idx + (getWidth() * (j * lod)) + lod;\r
+\r
+ if (j == lodDiff && i == it - 1) {// the last one\r
+ buffer.put(getWidth() * getWidth() - getWidth());\r
} else if (j == lodDiff) {\r
buffer.put(idxB);\r
- buffer.put(idxB-lod);\r
+ buffer.put(idxB - lod);\r
} else {\r
buffer.put(idxB);\r
buffer.put(idx);\r
}\r
}\r
\r
- } else {\r
- buffer.put(0);\r
- buffer.put(getWidth()*lod + lod);\r
- buffer.put(0);\r
- for (int row=lod; row<getWidth()-lod; row+=lod) {\r
- int idx = row*getWidth();\r
- buffer.put(idx);\r
- idx = row*getWidth()+lod;\r
- buffer.put(idx);\r
- }\r
- buffer.put(getWidth()*(getWidth()-1));\r
- }\r
- //buffer.put(getWidth()*(getWidth()-1));\r
-\r
-\r
- //System.out.println("\nbuffer left: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
- //if (true) return buffer.delegate;\r
- //System.out.println("\nbottom");\r
-\r
- // bottom\r
- if (bottomLod>lod) { // if lower LOD\r
- if (leftLod>lod) {\r
- buffer.put(getWidth()*(getWidth()-1));\r
- buffer.put(getWidth()*(getWidth()-lod));\r
- buffer.put(getWidth()*(getWidth()-1));\r
- }\r
-\r
- int idx = getWidth()*getWidth() - getWidth();\r
- int it = (getWidth()-1)/bottomLod; // iterations\r
- int lodDiff = bottomLod/lod;\r
- for (int i=0; i<it; i++) { // for each lod level of the neighbour\r
- idx = getWidth()*getWidth() - getWidth() + (i*bottomLod);\r
- for (int j=1; j<=lodDiff; j++) { // for each section in that lod level\r
- int idxB = idx - (getWidth()*lod) +j*lod;\r
-\r
- if (j == lodDiff && i == it-1) {// the last one\r
- buffer.put(getWidth()*getWidth()-1);\r
+ } else {\r
+ buffer.put(0);\r
+ buffer.put(getWidth() * lod + lod);\r
+ buffer.put(0);\r
+ for (int row = lod; row < getWidth() - lod; row += lod) {\r
+ int idx = row * getWidth();\r
+ buffer.put(idx);\r
+ idx = row * getWidth() + lod;\r
+ buffer.put(idx);\r
+ }\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ }\r
+ //buffer.put(getWidth()*(getWidth()-1));\r
+\r
+\r
+ //System.out.println("\nbuffer left: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+ //if (true) return buffer.delegate;\r
+ //System.out.println("\nbottom");\r
+\r
+ // bottom\r
+ if (bottomLod > lod) { // if lower LOD\r
+ if (leftLod > lod) {\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ buffer.put(getWidth() * (getWidth() - lod));\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ }\r
+\r
+ int idx = getWidth() * getWidth() - getWidth();\r
+ int it = (getWidth() - 1) / bottomLod; // iterations\r
+ int lodDiff = bottomLod / lod;\r
+ for (int i = 0; i < it; i++) { // for each lod level of the neighbour\r
+ idx = getWidth() * getWidth() - getWidth() + (i * bottomLod);\r
+ for (int j = 1; j <= lodDiff; j++) { // for each section in that lod level\r
+ int idxB = idx - (getWidth() * lod) + j * lod;\r
+\r
+ if (j == lodDiff && i == it - 1) {// the last one\r
+ buffer.put(getWidth() * getWidth() - 1);\r
} else if (j == lodDiff) {\r
buffer.put(idxB);\r
- buffer.put(idx+bottomLod);\r
+ buffer.put(idx + bottomLod);\r
} else {\r
buffer.put(idxB);\r
buffer.put(idx);\r
}\r
}\r
}\r
- } else {\r
- if (leftLod>lod) {\r
- buffer.put(getWidth()*(getWidth()-1));\r
- buffer.put(getWidth()*getWidth() - (getWidth()*lod)+lod);\r
- buffer.put(getWidth()*(getWidth()-1));\r
- }\r
- for (int col=lod; col<getWidth()-lod; col+=lod) {\r
- int idx = getWidth()*(getWidth()-1-lod) + col; // up\r
- buffer.put(idx);\r
- idx = getWidth()*(getWidth()-1) + col; // down\r
- buffer.put(idx);\r
- }\r
- //buffer.put(getWidth()*getWidth()-1-lod); // <-- THIS caused holes at the end!\r
- }\r
-\r
- buffer.put(getWidth()*getWidth()-1);\r
-\r
- //System.out.println("\nbuffer bottom: "+(buffer.getCount()-runningBufferCount));\r
- //runningBufferCount = buffer.getCount();\r
-\r
- //System.out.println("\nBuffer size: "+buffer.getCount());\r
-\r
- // fill in the rest of the buffer with degenerates, there should only be a couple\r
- for (int i=buffer.getCount(); i<numIndexes; i++)\r
- buffer.put(getWidth()*getWidth()-1);\r
-\r
- return buffer.delegate;\r
- }\r
-\r
-\r
- /*private int calculateNumIndexesNormal(int lod) {\r
- int length = getWidth()-1;\r
- int num = ((length/lod)+1)*((length/lod)+1)*2;\r
- System.out.println("num: "+num);\r
- num -= 2*((length/lod)+1);\r
- System.out.println("num2: "+num);\r
- // now get the degenerate indexes that exist between strip rows\r
- num += 2*(((length/lod)+1)-2); // every row except the first and last\r
- System.out.println("Index buffer size: "+num);\r
- return num;\r
- }*/\r
-\r
- /**\r
- * calculate how many indexes there will be.\r
- * This isn't that precise and there might be a couple extra.\r
- */\r
- private int calculateNumIndexesLodDiff(int lod) {\r
- if (lod == 0)\r
+ } else {\r
+ if (leftLod > lod) {\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ buffer.put(getWidth() * getWidth() - (getWidth() * lod) + lod);\r
+ buffer.put(getWidth() * (getWidth() - 1));\r
+ }\r
+ for (int col = lod; col < getWidth() - lod; col += lod) {\r
+ int idx = getWidth() * (getWidth() - 1 - lod) + col; // up\r
+ buffer.put(idx);\r
+ idx = getWidth() * (getWidth() - 1) + col; // down\r
+ buffer.put(idx);\r
+ }\r
+ //buffer.put(getWidth()*getWidth()-1-lod); // <-- THIS caused holes at the end!\r
+ }\r
+\r
+ buffer.put(getWidth() * getWidth() - 1);\r
+\r
+ //System.out.println("\nbuffer bottom: "+(buffer.getCount()-runningBufferCount));\r
+ //runningBufferCount = buffer.getCount();\r
+\r
+ //System.out.println("\nBuffer size: "+buffer.getCount());\r
+\r
+ // fill in the rest of the buffer with degenerates, there should only be a couple\r
+ for (int i = buffer.getCount(); i < numIndexes; i++) {\r
+ buffer.put(getWidth() * getWidth() - 1);\r
+ }\r
+\r
+ return buffer.delegate;\r
+ }\r
+\r
+\r
+ /*private int calculateNumIndexesNormal(int lod) {\r
+ int length = getWidth()-1;\r
+ int num = ((length/lod)+1)*((length/lod)+1)*2;\r
+ System.out.println("num: "+num);\r
+ num -= 2*((length/lod)+1);\r
+ System.out.println("num2: "+num);\r
+ // now get the degenerate indexes that exist between strip rows\r
+ num += 2*(((length/lod)+1)-2); // every row except the first and last\r
+ System.out.println("Index buffer size: "+num);\r
+ return num;\r
+ }*/\r
+ /**\r
+ * calculate how many indexes there will be.\r
+ * This isn't that precise and there might be a couple extra.\r
+ */\r
+ private int calculateNumIndexesLodDiff(int lod) {\r
+ if (lod == 0) {\r
lod = 1;\r
- int length = getWidth()-1; // make it even for lod calc\r
- int side = (length/lod)+1 -(2);\r
- //System.out.println("side: "+side);\r
- int num = side*side*2;\r
- //System.out.println("num: "+num);\r
- num -= 2*side; // remove one first row and one last row (they are only hit once each)\r
- //System.out.println("num2: "+num);\r
- // now get the degenerate indexes that exist between strip rows\r
- int degenerates = 2*(side-(2)); // every row except the first and last\r
- num += degenerates;\r
- //System.out.println("degenerates: "+degenerates);\r
-\r
- //System.out.println("center, before edges: "+num);\r
-\r
- num += (getWidth()/lod)*2 *4;\r
- num++;\r
-\r
- num+=10;// TODO remove me: extra\r
- //System.out.println("Index buffer size: "+num);\r
- return num;\r
- }\r
+ }\r
+ int length = getWidth() - 1; // make it even for lod calc\r
+ int side = (length / lod) + 1 - (2);\r
+ //System.out.println("side: "+side);\r
+ int num = side * side * 2;\r
+ //System.out.println("num: "+num);\r
+ num -= 2 * side; // remove one first row and one last row (they are only hit once each)\r
+ //System.out.println("num2: "+num);\r
+ // now get the degenerate indexes that exist between strip rows\r
+ int degenerates = 2 * (side - (2)); // every row except the first and last\r
+ num += degenerates;\r
+ //System.out.println("degenerates: "+degenerates);\r
+\r
+ //System.out.println("center, before edges: "+num);\r
+\r
+ num += (getWidth() / lod) * 2 * 4;\r
+ num++;\r
+\r
+ num += 10;// TODO remove me: extra\r
+ //System.out.println("Index buffer size: "+num);\r
+ return num;\r
+ }\r
\r
@Override\r
public FloatBuffer writeNormalArray(FloatBuffer store, Vector3f scale) {\r
- if (!isLoaded())\r
+ if (!isLoaded()) {\r
throw new NullPointerException();\r
+ }\r
\r
- if (store!=null){\r
- if (store.remaining() < getWidth()*getHeight()*3)\r
+ if (store != null) {\r
+ if (store.remaining() < getWidth() * getHeight() * 3) {\r
throw new BufferUnderflowException();\r
- }else{\r
- store = BufferUtils.createFloatBuffer(getWidth()*getHeight()*3);\r
+ }\r
+ } else {\r
+ store = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);\r
}\r
store.rewind();\r
\r
Vector3f topPoint = new Vector3f();\r
Vector3f bottomPoint = new Vector3f();\r
\r
- // calculate normals for each polygon\r
- for (int r=0; r<getHeight(); r++) {\r
- for (int c=0; c<getWidth(); c++) {\r
+ // calculate normals for each polygon\r
+ for (int r = 0; r < getHeight(); r++) {\r
+ for (int c = 0; c < getWidth(); c++) {\r
\r
- rootPoint.set(c, getValue(c,r), r);\r
+ rootPoint.set(c, getValue(c, r), r);\r
Vector3f normal = new Vector3f();\r
\r
if (r == 0) { // first row\r
if (c == 0) { // first column\r
- rightPoint.set(c+1, getValue(c+1,r), r);\r
- bottomPoint.set(c, getValue(c,r+1), r+1);\r
+ rightPoint.set(c + 1, getValue(c + 1, r), r);\r
+ bottomPoint.set(c, getValue(c, r + 1), r + 1);\r
normal.set(getNormal(bottomPoint, rootPoint, rightPoint));\r
- } else if (c == getWidth()-1) { // last column\r
- leftPoint.set(c-1, getValue(c-1,r), r);\r
- bottomPoint.set(c, getValue(c,r+1), r+1);\r
+ } else if (c == getWidth() - 1) { // last column\r
+ leftPoint.set(c - 1, getValue(c - 1, r), r);\r
+ bottomPoint.set(c, getValue(c, r + 1), r + 1);\r
normal.set(getNormal(leftPoint, rootPoint, bottomPoint));\r
} else { // all middle columns\r
- leftPoint.set(c-1, getValue(c-1,r), r);\r
- rightPoint.set(c+1, getValue(c+1,r), r);\r
- bottomPoint.set(c, getValue(c,r+1), r+1);\r
+ leftPoint.set(c - 1, getValue(c - 1, r), r);\r
+ rightPoint.set(c + 1, getValue(c + 1, r), r);\r
+ bottomPoint.set(c, getValue(c, r + 1), r + 1);\r
Vector3f n1 = getNormal(leftPoint, rootPoint, bottomPoint);\r
Vector3f n2 = getNormal(bottomPoint, rootPoint, rightPoint);\r
normal.set(n1.add(n2).normalizeLocal());\r
}\r
- } else if (r == getHeight()-1) { // last row\r
+ } else if (r == getHeight() - 1) { // last row\r
if (c == 0) { // first column\r
- topPoint.set(c, getValue(c,r-1), r-1);\r
- rightPoint.set(c+1, getValue(c+1, r), r);\r
+ topPoint.set(c, getValue(c, r - 1), r - 1);\r
+ rightPoint.set(c + 1, getValue(c + 1, r), r);\r
normal.set(getNormal(rightPoint, rootPoint, topPoint));\r
- } else if (c == getWidth()-1) { // last column\r
- topPoint.set(c, getValue(c,r-1), r-1);\r
- leftPoint.set(c-1, getValue(c-1,r), r);\r
+ } else if (c == getWidth() - 1) { // last column\r
+ topPoint.set(c, getValue(c, r - 1), r - 1);\r
+ leftPoint.set(c - 1, getValue(c - 1, r), r);\r
normal.set(getNormal(topPoint, rootPoint, leftPoint));\r
} else { // all middle columns\r
- topPoint.set(c, getValue(c,r-1), r-1);\r
- leftPoint.set(c-1, getValue(c-1,r), r);\r
- rightPoint.set(c+1, getValue(c+1,r), r);\r
+ topPoint.set(c, getValue(c, r - 1), r - 1);\r
+ leftPoint.set(c - 1, getValue(c - 1, r), r);\r
+ rightPoint.set(c + 1, getValue(c + 1, r), r);\r
Vector3f n1 = getNormal(topPoint, rootPoint, leftPoint);\r
Vector3f n2 = getNormal(rightPoint, rootPoint, topPoint);\r
normal.set(n1.add(n2).normalizeLocal());\r
}\r
} else { // all middle rows\r
if (c == 0) { // first column\r
- topPoint.set(c, getValue(c,r-1), r-1);\r
- rightPoint.set(c+1, getValue(c+1,r), r);\r
- bottomPoint.set(c, getValue(c,r+1), r+1);\r
+ topPoint.set(c, getValue(c, r - 1), r - 1);\r
+ rightPoint.set(c + 1, getValue(c + 1, r), r);\r
+ bottomPoint.set(c, getValue(c, r + 1), r + 1);\r
Vector3f n1 = getNormal(rightPoint, rootPoint, topPoint);\r
Vector3f n2 = getNormal(bottomPoint, rootPoint, rightPoint);\r
normal.set(n1.add(n2).normalizeLocal());\r
- } else if (c == getWidth()-1) { // last column\r
- topPoint.set(c, getValue(c,r-1), r-1);\r
- leftPoint.set(c-1, getValue(c-1,r), r);\r
- bottomPoint.set(c, getValue(c,r+1), r+1);\r
+ } else if (c == getWidth() - 1) { // last column\r
+ topPoint.set(c, getValue(c, r - 1), r - 1);\r
+ leftPoint.set(c - 1, getValue(c - 1, r), r);\r
+ bottomPoint.set(c, getValue(c, r + 1), r + 1);\r
Vector3f n1 = getNormal(topPoint, rootPoint, leftPoint);\r
Vector3f n2 = getNormal(leftPoint, rootPoint, bottomPoint);\r
normal.set(n1.add(n2).normalizeLocal());\r
} else { // all middle columns\r
- topPoint.set(c, getValue(c,r-1), r-1);\r
- leftPoint.set(c-1, getValue(c-1,r), r);\r
- rightPoint.set(c+1, getValue(c+1,r), r);\r
- bottomPoint.set(c, getValue(c,r+1), r+1);\r
+ topPoint.set(c, getValue(c, r - 1), r - 1);\r
+ leftPoint.set(c - 1, getValue(c - 1, r), r);\r
+ rightPoint.set(c + 1, getValue(c + 1, r), r);\r
+ bottomPoint.set(c, getValue(c, r + 1), r + 1);\r
Vector3f n1 = getNormal(topPoint, rootPoint, leftPoint);\r
Vector3f n2 = getNormal(leftPoint, rootPoint, bottomPoint);\r
Vector3f n3 = getNormal(bottomPoint, rootPoint, rightPoint);\r
}\r
}\r
\r
- BufferUtils.setInBuffer(normal, store, (r*getWidth()+c)); // save the normal\r
+ BufferUtils.setInBuffer(normal, store, (r * getWidth() + c)); // save the normal\r
\r
}\r
}\r
\r
private Vector3f getNormal(Vector3f firstPoint, Vector3f rootPoint, Vector3f secondPoint) {\r
Vector3f normal = new Vector3f();\r
- normal.set(firstPoint).subtractLocal(rootPoint)\r
- .crossLocal(secondPoint.subtract(rootPoint)).normalizeLocal();\r
+ normal.set(firstPoint).subtractLocal(rootPoint).crossLocal(secondPoint.subtract(rootPoint)).normalizeLocal();\r
return normal;\r
}\r
\r
- \r
-\r
- /**\r
- * Keeps a count of the number of indexes, good for debugging\r
- */\r
- public class VerboseIntBuffer {\r
- private IntBuffer delegate;\r
- int count = 0;\r
- public VerboseIntBuffer(IntBuffer d) {\r
- delegate = d;\r
- }\r
- public void put(int value) {\r
- try {\r
- delegate.put(value);\r
- count++;\r
- } catch (BufferOverflowException e) {\r
- //System.out.println("err buffer size: "+delegate.capacity());\r
- }\r
- }\r
- public int getCount() {\r
- return count;\r
- }\r
- }\r
+ /**\r
+ * Keeps a count of the number of indexes, good for debugging\r
+ */\r
+ public class VerboseIntBuffer {\r
+\r
+ private IntBuffer delegate;\r
+ int count = 0;\r
+\r
+ public VerboseIntBuffer(IntBuffer d) {\r
+ delegate = d;\r
+ }\r
+\r
+ public void put(int value) {\r
+ try {\r
+ delegate.put(value);\r
+ count++;\r
+ } catch (BufferOverflowException e) {\r
+ //System.out.println("err buffer size: "+delegate.capacity());\r
+ }\r
+ }\r
+\r
+ public int getCount() {\r
+ return count;\r
+ }\r
+ }\r
\r
/**\r
* Get a representation of the underlying triangle at the given point,\r
* @return\r
*/\r
protected Triangle[] getGridTrianglesAtPoint(float x, float z) {\r
- int gridX = (int)x;\r
- int gridY = (int)z;\r
+ int gridX = (int) x;\r
+ int gridY = (int) z;\r
\r
- int index = findClosestHeightIndex(gridX,gridY);\r
- if (index < 0)\r
+ int index = findClosestHeightIndex(gridX, gridY);\r
+ if (index < 0) {\r
return null;\r
+ }\r
\r
Triangle t = new Triangle(new Vector3f(), new Vector3f(), new Vector3f());\r
Triangle t2 = new Triangle(new Vector3f(), new Vector3f(), new Vector3f());\r
float h4 = hdata.get(index + width + 1); // bottom right\r
\r
\r
- if ((gridX == 0 && gridY == 0) || (gridX == width-1 && gridY == width-1)) {\r
+ if ((gridX == 0 && gridY == 0) || (gridX == width - 1 && gridY == width - 1)) {\r
// top left or bottom right grid point\r
t.get(0).x = (gridX);\r
t.get(0).y = (h1);\r
t2.get(2).x = (gridX + 1);\r
t2.get(2).y = (h2);\r
t2.get(2).z = (gridY);\r
- }\r
- else {\r
+ } else {\r
// all other grid points\r
t.get(0).x = (gridX);\r
t.get(0).y = (h1);\r
t2.get(2).z = (gridY + 1);\r
}\r
\r
- return new Triangle[]{t,t2};\r
+ return new Triangle[]{t, t2};\r
}\r
- \r
+\r
/**\r
* Get the triangle that the point is on.\r
* \r
protected Triangle getTriangleAtPoint(float x, float z) {\r
Triangle[] triangles = getGridTrianglesAtPoint(x, z);\r
if (triangles == null) {\r
- System.out.println("x,z: "+x+","+z);\r
+ System.out.println("x,z: " + x + "," + z);\r
return null;\r
}\r
Vector2f point = new Vector2f(x, z);\r
Vector2f t2 = new Vector2f(triangles[0].get2().x, triangles[0].get2().z);\r
Vector2f t3 = new Vector2f(triangles[0].get3().x, triangles[0].get3().z);\r
\r
- if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point))\r
+ if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) {\r
return triangles[0];\r
+ }\r
\r
t1.set(triangles[1].get1().x, triangles[1].get1().z);\r
t1.set(triangles[1].get2().x, triangles[1].get2().z);\r
t1.set(triangles[1].get3().x, triangles[1].get3().z);\r
\r
- if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point))\r
+ if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) {\r
return triangles[1];\r
+ }\r
\r
return null;\r
}\r
\r
-\r
protected int findClosestHeightIndex(int x, int z) {\r
\r
if (x < 0 || x >= width - 1) {\r
super.read(im);\r
}\r
}\r
-\r