• Advertisement

• ### Popular Now

• 13
• 16
• 27
• 9
• 9
• Advertisement
• Advertisement
• Advertisement

# Tyre tracks on terrain (and road texturing, too, while we're at it)

This topic is 2936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I have a vehicle (let's say a tank) and I think I have it following the terrain pretty closely now (I'm using 4 points in a T-shape to do my pitch and roll calculations). It still clips through the terrain here and there and one of the wheels stays too far off the ground here and there, but only so much). The one solution I think that might alleviate the fact that I don't want to do vertex/pixel-accurate collision detection is tyre tracks. I've bounced the ideas that I have in my head around for a while now, but none of them seem to work too well. - my vehicle can turn arbitrary angles and go in arbitrary directions - it can turn locally, without moving sideways, back or forward (like a tank) - it is user-controlled - the terrain is a heightmap and should be assumed to be arbitrary I'm guessing the safest bet would be to use decal textures, but I've no idea how to go about calculating texture coordinates for the tracks. or even how to go about applying them to the terrain without massive additional geometry. The only alternative I can think of is using displacement mapping and doing the whole thing on the GPU. Unfortunately I can't consider myself savvy enough to do that (so, at this point I'm looking for a simpler alternative). Also, apparently there aren't too many webpages/tutorials dedicated to this kind of stuff on the web, so if anyone can direct me to something, I'd much appreciate it! Another thing closely related to tyre tracks that I've had on my mind for some time now, but haven't really got around to dealing with yet, are roads. Without getting into too much detail at this point, I'll just throw the question out there - how precisely do they texture/render dirt and gravel roads in games like Colin McRae Rally and such? I don't need that kind of detail, but the concept intrigues me.

#### Share this post

##### Share on other sites
Advertisement
You can find a pretty interesting article about the way they added skid marks to MotoGP here: Shawn Hargreaves Blog.

#### Share this post

##### Share on other sites
Theres an article on Decals in Games Programming Gems 2. It fully explains how to create the triangles, clip them to the projection area and calculate the texture co-ordinates. However, the price might be a bit steep for just 1 article (assuming you can't find it in a library), so this less descriptive but pretty complete blog post may help you.

In your case though, decals like those might be overkill. They're very good for projecting onto polygon soups but in your case you know they will only ever affect the terrain, so you can take a simpler approach. Something like this should cover it:

foreach track in tankTracks do    topLeft = track.position + (track.left * track.width * 0.5)    topRight = topLeft - (track left * track.width)    bottomLeft = track.previousTopLeft    bottomRight = track.previousTopRight    topLeft.y = Terrain.Query( topLeft.x, topLeft.z )    topRight.y = Terrain.Query( topRight.x, topRight.z )    wheel.previousTopLeft = topLeft    wheel.previousTopRight = topRight    TankTrackManager.Add( topLeft, UV(0,0),                          topRight, UV(1,0),                          bottomLeft, UV(0,1),                          bottomRight, UV(1,1) )end

Assuming there are no sudden sharp spikes in the terrain between the current position and the previous position, that should give you a simple starting point to work from. Note, this is not a function that should be called continually [smile] Once every few meters of movement should be fine (the tank tracks will probably cover up the area of terrain that doesn't yet have any imprint).

As for massive additional geometry, well each decal is now just 2 triangles (instead of a potential polygon soup). You could also store all tracks in one vertex buffer (updating it with just 2 additional triangles every few frames won't cause much of a slow down at all) this will let you batch the drawing into 1 call. You could also remove older triangles from the buffer after a certain length of time, or if you decide you have too many. Another potential optimisation is using a triangle strip rather than a list, this means adding just 2 extra vertices to the buffer rather than 4. Theres plenty of options available to you, more than I have stated here. A bit of experimentation should have you set with a pretty robust system =]

Hope that helps. [grin]

 As it happens, pretty much all of what I just said is mentioned in link Promethium posted. Maybe I should have read that first? Ah well, my bad. =]

#### Share this post

##### Share on other sites
Much appreciated, guys! I implemented the method outlined in Promethium's link -so far I'm having trouble with the tracks aligning with the heightmap: as the tracks can appear at arbitrary angles and directions and the heightmap is inherently discrete, cell borders becomes issues and need special addressing lest the tracks skip through the terrain at hilltops. I'll have a look into the projection method a bit later as I'm instead having some vehicle trouble that I need to work out before I start dealing with eyecandy. In any case, much appreciated, guys!

#### Share this post

##### Share on other sites

• Advertisement