Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Roads on a Terrain

Author
Message
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 18th Jan 2010 01:56
I know this probably has been discussed before. I am looking to create terrains and add roads over the top of them. Have roads cross like we see it Cities and Towns. I create the Terrains as Objects so we have a nice textured terrain.

One early theory is to use a Matrix under the terrain and set the height above the terrain where ever I need to draw the road. The limitation here is I can only have roads in two directions, North to South, East to West. Cannot do curves or diangle roads. Plus it is adding more vertexes into the scenery and do notice a drop in frame rate.

The more complicated way to do it is create roads meshes with the memblock and I have been looking for samples and source code that deals with Memblock created meshes. I think this may be a route I may go with later.

This is something I intend to use with my AutoDual clone game that I asked for some help with last year. If somebody has done something like this already, I would not mind looking at some source code and maybe I can adapt it to what I need.
gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 18th Jan 2010 02:08
I'm not 100% on what kind of roads you're looking for: Do you want "flat" roads that lie on the terrain, or roads that exist "above" the terrain, as in overhead bypasses?

If you want flat roads, I'd say you should just decide where you want your road to go, and set every point along that path on your heightmap to the same value. If you're using DBPro's standard terrain commands, you'd just do that in whatever art program you make your heightmaps in, although you may also want to look at more advanced terrain editor programs that exist throughout the forums. Once you have a flattened path around your terrain, either texture the terrain directly with a road, or add textured plains to the terrain that make up road "segments".
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 18th Jan 2010 02:27 Edited at: 18th Jan 2010 02:29
They would be flat roads that lay on the terrain, follow the contours of hills. I am not sure how to texture specific parts of a terrain, been scanning through the DBPro Help for solutions to this problem.
gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 18th Jan 2010 03:23
In that case, you probably want to use a shader to texture the terrain, as DBP's native terrain commands do not offer an easy way to do this. DBP uses two images for textures: You have a "texture" image, which is mostly used to supply the terrain with color. The image is stretched across the entire terrain, so if you have a 512x512 heightmap and a 512x512 texture image, a single pixel from the texture would be used for an entire tile in the terrain. Naturally you can see you would require an astronomically sized texture to get an even somewhat discernible road pattern using this method.

You also have a "detail" image, which is typically a greyscale image, and this is actually tiled across the terrain. It basically gives the texture it's "depth", so instead of solid colors, you see details like stones or grass or whatever is in the detail image. The downfall of course is that you can only use one detail image for every tile in the entire terrain.


You should also look into VanB's Tersculpt program, it's a pretty nice terrain editor that allows you to easily set multiple textures, so you should be able to craft a road using that.
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 18th Jan 2010 04:41
With one texture stretched across and a second one being tiled, it does not leave anything for detail drawing. I may not go with using the DBPro Matrix process because that does not suit what I need to do. I have found some code on here that uses MAKE OBJECT NEW, SET VERTEX POSITION, etc. I think I can manipulate it to render a texture road on top of a terrain.

Well thank you anyway. Maybe if I get it done soon, I will share what I come up with.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Jan 2010 13:44
Use some form of terrain plugin, (like sdvanced terrain, blitzterrain ect) and draw your road on your supertexture. simple.

My signature is NOT a moderator plaything! Stop changing it!
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 18th Jan 2010 22:36
Do you mean advance terrain or is "sdvanced terrain" a new product?

I will check these out, looks like blitzterrain is better documented.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Jan 2010 23:32 Edited at: 18th Jan 2010 23:34
I build my road as a separate mesh on the terrain. Then I can use it programmatically to get the vehicles following it, create waypoints, detect collision, etc.

I've had to do it from scratch. I create splines to represent the track. Then the spline is used to generate the polys that make the 3D mesh for the track. Finally, you have to go through the vertices and drop them onto the terrain at the correct height. It's hard work, but the results pay dividends.

The image is an early prototype, with alpha textures it blends well.



PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 18th Jan 2010 23:40
Now that is more or less what I am looking for. One issue with using Advance Terrain or BlitzTerrain is that I would have to pay to use them. Building it as a separate mesh is a route I am starting to explore right now because I need to control textures. I have textures that have painted yellow and white lines on them.
Green7
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 18th Jan 2010 23:50
Quote: "One issue with using Advance Terrain...is that I would have to pay to use"

really? isn't AT for free?

PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 19th Jan 2010 00:14
BlitzTerrain may be. I have not looked into Advance Terrain yet. When people tell me about these things, they don't include where to get these things and I have to search and sometimes have to read a half dozen threads before coming upon where and how to download the plug in.

I would not mind looking at the source code of how to draw that road. I am starting to write my own right now.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jan 2010 00:16
Yes, AT is part of DBPro now and has been for a long time.
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 19th Jan 2010 00:23
Yeah I already using advance terrain with my current program. But command structure is not in the DBPro main help file so I have to search the threads here and see how to do something like painting a road onto a terrain.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 19th Jan 2010 06:23
Have a look at my post on track editors,most of the code you want is in there,if you need any help with it let me know.
http://forum.thegamecreators.com/?m=forum_view&t=158864&b=8
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Jan 2010 12:42
Quote: "But command structure is not in the DBPro main help file "


I think Sixty Squares posted a Help file for AT on this board.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jan 2010 12:57
Your kinda on your own with AT - you have a detail textures and a colour texture - with AT your only real option is to draw the road with an art package.

The other methods shown are more elegant, either use a shader to add a road texture onto the terrain - which can give 5 or 6 detail textures if you want. Or there's the road mesh like Batvink shows, laying on top of the terrain. One similar technique I've used, is to have chunks of terrain on top, like blankets on an existing terrain (AT even) but then only create polygons where there is actually road, so similar to Batvinks, except it adopts the same terrain mesh layout. One benefit in this is that with 1-bit transparency, you can vertex colour and produce really smooth edges, either smoothly fading out, or infinitely smooth curves. I made an example for this, but I'm not sure if it still works - allows patches to be added to a terrain based on a greyscale - like you could get a road texture and draw where you want it on a greyscale image.

So there are several techniques you could use, some very complex, some quite demanding on the processor - but I think we'd all agree that just drawing a road onto an AT colour map is the easiest, but the sloppiest and ugliest method.


Health, Ammo, and bacon and eggs!
kaedroho
18
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 19th Jan 2010 14:15
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 20th Jan 2010 02:49
I am looking at that track editor code at the present time. It gives me an ideal of how to do it. I would have to figure out what some of those functions do. I am thinking about something that can automatically adjust to the contours of a landscape and have multiple connecting roads.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 20th Jan 2010 07:46
PeteyM5,if you read down the post you will notice i said i'd split the code up into 3 seperate parts,but ive only posted the basic track editor,i also have a random fractal based terrain generator that can either carve out the random terrain to match the hights of the track or ignore the hight data for the track and lay it directly on the surface,just slightly above so as not to clash,but not high enough to be noticeable.If you want it,i'll post it for your when i get home.The hole thing is based around functions to make it portable between my different projects,im sure you could make it work with any type of hight map data you use.
If you want to use advanced terrain however then i dont think this will be of much use to you
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 21st Jan 2010 10:44
@paul547
I tested your first code and works great ! awesome!...what plug ing do we need to run other codes?...I,m interested in your code pleeees

cheers.

learning every day
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 21st Jan 2010 15:53
Chafari,i dont think it uses any plugins except may be for file loading but you can just set the file names directly in the code,i'll check it though before i post it because i tend to use Ianm's Matrix1 plugins without realising some times.
qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 21st Jan 2010 19:44
paul, yeah that'd be cool if you posted that. i'll be working with fractally generating terrain and laying down roads pretty soon so seeing how others approach the problem would help a lot
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 21st Jan 2010 21:26 Edited at: 21st Jan 2010 21:27
OK,heres the 3 bits of code.Copy and save each code snippet as a project file,then run each one in this order,editor,builder,loader.
These arnt the versions that i used for the videos they are very stripped down bits of code and as such the track in this is not layed directly on the surface but is about one unit above.The builder part of the code as been optimesed for speed not acuracy.The builder i used for the videos took about an hour on my pc to sculpt the track,this only takes about a 60 seconds,but the game im helping with has walls around the track so the gap isnt this obvious.
Editor

Builder

Loader

Hope this helps some on or atleast gives a few ideas.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Jan 2010 11:45
@paul5147
Ok now all three codes works perfect to me! thanks !!... Just one more question...I,v have been trying to make an avi with the road made with your editor, and I don´t figure out how to get this smooth and continuosly avi. Time ago I had Camtasia studio but it was a 30 days trial.

cheers.

learning every day
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 22nd Jan 2010 11:47 Edited at: 22nd Jan 2010 12:45
Try fraps,its free and very easy to use.
Little bit more code for you,media free landscapes,this has a deformable mesh wish is how I do the sculpturing for the track now.
Very quick but it does need Sparky's and Matrix1 plugins to work.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd Jan 2010 12:44
Quote: "Try fraps,its free and very easy to use. "

But limited to 30 seconds of recording.

My signature is NOT a moderator plaything! Stop changing it!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Jan 2010 15:00
@paul5147

woW!!...awesome this last code, I like the way it rise up the mesh so smooth..Thanks.

About fraps, I will have a loot at it.

