tile based terrain system

Blitz3D Forums/Blitz3D Programming/tile based terrain system

aCiD2(Posted 2004) [#1]
hey all, im making a tile based system, so that i can have roads on maps and stuff. Im currently using the following code to do it:

Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()
AntiAlias 1

Type map
	Field width, height
	Field t.tile
	Field tsize
End Type
Type tile
	Field brush, index
	Field r, g, b
	Field isOver
End Type

text1 = LoadTexture("images/text1.png")
text2 = LoadTexture("images/text2.png")

m.map = New map
	m\tsize = 1
	m\width = 4
	m\height = 4
	index = 0
	Restore map
	For i = 0 To (m\height - 1)
		For i2 = 0 To (m\width - 1)
			m\t.tile = New tile
			m\t\index = index
			m\t\brush = CreateBrush()
				Read what
				Select what
					Case 1 BrushTexture m\t\brush, text1
					Case 2 BrushTexture m\t\brush, text2: m\t\isOver = True
				End Select
			index = index + 1	
		Next
	Next

Global terr1 = Terr_Create(m)
	ScaleMesh terr1, 10, 1, 10

Global cam = CreateCamera()
	MoveEntity cam, 0, 50, 0
	PointEntity cam, terr1
	
RenderWorld: Flip
WaitKey
End

Function Terr_Create(m.map)
	Local mesh, u#, v#, stp#, z#, x#, h1#, h2#, h3#, h4#, br, surf, cnt, index, texture	

	tilex = m\width
	tilez = m\height

	mesh=CreateMesh()
	u#=0
	v#=0
	stp#=m\tsize/Float(tilex)
 	index = 0
	For z#=0 To tilez-1
		u=0
		For x#=0 To tilex-1
			h1#=0
			h2#=0
			h3#=0
			h4#=0
			For m\t.tile = Each tile
				If m\t\index = index
					surf=FindSurface( mesh,m\t\brush )				; Find a surface in the mesh that contains the same brush
					If surf=0 surf=CreateSurface(mesh,m\t\brush) 	; If it can't find one create a new surface
					Exit
				EndIf
			Next
			If surf = 0
				surf = CreateSurface(mesh)
			EndIf
			cnt=CountVertices( surf )				; Get count of vertices

			;Add vertices including tile coords
			AddVertex surf,x,h1,z,0,0
			AddVertex surf,x+m\tsize,h2,z,1,0
			AddVertex surf,x+m\tsize,h3,z+m\tsize,1,1
			AddVertex surf,x,h4,z+m\tsize,0,1
			;Add second set of tex coords to fit grid
			VertexTexCoords surf,cnt,u,v,0,1
			VertexTexCoords surf,cnt+1,u+stp,v,0,1
			VertexTexCoords surf,cnt+2,u+stp,v+stp,0,1
			VertexTexCoords surf,cnt+3,u,v+stp,0,1
			;Finally add the two triangles
			AddTriangle surf,cnt,cnt+2,cnt+1
			AddTriangle surf,cnt,cnt+3,cnt+2
			u=u+stp
			
			index = index + 1
		Next
		v=v+stp
	Next
	UpdateNormals mesh
	;CenterMesh(mesh)
	Return mesh
End Function

.map
Data 1,2,1,1
Data 1,2,1,1
Data 1,2,2,2
Data 1,1,1,1


it generates a terrain mesh all fine and dandy, but the actual tiles are to 'distinct' how can i make it so that the grass and the path blur into each other? the only awy i can think of doing it is by making an animated texture that had lots of frames for directions of the path, with a blur alpha map sort of. then i could multitexture using the alpha mask.
surely there is a quicker way of doing this however?

thanks all,
aCiD2