Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

MapMatrix #1920

Closed
arkasia opened this Issue May 14, 2012 · 1 comment

Comments

2 participants

arkasia commented May 14, 2012

I think, a MapMatrix object would be very useful. We could handle terrains, or fluid sucface easily with that.

An example:

// The width and depth are the values used for the size of the terrain.
// The xTiles, and zTiles are the number of divisions the matrix will have.
map = new THREE.MapMatrix( width, depth, xTiles, zTiles );

// map.matrix is a 2D array, which contains the heights. Every value is 0 by default
var height_at = map.matrix[xTile][zTile];

// If you want to modify the height, update it's value, and then update the matrix.
map.matrix[xTile][zTile] = newheight;
map.matrix[xTile2][zTile2] = newheight2;
//... etc
map.update();

The map.getHeight( x, z ) command will return with the map height at the x,z point. 0,0 is at the left-top corner.
The map.randomize( maxheight, [minheight] ) will randomize the matrix

'Demo' with sceenshots:

// By default this 3x3 matrix looks like this:
// http://imageshack.us/photo/my-images/833/matrix01.png/
map = new THREE.MapMatrix( 200, 200, 3, 3);

// put the map in the middle of the scene
map.position.x = -100;
map.position.z = -100;

// Modify the matrix a bit
for(var i=2;i<4;i++) {
  for(var j=0;j<4;j++) {
    map.matrix[i][j] = 15;
  }
}

// After the update the map will look like this:
// http://imageshack.us/photo/my-images/6/matrix02.png/
map.update();

alert(map.getHeight(100,100)); // the result is 7.5

If the map isn't colored, or don't have any texture, then you only see the wireframe (if wireframe isn't disabled).
You can set texture/color per tile, or you can draw on this map, like on the 2dcanvas.

So what do you think about it?

Owner

mrdoob commented May 14, 2012

I think this is one of these things that should go in the application layer, not in the lib itself.
Also, I prefer doing terrains using imagedata.data which, even if it's a unidirectional array, is much easy to visualise ;)

@mrdoob mrdoob closed this May 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment