Texturing track/path onto textures

Blitz3D Forums/Blitz3D Beginners Area/Texturing track/path onto textures

I am working on a train based game which will require tracks to be drawn on the 'ground'. I have created a plane and textured it with a grassy texture, and now need to be able to draw the railway tracks. I have a 256x256 texture ballasted track/rails and need to repeatedly render this onto the floor while following the centre-line of each track piece. Unfortunately I cannot fathom how to do this. I have searched the forums and found a couple of similar questions, but none with any indication as to how this is done.

Do I need to create an object for every required occurance of the track texture? Should I be using 3D sprites instead (er - if so, I'm not entirely sure what a '3D sprite' is...)?

If anyone could point me in the right direction I would be very grateful!

why not make a 3d model?

The track is generated from a data file when the game starts - so that the eventual game will be able to run different layouts.

At the moment, I have a system which builds the layout from lots (and lots) of textured cubes, all joined to and rotated around pivots to produce a circuit. My concern is that using cubes involves 6 surfaces, all of which need to be rendered by the 3D engine every update. Since I am only really interested in the 'top' surface, I was hoping there was a way of creating a single surface 'tile' and drawing it onto the ground - rather than using cube entities.

If you are recreating some sort of model layout i.e. you are not creating a train sim then you can just create some 3D models representing straight tracks, curved tracks, crossed tracks and points. That way you'll be able to put the whole track together piece by piece just as with your home train set. Take a look at some of the catalogues produced by big companies such as Hornby, Maerklin, Roco, Fleischman, etc. They all have a section describing their track system i.e. showing all the pieces with their lengths and radii. That should be a good starting point.

Barney

You could use the UV coordinates for assigning the track pieces onto the plane. Each mesh can hold 2 sets of UV coords. You could for instance use the first one for the track, and the second one for the common texture.
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

;create texture
tex = CreateTexture(128, 128)

;green background
Color 0, 255, 0
Rect 0, 0, 128, 128

;curves
Color 255,255,255
Oval 12, 12, 40, 40
Color 0, 255, 0
Oval 20, 20, 24, 24

;straight lines
Color 255, 255, 255
Rect 64+12,0,8, 32
Rect 64,32+12,32,8

;put graphics onto texture
CopyRect 0, 0, 128, 128, 0, 0, BackBuffer(), TextureBuffer(tex)

;draw grid (only for preview)
Color 255, 0, 0
For i = 0 To 3
For j = 0 To 3
a = i * 32
b = j * 32
Rect a, b, 32, 32, 0
Next
Next

Flip

Delay 1000

;create mesh
mesh = CreateMesh()
surf = CreateSurface(mesh)

;create 4x4 grid
For i = 0 To 3
For j = 0 To 3

	;read image index from data
	Read x, y
	;convert to UV coordinates (on a 4x4 matrix)
	u# = x * 0.25
	v# = y * 0.25
	w# = 0.25

	;create vertices
	v0 = AddVertex(surf, i + 0, j + 0, 0, u + 0, v + 0)
	v1 = AddVertex(surf, i + 1, j + 0, 0, u + w, v + 0)
	v2 = AddVertex(surf, i + 1, j + 1, 0, u + w, v + w)
	v3 = AddVertex(surf, i + 0, j + 1, 0, u + 0, v + w)
	;add triangles
	AddTriangle surf, v2, v1, v0
	AddTriangle surf, v3, v2, v0
	
Next
Next

;put texture onto mesh
EntityTexture mesh, tex

;create camera
cam = CreateCamera()
MoveEntity cam, 2.5, 2.5, -5

;show result
Repeat

	RenderWorld()
	Text 0, 0, "Press Esc to end"
	Flip

Until KeyHit(1)

End

;4x4 data (row, col)
;the mesh is mirrored, because i didn't create it in the right direction
Data 0, 0
Data 2, 0
Data 2, 0
Data 0, 1

Data 2, 1
Data 3, 0
Data 3, 0
Data 2, 1

Data 2, 1
Data 3, 0
Data 3, 0
Data 2, 1

Data 1, 0
Data 2, 0
Data 2, 0
Data 1, 1


@Barney: Although not a true sim, I hope to have fairly realistic track formations and curves, so want to be able to load many predefined configurations to give me maximum flexibility (mind you - since they ARE predefined, your idea of a model per track-piece might be the way I end up going).

@b32: This looks good. I will see if I can understand how it works and try to apply it to what I have already.

Thanks.