From a5511a19dc184c8d1e0e166e0ef483187f6a4226 Mon Sep 17 00:00:00 2001 From: "bre..ns" Date: Fri, 8 Jul 2011 00:07:08 +0000 Subject: [PATCH] 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 --- .../heightmap/ImageBasedHeightMap.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java b/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java index b9633fc3e..37219b251 100644 --- a/engine/src/terrain/com/jme3/terrain/heightmap/ImageBasedHeightMap.java +++ b/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); } } }