소스 검색

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 년 전
부모
커밋
a5511a19dc
1개의 변경된 파일11개의 추가작업 그리고 12개의 파일을 삭제
  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);
         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) {
     public boolean load(boolean flipX, boolean flipY) {
 
 
         // FUTURE: Rescale image if not square?
         // FUTURE: Rescale image if not square?
@@ -220,9 +227,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (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 {
                 } else {
                     for (int w = 0; w < imageWidth; ++w) {
                     for (int w = 0; w < imageWidth; ++w) {
@@ -234,9 +239,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (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]));
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (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 {
                 } else {
                     for (int w = 0; w < imageWidth; ++w) {
                     for (int w = 0; w < imageWidth; ++w) {
@@ -267,9 +268,7 @@ public class ImageBasedHeightMap extends AbstractHeightMap {
                                 : (256 + (data[baseIndex + 1]));
                                 : (256 + (data[baseIndex + 1]));
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                         float red = data[baseIndex + 2] >= 0 ? data[baseIndex + 2]
                                 : (256 + (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);
                     }
                     }
                 }
                 }
             }
             }