From 096406bce5116cdbe378918817fe3255228ba264 Mon Sep 17 00:00:00 2001 From: savagex Date: Thu, 22 May 2008 16:24:45 +0000 Subject: [PATCH] grow vis-blockers in both x and y seperately. This allows for non-square visblockers, decreasing the total amount of blocks considerably. And yeah, it was a stupid thing to not do it that way right from the start. I know that, mkay? Fine? Fine. git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3644 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- tools/ImgToMap/src/imgtomap/MapWriter.java | 57 ++++++++++++++++------ 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/tools/ImgToMap/src/imgtomap/MapWriter.java b/tools/ImgToMap/src/imgtomap/MapWriter.java index e70908502..fada23b63 100644 --- a/tools/ImgToMap/src/imgtomap/MapWriter.java +++ b/tools/ImgToMap/src/imgtomap/MapWriter.java @@ -164,15 +164,13 @@ public class MapWriter { z = z * 16; if (z > 0) { - int dim = b.dim; - double x = b.x * units; - double y = (b.y + dim) * units; + double y = (b.y + b.ydim) * units; x = x > xmax ? xmax : x; y = y > ymax ? ymax : y; Vector3D p1 = new Vector3D(x, -y, -32.0); - x = (b.x + dim) * units; + x = (b.x + b.xdim) * units; y = b.y * units; x = x > xmax ? xmax : x; y = y > ymax ? ymax : y; @@ -291,11 +289,15 @@ public class MapWriter { } private double[] getMinMaxForRegion(double[][] field, int x, int y, int dim) { + return getMinMaxForRegion(field, x, y, dim, dim); + } + + private double[] getMinMaxForRegion(double[][] field, int x, int y, int xdim, int ydim) { double max = -100d; double min = 100d; - for (int i = x; i < x + dim; ++i) { - for (int j = y; j < y + dim; ++j) { + for (int i = x; i < x + xdim; ++i) { + for (int j = y; j < y + ydim; ++j) { if (i >= 0 && j >= 0 && i < field.length && j < field[0].length) { min = field[i][j] < min ? field[i][j] : min; max = field[i][j] > max ? field[i][j] : max; @@ -323,22 +325,45 @@ public class MapWriter { b.minheight = b.origheight = columns[x][y]; // grow till the delta hits - int dim; + int xdim = 1; + int ydim = 1; + boolean xgrow = true; + boolean ygrow = true; double min = b.minheight; - for (dim = 1; dim < columns.length; ++dim) { - double[] minmax = getMinMaxForRegion(columns, x, y, dim); + for (; xdim < columns.length && ydim < columns[0].length;) { + double[] minmax = getMinMaxForRegion(columns, x, y, xdim + 1, ydim); if (Math.abs(b.origheight - minmax[0]) > delta || Math.abs(b.origheight - minmax[1]) > delta) { - break; + xgrow = false; } + + minmax = getMinMaxForRegion(columns, x, y, xdim, ydim + 1); + if (Math.abs(b.origheight - minmax[0]) > delta || Math.abs(b.origheight - minmax[1]) > delta) { + ygrow = false; + } + min = minmax[0]; + if (xgrow) { + ++xdim; + } + if (ygrow) { + ++ydim; + } + + minmax = getMinMaxForRegion(columns, x, y, xdim, ydim); + min = minmax[0]; + + if (!(xgrow || ygrow)) { + break; + } } - b.dim = dim - 1; + b.xdim = xdim; + b.ydim = ydim; b.minheight = min; - for (int i = x; i < x + b.dim; ++i) { - for (int j = y; j < y + b.dim; ++j) { + for (int i = x; i < x + b.xdim; ++i) { + for (int j = y; j < y + b.ydim; ++j) { if (i >= 0 && j >= 0 && i < blockers.length && j < blockers[0].length) { blockers[i][j] = b; columns[i][j] = -1337.0; @@ -354,7 +379,7 @@ public class MapWriter { private class Vector3D { - public double x, y, z; + public double x, y, z; public Vector3D() { this(0.0, 0.0, 0.0); @@ -411,7 +436,7 @@ public class MapWriter { private class VisBlocker { - public int x, y, dim; - public double origheight, minheight; + public int x, y, xdim, ydim; + public double origheight, minheight; } } \ No newline at end of file -- 2.39.2