Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

The 20 Line Challenge / [DBP] Matrix From Heightmap (cheap)

Author
Message
Derek Darkly
6
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 27th May 2013 20:53 Edited at: 21st Nov 2014 15:57
-=-=-=-=-=-=-=-=-=-=-=-=
New version Sept 5, 2013
-=-=-=-=-=-=-=-=-=-=-=-=

Replaced the POINT 'pixel finder' with Memblock version

Be sure to play with the 'Hscale#' and 'Scale' numbers.
'Hscale#' is the overall Height scaling, 'Scale' is the X/Z size.

This code works best with a small heightmap and a very large terrain/texture map, as the matrix segments are numbered according to the heightmap's pixels, and the texture is not tiled, but rather treated as one painted terrain spread across the whole matrix.

I will probably be horrible at fixing any bugs.







[EDITED 10/10/13: camera control/height placement]

Gameboy Xx_xX
5
Years of Service
User Offline
Joined: 16th Mar 2013
Location: My ***
Posted: 30th May 2013 18:21
matrix dimensions illegal at line 6
RonsWare
7
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 25th Jun 2013 22:44
I have the same Error.
I have used a gray colored heightmap with 600x600 dimensions.
Texture map has the same dimensions.

I try to fix this, i am interrested in this way to create a matrix

Cheers Ron.

Programming is learning
Derek Darkly
6
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 5th Sep 2013 07:16 Edited at: 19th Sep 2013 04:22
I've added a couple of IF statements to cover the heights of the outermost vertices.

I had to do this because the number of unique vertices outnumber the actual number of tiles; a 9x9 matrix, for example, will actually have 10x10 points to raise.

(I need to properly update this to dimension the matrix as 1 less "squared" so as to use the whole heightmap evenly across the vertices.)

D.D.
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Sep 2013 00:40
Your code makes an insanely large amount of vertices for the matrix. I used an image 1000x1000 for the height map, which with your code generates a matrix of 2000 by 2000 tiles. You should make the size of the matrix independent from the heightmap image. This can be accomplished by using proportions.


In regards to the following code:
Quote: "
r#=memblock byte(Land,MemCount+2)
g#=memblock byte(Land,MemCount+1)
b#=memblock byte(Land,MemCount)
Height# = (r#*Hscale#+(g#*(Hscale#*2)) + (b#*Hscale#*4))*.01
"


Typically a heightmap is greyscale, therefore all color components would technically be the same value. Also, there's no need to make the RGB variables floats.


I changed the code to give more control over the matrix size


Derek Darkly
6
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 6th Sep 2013 02:26 Edited at: 6th Sep 2013 02:27
Nice variation, Phaelax!

I'll have to study your code again, but it seems like your method leaves out the furthest edges of the matrix's height..?

Are you skipping certain pixels in your heightmap to assign them to a 100x100 grid? Would resizing your heightmap to 100x100 give nearly the same result?

You're right about the floats, but I did program the rest on purpose for separate RGB values - just to try to allow for more variation in the vertical stepping of the matrix. Of course, as you say, most people don't use color heightmaps anyway, but the option is there.

D.D.
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Sep 2013 08:02
Doesn't matter what size the heightmap is. A larger image would give room for greater resolution in the terrain, but you'd need a lot more points in the matrix to really make use of it all. But you don't need a vertex for each pixel in the map.

Quote: "Are you skipping certain pixels in your heightmap to assign them to a 100x100 grid?"

Ok, so let's say the matrix is 100x100, and the height map is 150x150. Vertices in the matrix range from 0 to 100 (1 more than the number of tiles you create it with), so what we do is translate/scale them to fit the image. 0=1, 100=150.

x = vertex
pixel = (x*150) / 100


When I tested the code, it didn't look like it was leaving out the outer edge of the matrix, but it could be. Looking at the code I would guess that it would.

Changing this:



To this should correct that.


Derek Darkly
6
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 19th Sep 2013 04:19 Edited at: 19th Sep 2013 04:28
Quote: "Ok, so let's say the matrix is 100x100, and the height map is 150x150. Vertices in the matrix range from 0 to 100 (1 more than the number of tiles you create it with), so what we do is translate/scale them to fit the image. 0=1, 100=150.

x = vertex
pixel = (x*150) / 100"


I think I understand your method...
Mathematically, as you go along pulling data from the memblock, your division
Quote: "px = (x * imgWidth) / tileCountX"
in effect resizes the heightmap by skipping pixel data sequentially.

I still think that dimensioning the matrix tiles according to the heightmap's size can be useful. Here are a couple of screenshots of a matrix with only 10x10 heightmaps:





The texture I used was about 400x400.
Not horrible for a 100-tile matrix!

I know matrices are kind of old school, but you could easily have a world consisting of, say, 400 10x10 adjoined matrices with decent texturing, normal controls, etc. and still get an awesome framerate.

D.D.

Login to post a reply

Server time is: 2018-04-26 02:50:13
Your offset time is: 2018-04-26 02:50:13