@Mobiius
Quote: "But limited to 30 seconds of recording"


Ha ha..thats all I need...then I`ll joint them with virtualdub..

learning every day
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 22nd Jan 2010 15:07
Yeah I did that with fraps. As soon as it stopped recording I just started to record again.

If it hasn't exploded yet, I haven't touched it.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jan 2010 15:20
It's worth investing in FRAPS, I think it's the best software recording solution, it does leave some processor power for whatever your capturing - I think it was only £15 or something, was ages ago that I got it so I'm not sure what it costs these days.


Health, Ammo, and bacon and eggs!
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd Jan 2010 16:18
Fraps is Only $37, which is currently £23.0039.

Not too bad, or you could even buy dark video with it's live capture. But that only encodes to it's own native format.

My signature is NOT a moderator plaything! Stop changing it!
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Jan 2010 16:19
Yeaaaah . that´s it...framps works perfect !!, and you don´t need more time, as you will prefer to have differents angles of vision,so you can make several shots and joint them and reduce the .avi with virtualdub that is free.

30 seconds of video, are 159 MB and converted wiht virtualdub to Xivd just 8 MB...It's worth it.

cheers.

learning every day
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jan 2010 16:29
Yeah, was probably only £15 back when I got it .

Fraps has a watermark, plus the 30 second limit as discussed - so it's very useful, but if you want to make better videos, then get the full version. For instance, my most popular youtube video is me making a terrain with Tersculpt and then exploring it - the exploring bit is at normal speed, but the creation part is at about 3 or 4 times speed. With a non-limited recorder like full Fraps, you can record it, and add it to your video at the speed you want - you might not need more that 30 seconds of actual footage right now, but that will probably change before very long; I couldn't make the fast terrain video without it. The restricted Fraps is restricted .


Health, Ammo, and bacon and eggs!
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 23rd Jan 2010 04:40
Hey guys thankyou. One thing I will try to modify is drawing the track using less objects. Maybe draw a whole section as one object or all the needed roads on the map as one object. What I see here gives me a good start. Reason being is that I don't want object numbers to conflict. Lets say we use 1000 to 1999 for road sections, 2000 to 2999 for trees.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 23rd Jan 2010 07:41
Glad we could help.You may get a bit stuck trying to make all the track as one object due to the uv data used for texturing it.You could always make the first section then convert all the others one at a time to meshes and add them as limbs to the first and use the texture limb command to get around this.The reason i make them all this way as seperate objects is for the collision detection,it allows me to pick out individual sections of track for use as trigers,say you put a power boost texture on a section or maybe an oil texture,i know if the player hits that precise section of track rather than just that there on the track somewhere.
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 24th Jan 2010 00:04
I could create the initial object for the first segment and add all the other segments as limbs. I do not need specific section collision but need to apply different textures for city roads, intersections, highways, bridges, etc.

I need to look up exactly what some of those memblock numbers do at the beginning. Pergaps searching this forum will shed some light on the matter.
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 24th Jan 2010 13:25 Edited at: 24th Jan 2010 13:38
I managed to draw very long strips as a single object. I use arrays rather than getting the limb positions of an object.



This provides more of what I am looking for.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 24th Jan 2010 14:04
Im assuming your still trying to do this with advanced terrain,nice bit of code i like the way you tiled the uv across it by using more than the 0-1 range for the uv,I think you may run into problems though with advanced terrain if you try to put a bend in the road because the sizes of the polies your using for the road wont match the grid pattern being used by AT so they will intersect and the terrain will pop through the road texture in places,were as if you use your own terrain object you can drag the nearest vertex to the position of you road objects vertex so they match up and give no tearing.The only problem is you cant do it quickly enough in real time so you have to build everything in advance and load it in.Thats why i split my code into seperate bits,i have quite a lot of different versions of the "builder" code,some simply carve the terrain to match,quick but ugly,others stretch and pull the terrain vertexes to match the terrain,slow but accurate as it has to go through every vertex of the track against every vertex of the terrain and match them up.Keep up the work,your definatley on the right lines it just depends on what you want to achieve,if its only a background and the roads arnt going to be followed or the player made to stick to them,then why not just work on memblock images that you can use in AT,you can even make the hight map and textures almost in real time,or you could just use sprites on a hidden bitmap to make the road part of the texture and use that as the AT texture.Hope you keep going and take this to a WIP post.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 24th Jan 2010 15:47
Small media less ATerrain way to add roads,would look a lot better with external media but you get the idea.
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 25th Jan 2010 23:25
I could not get that sprite code to work. Says something it cannot grab image due to an illegal area. I am not sure using a sprite system would be compatible for what I am looking to do.

I have started a system where I can have multiple intersecting roads. I have to work out bridges over water and over pass bridge. It can currently have a road go up a mountain and I got around the terrain popping through by raising the road further above the ground if it detects a large change in height. I am intending to use large mountains more for background scenery and have the roads go through the parts that are flat or slightly hilly.
paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 27th Jan 2010 08:06
Sorry PeteyM5,you need to run it windowed at 1024 x 768 ,other wise it defaults to 640x480 and cant grab an image outside that area.It only uses the sprites to make the texture for the road.
Edited code

Should work now
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jan 2010 08:35
Quote: "I use arrays rather than getting the limb positions of an object"


I started with arrays but moved to memblocks, it was multiple times faster.

PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 30th Jan 2010 02:04
What it is doing now is set up everything in an array then it transfers all the points to a memblock. Maybe a final version of the routine will encode everything directly to a memblock. I am working out different formats for curves, onramps, offramps, switch the number of lanes, bridges, intersections, etc. I am creating city environments and highways that connect between cities. This is an automobile battle game that will have cars with weapons that you can custom build. I will be posting in the WIP thread for the overall progress of the game.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Jan 2010 19:39
If it helps...all of my vertices were stored in an array, and then I built the mesh in a memblock. By saving the vertex data in a memblock and then building the mesh in a second memblock, it was many times faster. It became noticeable in edit mode, where I drag the spline handles and reshape the road in real time.

Another tip...when editing in real time I reduce the number of polys for speed. Once the mouse button is released I go back to full resolution. The beauty of splines is that this technique is extremely easy.

paul5147
20
Years of Service
User Offline
Joined: 11th Jan 2006
Location: Hot & Sunny
Posted: 6th Feb 2010 23:41
Latest video of my code if you want it i´ll post it for you,demonstrates how to map the road to the terrain perfectly and how to use transparent images to make the textures in game at run time,check my wip post on this later for the editor and loader code.
http://www.youtube.com/watch?v=MX6wCdkpFQw
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 14th Feb 2010 13:19 Edited at: 14th Feb 2010 13:20
I tried that alternate terrain textured program and wonder how to get curved roads on the terrain. I know that would be an issue using that technique or if I created a terrain and road system with matrix commands.

How ever I have made some progress with multiple intersecting roads with bridges now.

http://forum.thegamecreators.com/?m=forum_view&t=165568&b=8&p=0

I have to record the start position of the bridge and add them as separate limbs. It also records the position of curves if they occur over a bridge, so a bridge can have snake like bends in them.

I know building an array on a first pass and then transferring all the points to a memblock on a second pass may slow things up a bit. But it does get the job done.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 2nd Mar 2010 06:47
Sorry so late to the party on this, but, I have come up with a 3 tool method for roads. It goes like this:
Build my terrains with my USGS apps, reduced poly count. Load the terrain into Ultimate Unwrap and export it as an .obj, so I can load it in Animation Master (doesn't import .x). Then, I use the Sweeper plugin to create a spline based road that roughly follows the terrain. I then delete any vertices on the original terrain in AM that the road is overlapping or very close to. I then export it out in .obj, reload in UU, export it out in .x, and load it up in DB with a utility I wrote to retriangulate the whole mess using Qdelauney. After the triangulation, reload into UU for mapping and paint.
Sounds like a lot, but the whole process, except for actual texturing, takes about 30 minutes.
Here is one I just did, notice the road is actually connected to the terrain, not overlapping, and even has curbs. In UU, it is possible to make the road another group, or limb, if you wish. With the sweeper plugin in AM, it is very easy to make evenly spaced swept splined objects.
Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 2nd Mar 2010 08:38 Edited at: 2nd Mar 2010 08:38
And here is another one I just did. It is loosely based on Limerock Park racetrack in Connecticut. I just rotoscoped a Google Earth image of the track, and added it to an AM generated terrain(not ver realistic), but, shows how the triangulation works very well in connecting the track surface to the surrounding terrain.
PeteyM5
17
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Buffalo NY USA
Posted: 28th Mar 2010 14:16
Here is my game project so far. I manage to set up something that helps me link road segments together and render bridges underneath them.

http://forum.thegamecreators.com/?m=forum_view&t=165568&b=8

Roads and Bridges are just one aspect of the game I do have to worry about. I am also working on ways to generate forests along side of the road, water under the bridges, and doing work on the vehicles themselves. It is a lot of work for myself and is why I do ask for assistance on this project. Right now I am looking for some help tweaking the visual elements to get them to look better without hogging the CPU. I want to put together something that can impress hardcore gamers and be profitable.

Login to post a reply

Server time is: 2026-07-26 21:11:32
Your offset time is: 2026-07-26 21:11:32