interpolated TerrainX,TerrainY,TerrainZ??? what does this mean?

Blitz3D Forums/Blitz3D Programming/interpolated TerrainX,TerrainY,TerrainZ??? what does this mean?

gpete(Posted 2017) [#1]
what does interpolated mean regarding B3D terrains? Does TerrainY# interpolated equal 1 to 256 or does it mean the answer is Zero to One divided into 256 decimal values( TerrainHeight#)? So B3D terrains are created from the Red value of an image- A color image has a RGB value of 0,0,0 for black and 255,255,255 for white.
Are the values for Green and Blue ignored?

One divided into 256 is 0.0039 approx. per each level of color.
Any explanation would be helpful... thanks!


Stevie G(Posted 2017) [#2]
Yes, Green and Blue components of the RGB color are ignored.

My understanding is that the Red component is converted to a height from 0..1 like you say. So Red0 = 0, Red128 is ~0.5 and Red255 = 1.

If you then scale the terrain entity on the Y axis by 100, Red255 becomes 100.

Something along those lines.

Stevie


Floyd(Posted 2017) [#3]
I think this is really about interpolated y for terrain height. That's probably the only terrain value that you would normally need to calculate.

A terrain is defined for a range of x and z values with a height y at each (x,z) location. A 1024 by 1024 terrain, for example, has about a million heights specified. This is far too many for the Direct3D mesh that Blitz3D will use. In fact Blitz3D uses a level of detail algorithm to approximate the full terrain using a much smaller number of vertices. If you use the command "Wireframe True" you can see this in action.

TerrainY() for a given x,z is the height at that point, interpolated from the known heights of nearby vertices.


gpete(Posted 2017) [#4]
thanks Stevie and Floyd- I am slogging thru experiments...


RemiD(Posted 2017) [#5]
About Blitz3d terrain, note that on a heightmap you have only 128x128 pixels, and therefore you can only get 128x128 heights.
However a terrain (with a scale of 1,255,1) has 128x128 "cells" (4vertices/2triangles), and so you will have vertices/heights from 0 to 128, and so the vertices at 0x and the vertices at 128x have the same height, and the vertices at 0z and the vertices at 128z have the same height.
Check it !


Floyd(Posted 2017) [#6]
Terrains must be square, same width and height. The number of cells in each direction must be a power of 2, such as 32, 64, 128, 256 etc. A heightmap ( image ) should follow the same rules.

Here is a hastily coded example with a 512 x 512 terrain. That would be over a quarter of a million vertices. So Blitz3D uses a level of detail algorithm to dynamically reduce this. It uses more triangles near the camera, fewer in the distance. I think the "power of 2" restriction is due to the ROAM algorithm which Blitz3D uses.

As I mentioned earlier you can watch this change by turning Wireframe mode on.

SeedRnd MilliSecs()
mapfilename$ = "heightmap" + Rand( 1000000, 9999999 )  ; quick and dirty attempt at new file name for .bmp
; Should not overwrite any existing bitmap file, but really ought to check that.

Graphics3D 800, 600, 0, 2  ; fill in something reasonable for your monitor
SetBuffer BackBuffer()

For i = 0 To 511     ; build height map for "wavy" terrain.
	For j = 0 To 511
		x# = 0.5 * 511 - i
		y# = 0.5 * 511 - j
		dist# = Sqr( x*x + y*y )
		height# = Sin( 4 * dist )   ; from -1 to +1
		height = ( 1 + height ) / 2   ; now 0 to 1
		h = 255 * height     ; 0 to 255
		Color h, h, h
		Plot i, j
	Next
Next

img = CreateImage( 512, 512 )
GrabImage img, 0, 0
Cls

SaveImage img, mapfilename
terrain = LoadTerrain( mapfilename )   ; heights are 0 to 1
ScaleEntity terrain, 4, 100, 4

DeleteFile mapfilename

cam = CreateCamera()
CameraRange cam, 10, 5000
PositionEntity cam, 1024, 800, 0
TurnEntity cam, 45, 0, 0

WireFrame True
For n = 1 To 2500
	If KeyDown(1) Then Exit  ; Escape quits if this gets boring.
	RenderWorld
	Flip
	MoveEntity cam, 0, 0.125, 0.5
Next