#Constant cShader = 0
#Constant cShaderLoad = 1
#Constant cTexture = 2
Global terrainMode as Byte
function InitWorld
If terrainMode = cShader
Global terFX
terFX = Find Free Effect()
load Effect "terrain\LGTerrainMip.fx", terFX, 1
//load Effect "terrain\LGTerrain.fx", terFX, 1
//load Effect "terrain\LGLavaTerrain.fx", terFX, 1
Endif
If terrainMode = cShaderLoad
Global terFX
terFX = Find Free Effect()
load Effect "terrain\LGTerrainMip.fx", terFX, 0
//load Effect "terrain\LGTerrain.fx", terFX, 0
//load Effect "terrain\LGLavaTerrain.fx", terFX, 0
Endif
imgTer = Find Free Image()
Load Image "terrain\HM0000.bmp", imgTer
imgEnv = Find Free Image()
Load Image "terrain\EnvMap0000.png", imgEnv
if TerrainMode = cTexture
imgDetail = Find Free Image()
Load Image "terrain\detail.jpg", imgDetail
imgTexture = Find Free Image()
Load Image "terrain\texture0000.png", imgTexture
Endif
Global terrain as integer
BT SetATMode 1
terrain = BT MakeTerrain()
BT SetTerrainHeightMap terrain, imgTer
if TerrainMode = cTexture
BT SetTerrainTexture terrain, imgTexture
BT SetTerrainDetail terrain, imgDetail
Endif
BT SetTerrainEnvironment terrain, imgEnv
BT SetTerrainScale terrain, 5
BT SetTerrainYScale terrain, 1.5
BT SetTerrainSplit terrain, 32
BT SetTerrainLOD terrain, 3
BT SetTerrainLODDistance terrain, 1, 150.0
BT SetTerrainLODDistance terrain, 2, 100.0
BT SetTerrainSmoothing terrain, 1
BT SetTerrainQuadRotation terrain, 1
For i = 1 to Array Count(environments())
e = BT AddTerrainEnvironment(terrain, RGB(environments(i).ColorR, environments(i).ColorG, environments(i).ColorB))
Next
BT BuildTerrain terrain, 1
BT SetBuildStep 0
repeat
progress = BT ContinueBuild()
until progress=-1
if TerrainMode = cShader
set Object effect terrain, terFX
Endif
if TerrainMode = cShaderLoad
Global imgWM0 as Integer
imgWM0 = Find Free Image()
Load Image "terrain\WM0_0000.png", imgWM0
Global imgWM1 as Integer
imgWM1 = Find Free Image()
Load Image "terrain\WM1_0000.png", imgWM1
Global imgWM2 as Integer
imgWM2 = Find Free Image()
Load Image "terrain\WM2_0000.png", imgWM2
Global imgWM3 as Integer
imgWM3 = Find Free Image()
Load Image "terrain\WM3_0000.png", imgWM3
imgAtlas0 = Find Free Image()
Load Image "terrain\Atlas0.png", imgAtlas0
imgAtlas1 = Find Free Image()
Load Image "terrain\Atlas1.png", imgAtlas1
Texture Object terrain, 0, imgWM0
Texture Object terrain, 1, imgWM1
Texture Object terrain, 2, imgWM2
Texture Object terrain, 3, imgWM3
Texture Object terrain, 4, imgAtlas0
Texture Object terrain, 5, imgAtlas1
set Object effect terrain, terFX
Endif
Global objScale as Float
objScale = BT GetTerrainSize(terrain) / Image Width(imgTer)
Global WorldSize
WorldSize = BT GetTerrainSize(terrain)
Global map
map = FindFreeObject()
Make Object Plain map, 100, 100
mapImg = Find Free Image()
Load Image "terrain/map.png", mapImg
Texture Object map, mapImg
Position Object map, 0, 0, 100
Lock Object On map
Global mapMarker
mapMarker = FindFreeObject()
Make Object Sphere mapMarker, 1
mapImg = Find Free Image()
Position Object mapMarker, -50, -50, 99
Lock Object On mapMarker
Hide Object map
Hide Object mapMarker
endFunction
Function UpdateWorld
BT SetCurrentCamera 0
BT UpdateTerrainLOD terrain
BT UpdateTerrainCull terrain
BT RenderTerrain terrain
EndFunction
Function SetShaders
if terrainMode = cTexture Then ExitFunction
Set Effect Constant Float terFx, "FogMin", terFogMin
Set Effect Constant Float terFx, "FogMax", terFogMax
Set Effect Constant Float terFx, "FogStart", terFogStart
Set Effect Constant Float terFx, "FogEnd", terFogEnd
Set Effect Constant Float terFx, "FogDensity", terFogDensity
tmp = New Vector4()
cR as Float
cR = RGBR(terFogColor)
cR = cR / 255
cG as Float
cG = RGBR(terFogColor)
cG = cG / 255
cB as Float
cB = RGBR(terFogColor)
cB =cB / 255
Set Vector4 tmp, cR, cG, cB, 0
Set Effect Constant Vector terFx, "FogColor", tmp
Set Effect Constant Float terFx, "DetailScale", terDetailScale
Set Effect Constant Float terFx, "TextureScale", terTextureScale
Set Effect Constant Float terFx, "RoadScale", terRoadScale
Set Effect Constant Float terFx, "Brightness", terBrightness
Set Effect Constant Float terFx, "DetailFac", terDetailFac
Delete Vector4 tmp
Endfunction
Function ChangeTexture(xPos as float, zPos as Float, texture as Integer)
if terrainMode <> cShaderLoad Then ExitFunction
img as Integer
color as Byte
xPos = xPos * (imgSize / worldSize)
zPos = zPos * (imgSize / worldSize)
zPos = imgSize - zPos
Select texture
Case 0
img = imgWM0
color = 0
EndCase
Case 1
img = imgWM0
color = 1
EndCase
Case 2
img = imgWM0
color = 2
EndCase
Case 3
img = imgWM0
color = 3
EndCase
Case 4
img = imgWM1
color = 0
EndCase
Case 5
img = imgWM1
color = 1
EndCase
Case 6
img = imgWM1
color = 2
EndCase
Case 7
img = imgWM1
color = 3
EndCase
Case 8
img = imgWM2
color = 0
EndCase
Case 9
img = imgWM2
color = 1
EndCase
Case 10
img = imgWM2
color = 2
EndCase
Case 11
img = imgWM2
color = 3
EndCase
Case 12
img = imgWM3
color = 0
EndCase
Case 13
img = imgWM3
color = 1
EndCase
Case 14
img = imgWM3
color = 2
EndCase
Case 15
img = imgWM3
color = 3
EndCase
EndSelect
ik Dot imgWM0, xPos, zPos, RGB (0, 0, 0, 0)
ik Dot imgWM1, xPos, zPos, RGB(0, 0, 0, 0)
ik Dot imgWM2, xPos, zPos, RGB (0, 0, 0, 0)
ik Dot imgWM3, xPos, zPos, RGB (0, 0, 0, 0)
Select color
Case 0
ik Dot img, xPos, zPos, RGB(0, 255, 0, 0)
EndCase
Case 1
ik Dot img, xPos, zPos, RGB(0, 0, 255, 0)
EndCase
Case 2
ik Dot img, xPos, zPos, RGB(0, 0, 0, 255)
EndCase
Case 3
Ik Dot img, xPos, zPos, RGB(255, 0, 0, 0)
EndCase
EndSelect
Endfunction
Function ChangeEnvironment(xPos as float, zPos as Float, envColor as dWord)
xPos = xPos * (imgSize / worldSize)
zPos = zPos * (imgSize / worldSize)
zPos = imgSize - zPos
ik Dot imgEnv, xPos, zPos, envColor
Endfunction
i have run the program but i am having problem a BT Error height-map size invalid
Function:BT Build terrain can someone tell me why i am having this problem
BM