Land.Blocks = 100
Land.BlockSize = 10
AllowSubGL = 1
junk = GetHeight(Cam.PosX, Cam.PosZ)
PRINT "Camera Position = CamPosX:"; Cam.PosX;
"Cam.PosY"; Cam.PosY;
"Cam.PosZ:"; Cam.PosZ
PRINT "Camera Aim = Cam.RotX:"; Cam.RotX;
"Cam.RotY"; Cam.RotY;
" Mode:"; Cam.Mode;
" "
Cam.PosX = Cam.PosX - Cam.Xmod
Cam.PosZ = Cam.PosZ - Cam.Zmod
Cam.PosX = Cam.PosX + Cam.Xmod
Cam.PosZ = Cam.PosZ + Cam.Zmod
IF Cam.RotY
> 359 THEN Cam.RotY
= 0 IF Cam.RotY
< 0 THEN Cam.RotY
= 359
IF Cam.RotY
= 0 THEN Cam.Xmod
= 0: Cam.Zmod
= -1 IF Cam.RotY
> 0 AND Cam.RotY
< 91 THEN Cam.Xmod
= Cam.RotY
/ 90 IF Cam.RotY
> 90 AND Cam.RotY
< 181 THEN Cam.Xmod
= 1 - ((Cam.RotY
- 90) / 90) IF Cam.RotY
> 180 AND Cam.RotY
< 271 THEN Cam.Xmod
= 2 - (Cam.RotY
/ 90) IF Cam.RotY
> 270 AND Cam.RotY
< 360 THEN Cam.Xmod
= -1 + ((Cam.RotY
- 270) / 90)
IF Cam.RotY
> 90 AND Cam.RotY
< 181 THEN Cam.Zmod
= (Cam.RotY
- 90) / 90 IF Cam.RotY
> 180 AND Cam.RotY
< 271 THEN Cam.Zmod
= 1 - ((Cam.RotY
- 180) / 90) IF Cam.RotY
> 270 AND Cam.RotY
< 360 THEN Cam.Zmod
= 2 - ((Cam.RotY
- 90) / 90) IF Cam.RotY
> 0 AND Cam.RotY
< 91 THEN Cam.Zmod
= -1 + (Cam.RotY
/ 90)
'Cam.RotX = _MOUSEY / 10
IF Cam.PosX
> -1 THEN Cam.PosX
= -1 IF Cam.PosZ
> -1 THEN Cam.PosZ
= -1 IF Cam.PosX
< -1 * (Land.Blocks
* Land.BlockSize
) THEN Cam.PosX
= -1 * (Land.Blocks
* Land.BlockSize
) IF Cam.PosZ
< -1 * (Land.Blocks
* Land.BlockSize
) THEN Cam.PosZ
= -1 * (Land.Blocks
* Land.BlockSize
)
IF (-1 * GetHeight!
(Cam.PosX
, Cam.PosZ
)) < Land.WaterHeight
THEN Cam.PosY = -1 * (GetHeight!(Cam.PosX, Cam.PosZ)) - 2.5
Cam.PosY = (-1 * Land.WaterHeight) - 2.5
IF Cam.PosY
> -1 * (GetHeight!
(Cam.PosX
, Cam.PosZ
)) - 2.5 THEN Cam.PosY
= -1 * (GetHeight!
(Cam.PosX
, Cam.PosZ
)) - 2.5
TerrainType = 1 'INT(RND * 3) + 1
'Wetlands
Land.InitHeight = 15
Land.MaxHeightChange = 3
Land.MainRnd = 100
Land.EnableWater = 1
Land.MaxHeight = 50
Land.MinHeight = -15
Land.WaterHeight = 0
Land.MaxWaterHeight = 1
Land.WaterSpeed = 0.001
'Mountains
Land.InitHeight = -50
Land.MaxHeightChange = 15
Land.MainRnd = 1000
Land.EnableWater = 0
Land.MaxHeight = -50
Land.MinHeight = 15
'Graslands
Land.InitHeight = -15
Land.MaxHeightChange = 3
Land.MainRnd = 100
Land.EnableWater = 0
Land.MaxHeight = -50
Land.MinHeight = 15
Cam.PosX = -1 '-1 * ((Land.Blocks * Land.BlockSize) / 2)
Cam.PosZ = -1 '-1 * ((Land.Blocks * Land.BlockSize) / 2)
Cam.PosY = (-1 * GetHeight!(Cam.PosX, Cam.PosZ)) - 2.5
Cam.RotY = 150
Cam.Xmod = 0
Cam.Zmod = -1
Cam.Mode = 1
Heightmap(1, 1) = 1.1 * Land.InitHeight
FOR x
= 2 TO Land.Blocks
+ 1 HeightChange
= RND * Land.MaxHeightChange
HeightChange
= -1 * (RND * Land.MaxHeightChange
) Heightmap(x, 1) = Heightmap(x - 1, 1) + HeightChange
IF Heightmap
(x
, 1) > Land.MaxHeight
THEN Heightmap
(x
, 1) = Land.MaxHeight
IF Heightmap
(x
, 1) < Land.MinHeight
THEN Heightmap
(x
, 1) = Land.MinHeight
FOR z
= 2 TO Land.Blocks
+ 1 HeightChange
= RND * Land.MaxHeightChange
HeightChange
= -1 * (RND * Land.MaxHeightChange
) Heightmap(1, z) = Heightmap(1, z - 1) + HeightChange
IF Heightmap
(1, z
) > Land.MaxHeight
THEN Heightmap
(1, z
) = Land.MaxHeight
IF Heightmap
(1, z
) < Land.MinHeight
THEN Heightmap
(1, z
) = Land.MinHeight
FOR x
= 2 TO Land.Blocks
+ 1 FOR z
= 2 TO Land.Blocks
+ 1 HeightChange
= RND * Land.MaxHeightChange
HeightChange
= -1 * (RND * Land.MaxHeightChange
) Heightmap(x, z) = ((Heightmap(x, z - 1) + Heightmap(x - 1, z)) / 2) + HeightChange
IF Heightmap
(x
, z
) > Land.MaxHeight
THEN Heightmap
(x
, z
) = Land.MaxHeight
IF Heightmap
(x
, z
) < Land.MinHeight
THEN Heightmap
(x
, z
) = Land.MinHeight
Land.WaterHeight = Land.WaterHeight + Land.WaterSpeed
IF Land.WaterHeight
>= Land.MaxWaterHeight
OR Land.WaterHeight
<= Land.MinWaterHeight
THEN Land.WaterSpeed
= Land.WaterSpeed
* -1
'_glMatrixMode _GL_PROJECTION
'_glLoadIdentity
'_glPushMatrix
'_glEnable _GL_TEXTURE_2D
'_glEnable _GL_BLEND
'_glBlendFunc _GL_SRC_ALPHA, _GL_ONE_MINUS_SRC_ALPHA
'_glAlphaFunc _GL_GREATER, 0.5
'_glEnable _GL_ALPHA_TEST
'_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
'_glTexParameteri _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_LINEAR
'load identity used to be here
FOR z
= 0 TO Land.Blocks
- 1 FOR x
= 0 TO Land.Blocks
- 1 _glColor3f 0, 0, 1:
_glVertex3f Land.BlockSize
* (x
+ 1), Heightmap
(x
+ 2, z
+ 2), Land.BlockSize
* (z
+ 1)
_glColor3f 0, 0, 1:
_glVertex3f Land.BlockSize
* Land.Blocks
, Land.WaterHeight
, Land.BlockSize
* Land.Blocks
MatrixX
= ABS(INT(Tx
/ Land.BlockSize
)) MatrixZ
= ABS(INT(Tz
/ Land.BlockSize
))
SquareX = 1 - ((Tx / Land.BlockSize) + MatrixX)
SquareZ = 1 - ((Tz / Land.BlockSize) + MatrixZ)
Triangle = 1
IF SquareZ
< 1 - SquareX
THEN Triangle
= 2
x1 = -1 * ((MatrixX - 1) * Land.BlockSize)
x2 = -1 * (MatrixX * Land.BlockSize)
x3 = -1 * ((MatrixX - 1) * Land.BlockSize)
z1 = -1 * ((MatrixZ - 1) * Land.BlockSize)
z2 = -1 * ((MatrixZ - 1) * Land.BlockSize)
z3 = -1 * (MatrixZ * Land.BlockSize)
y1 = Heightmap(MatrixX, MatrixZ)
y2 = Heightmap(MatrixX + 1, MatrixZ)
y3 = Heightmap(MatrixX, MatrixZ + 1)
x1 = -1 * (MatrixX * Land.BlockSize)
x2 = -1 * (MatrixX * Land.BlockSize)
x3 = -1 * ((MatrixX - 1) * Land.BlockSize)
z1 = -1 * (MatrixZ * Land.BlockSize)
z2 = -1 * ((MatrixZ - 1) * Land.BlockSize)
z3 = -1 * (MatrixZ * Land.BlockSize)
y1 = Heightmap(MatrixX + 1, MatrixZ + 1)
y2 = Heightmap(MatrixX + 1, MatrixZ)
y3 = Heightmap(MatrixX, MatrixZ + 1)
A = y1 * (z2 - z3) + y2 * (z3 - z1) + y3 * (z1 - z2)
B = z1 * (x2 - x3) + z2 * (x3 - x1) + z3 * (x1 - x2)
C = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)
D = 0 - (x1 * (y2 * z3 - y3 * z2) + x2 * (y3 * z1 - y1 * z3) + x3 * (y1 * z2 - y2 * z1))
GetHeight = 0 - (D + A * Tx + C * Tz) / B