Browse Source

pulled ImageBasedHeightmap height color calculation out so it can be customized by subClasses

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7841 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
bre..ns 14 years ago
parent
commit
a5511a19dc
1 changed files with 11 additions and 12 deletions
  1. 11 12
      engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java

+ 11 - 12
engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java

@@ -165,6 +165,13 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
         return load(false, false);
     }
 
+    /**
+     * Get the grayscale value, or override in your own sub-classes
+     */
+    protected float calculateHeight(float red, float green, float blue) {
+        return (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen);
+    }
+    
     public boolean load(boolean flipX, boolean flipY) {
 
         // FUTURE: Rescale image if not square?
@@ -220,9 +227,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (data[baseIndex + 2]));
-                        float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen);
-                        heightData[index++] = grayscale;
-                        //heightData[index++] = calculateHeight(red,green,blue);
+                        heightData[index++] = calculateHeight(red,green,blue);
                     }
                 } else {
                     for (int w = 0; w < imageWidth; ++w) {
@@ -234,9 +239,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (data[baseIndex + 2]));
-                        float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen);
-                        heightData[index++] = grayscale;
-                        //heightData[index++] = calculateHeight(red,green,blue);
+                        heightData[index++] = calculateHeight(red,green,blue);
 
                     }
                 }
@@ -253,9 +256,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (data[baseIndex + 2]));
-                        float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen);
-                        heightData[index++] = grayscale;
-                        //heightData[index++] = calculateHeight(red,green,blue);
+                        heightData[index++] = calculateHeight(red,green,blue);
                     }
                 } else {
                     for (int w = 0; w < imageWidth; ++w) {
@@ -267,9 +268,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (data[baseIndex + 2]));
-                        float grayscale = (float) ((0.299 * red + 0.587 * green + 0.114 * blue) * dampen);
-                        heightData[index++] = grayscale;
-                        //heightData[index++] = calculateHeight(red,green,blue);
+                        heightData[index++] = calculateHeight(red,green,blue);
                     }
                 }
             }