ModifyTerrain problem

Blitz3D Forums/Blitz3D Programming/ModifyTerrain problem

Mr Snidesmin(Posted 2006) [#1]
I'm trying to make an editor that has a lower/raise/level terrain tool using modifyterrain.

The editor will then save the terrain back to a BMP, therefore it makes sense to only have 256 height levels (Anything in-between would be rounded when saving)

So to do this I was using a constant to represent one unit of height:

Const HeightUnit = 1.0/256.0


The problem I'm getting is that when I SUBTRACT this unit from a point on the terrain like this:

ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)-HeightUnit , True


it works fine, however ADDING:

ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)+HeightUnit , True


Seems to have no effect unless I use a value ever so slightly more than HeightUnit which starts to mess up my terrain 'levels'

Ive actually tried subtracting with values much smaller than HeightUnit and that seems to work fine - why is there this difference???

Any explanations?


skidracer(Posted 2006) [#2]
It may not help but don't you mean Const HeightUnit# = 1.0/256.0?


Mr Snidesmin(Posted 2006) [#3]
Yeah I did mean that. . . sorry. I have it correctly as a float in the code. . .


Mr Snidesmin(Posted 2006) [#4]
I've been noticing really weird effects. . .

Doing the operation:

ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)+HeightUnit*2, True


works okay, as does:

ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)-HeightUnit, True



Therefore to get the effect of:

ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)+HeightUnit, True


I could do:
ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)+HeightUnit*2, True
ModifyTerrain terr, x, z, TerrainHeight(terr, x, z)-HeightUnit, True


However this does not work!!!

This has to be a floating number precision problem in combination with a blitz terrain bug. . . Either that or it's some kind of weird quantum entanglement. . . :O)


skidracer(Posted 2006) [#5]
Given the terrain engine seems to map the values 0..255 -> 0..1.0 I'm wondering if in fact the scale factor may mean 1.0/255 is a better fit?


Mr Snidesmin(Posted 2006) [#6]
Ah okay. . .

I noticed that no matter how small the number you subtract, a minimum value of 1/256 is subtracted. Same for adding - it's just a case of how blitz rounds the number that decided why the ADD fraction has to be greater than 1/256 and the SUBTRACT fraction can be less.

I thought you could modify a terrain's height to any value from 0-1.

Now it seems it will only accept the 256 different values. . .
I wonder if this is only true if you load the terrain from a bitmap - could a 'created' new terrain allow a more continuous set of values. . . hmmm.


Mr Snidesmin(Posted 2006) [#7]
Hmm interesting idea skidracer. . . let me try that out.


- YES this definitely works (which makes sense because 1/255 is ever so slightly more than 1/256)

I guess you are right on this one. . . either way the code works fine now - thanks :O)