SyntaxBomb - Indie Coders

Languages & Coding => Blitz Code Archives => 3D Graphics - Maths => Topic started by: BlitzBot on June 29, 2017, 00:28:38

Title: [bb] Create Tiled Terrain by Leon Drake [ 1+ years ago ]
Post by: BlitzBot on June 29, 2017, 00:28:38
Title : Create Tiled Terrain
Author : Leon Drake
Posted : 1+ years ago

Description : This is a code i wrote for my Program to create some water and Terrains. With the ability to use mesh commands like grabbing surfaces and vertexes. I also set it to tile the textures in each grid of the surface. You could also alter this code to create a surface for each tile so you can have multiple textures on this one plane.

Code :
Code (blitzbasic) Select
; just some types i use for creating the plane.

Type bsurface
Field geohandle,surfacen$,shandle,surf
End Type


Type btri
Field v1handle,v2handle,v3handle,shandle,thandle,tri
End Type


Function CreatePlane()
; lets set how wide and thick each tile will be
;a width of 30 can make a pretty decent sized plane
local rectbrush_widthw,rectbrush_depthd,rectbrush_ripple,rectbrush_heighth
rectbrush_widthw = 30
rectbrush_depthd = 30
; i set the height to 0 as it will be a flat plane
rectbrush_heighth = 0
; i was using this for water but variable here stands for
;how many segments are in the plane. 6 will do
; it will create a plane in 6x6 tiles
rectbrush_ripple = 6
mainbrush = CreateMesh()

;i created a type just to make it easier than creating a bunch of vars for creating the plane.

xbrush.bsurface = New bsurface
xbrushshandle = Rand(1,1000000)
xbrushsurfacen$ = "myplane"
xbrushsurf = CreateSurface(mainbrush)

For tempstuffy = 0 To rectbrush_ripple-1
For tempstuffx = 0 To rectbrush_ripple-1
;tempstuffx = tempstuffy

ttri.btri = New btri
ttrishandle = xbrushshandle
ttri handle = Rand(1,1000000)
ttriv1handle = AddVertex (xbrushsurf, 0+(rectbrush_widthw*tempstuffx),rectbrush_heighth,rectbrush_depthd+(rectbrush_depthd*tempstuffy), 0 ,1)
ttriv2handle = AddVertex (xbrushsurf, rectbrush_widthw+(rectbrush_widthw*tempstuffx),rectbrush_heighth,0+(rectbrush_depthd*tempstuffy), 1 ,0)
ttriv3handle = AddVertex (xbrushsurf, 0+(rectbrush_widthw*tempstuffx),rectbrush_heighth,0+(rectbrush_depthd*tempstuffy), 0,0)
ttri ri = AddTriangle (xbrushsurf,ttriv1handle,ttriv2handle,ttriv3handle)
ttri.btri = New btri
ttrishandle = xbrushshandle
ttri handle = Rand(1,1000000)
ttriv1handle = AddVertex (xbrushsurf, rectbrush_widthw+(rectbrush_widthw*tempstuffx),rectbrush_heighth,rectbrush_depthd+(rectbrush_depthd*tempstuffy), 1 ,1)
ttriv2handle = AddVertex (xbrushsurf, rectbrush_widthw+(rectbrush_widthw*tempstuffx),rectbrush_heighth,0+(rectbrush_depthd*tempstuffy), 1 ,0)
ttriv3handle = AddVertex (xbrushsurf, 0+(rectbrush_widthw*tempstuffx),rectbrush_heighth,rectbrush_depthd+(rectbrush_depthd*tempstuffy), 0,1)
ttri ri = AddTriangle (xbrushsurf,ttriv2handle,ttriv3handle,ttriv1handle)

Next
Next

For brush.bsurface = Each bsurface
Delete brush
Next

For ttri.btri = Each btri
Delete ttri
Next

return mainbrush

End Function


Comments : none...