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 Discussion / Height Maps

Author
Message
Pillar3721
16
Years of Service
User Offline
Joined: 5th May 2009
Location:
Posted: 6th May 2009 04:06
Hey guys.

So im in high school, and my gaming class has been learning basic through darkbasic all year.
But, its the end of the year, so the teacher has split us up into groups and given us free reign to make a game.
The problem is, we've not really learned a lot this year but yet our group want to make a pretty decent game.

My job for this is to make terrain, some way, some how.

Originally, we tried doing a .3ds model, but it didn't come with texture, and we had no idea what we were looking at, so we trashed that.

And i've been browsing around, and heard about heightmaps for terrain. This is something that i think might work for our terrain, but i dont know how to add heightmaps to matrixs, or even do collision for it.

I've added the heightmap we'll be using, but if someone could possibly give us the snippet to transform the heightmap into the matrix, and then add collision to it, it would be appriciated so much!

Thanks.

Attachments

Login to view attachments
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 6th May 2009 04:21
i remember from a while back that someone said that in the .3ds file, there was a line that said the filename of the texture, sometimes this was wrong and a simple change would make it load the right texture

otherwise i believe u can just load the image using load image then texture the .3ds model with texture object <object number>

sorry i cant help with heightmapping though

There are only 10 kinds of people in the world, those who understand binary and those who dont
Pillar3721
16
Years of Service
User Offline
Joined: 5th May 2009
Location:
Posted: 6th May 2009 04:46
Well we got the model off of turbosquid, but when we tried to download the texture in a separate pack, the file wasnt there, so we were left a texture less model, and that to even had lots of empty spaces, and we didnt know what we were looking at.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th May 2009 05:53
Quote: "I've added the heightmap we'll be using, but if someone could possibly give us the snippet to transform the heightmap into the matrix, and then add collision to it, it would be appriciated so much!"

Sure why not, got any algebra homework while you're at it

Matrices (plural of matrix) are your best bet. They are simple to use, do the math for you and can create some pretty good landscapes.
So, onto heightmaps. If you want your landscape's hills and valleys to be the same every time you run the program you'll have to store them in some way. A simple way is to use an array (ryhmes so it must be true). What you do is make an array the same size as your matrix, then in the fields/instances of the array you store the height of each particular vertex (point).
Like this...

For every vertex on the matrix there is a corresponding instance in the array. By cross-referencing them we can set the height of

OBese87 - bringing you the world of today, tomorrow.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th May 2009 05:54 Edited at: 6th May 2009 06:09
the matrix...

UPDATE the matrix and you'll see your designed level spring out of nowhere.
Note that I am using a variable for the land width and depth in these examples, its likely that you'll want to change the size of the landscape; using variables makes it really easy to do this as we'd only have to change their initial values and the whole program would adapt.

Ground collisions are easy with matrices, the command GET GROUND HEIGHT() will return the height of the given position on the matrix. Then all you have to do is position your object at that height.
most objects are positioned by their middle so you'll have to add a set amount to ground height to make it look right.

Look in the help file if some of the commands I mentioned are new to you. If you have any problems post back, there are lots of talented coders with far too much time on their hands

Hope I helped.

OBese87 - bringing you the world of today, tomorrow.
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th May 2009 08:38
@Obese
This might be jumping in a bit too far for him, but could you not have the heightmap saved as a bmp and then load it into a memblock and get the data from it that way?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th May 2009 13:37
@BN2
yeah I've seen people do that using brighter colours to show higher points. The nice benefit of that is you have a visual representation.
but as you said you'd need to be pretty good with memblocks before trying that.

OBese87 - bringing you the world of today, tomorrow.
Pillar3721
16
Years of Service
User Offline
Joined: 5th May 2009
Location:
Posted: 7th May 2009 03:30
@Obese

Well with the code you gave me, the first part did not have enough integers to fully work, so after i put that in, the for/next loop didnt work either, and i didnt know how to fix that. But thanks anyways!

And when i tried using one of the codes from the code base to do my desired effect

http://darkbasic.thegamecreators.com/?m=codebase_view&i=89f07ac2301f87987ffbd6eebdcc7f3f

All it did for me was paste the picture of the bitmap i was using onto the screen, nothing else. It might be that might bitmap sizes were bigger than 256x256, and ill check that tomorrow.
Maybe someone can see whats wrong with it.

But now mainly in the essence of time, and the fact that i can not get anything to work, and that you can't get full collision on .x and .3ds models so that i can use a premade model terrain, im going to resort to stealing a piece of code where it makes a random matrix and has collision for it, and maybe try to figure out how to preset tile in the matrix to certain heights. But thats a maybe.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 8th May 2009 18:37 Edited at: 8th May 2009 19:08
I have some code somewhere that I made out of several pieces of peoples and my own code. It loaded a heightmap, made a large matrix (not for feint hearted pcs) then split it into smaller matrices, then into memblocks and then objects which can be used for lod or collision or saved and loaded next time, just like any other object. Ill dig it up for ya

Edit:
Ive attached the code + some heightmaps.
Im afraid its not commented, its 600+ lines long and i didnt bother to comment it when I made it. If you just complie it straight away, it should run with the heightmap its set to, I dunno if itll need to change a bit to work with other maps.
If you want any help, just ask =)

Move with mouse and mouseclick

Attachments

Login to view attachments
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th May 2009 18:53
@Pillar

Check out:

Phaelax height map

and

Pharoseer Plasma

Enjoy your day.
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 8th May 2009 19:08
Pillar, that code snippet that you posted above works, it just didnt have any waits or anything...

I added a loop into it so that you can travel around the terrain, and the code does work. Although, its effectiveness depends on your choice of .bmp


Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th May 2009 15:08
Sorry I didn't test that. Here's the working code...


OBese87 - bringing you the world of today, tomorrow.
pictionaryjr
16
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 10th May 2009 05:29 Edited at: 10th May 2009 05:35
This is a heightmap function I just whipped up. I know it takes a long time to load, but it works.

Mt is the Matrix Number
Mx and My effect how big the matrix is
Tx and Ty effect how many tiles will be on the matrix
Heightmap$ is the name of the heightmap picture


*The picture size has to be the same size as the number of tiles in the matrix. Ex.(The picture is 45 by 70 so the matrix tile numbers would be tx=45 and ty=70)

The Function



How to Use the Function



@Pillar
The Download includes your picture resized to 70 by 70 and how to use the function.

Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 10th May 2009 05:55
@Pic Jr
You can get rid of that fiddley Amount variable and just use the x/y by changing the heightmap to a 2D array heightmap(x,y).

The point command is horribly slow. You need to use memblocks to get decent speed. They are quite hard to get the hang of but once you do they are easy. I'll upload some functions that will make this code easy with memblocks when I go to the library.

Riddle: The more you take, the more you leave behind. What are they? Answer
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 11th May 2009 03:49
Quote: "They are quite hard to get the hang of but once you do they are easy. "


Really no. all you need to know is how big the different data types are. and the equations to find positions in them. i would strongly i mean STRONGLY suggest looking into them. they are fast and they are like a array but it can have more then one data type.

New Site! Check it out \/
Pillar3721
16
Years of Service
User Offline
Joined: 5th May 2009
Location:
Posted: 14th May 2009 15:26
Thanks guys, all that helped a lot. And one more thing, is there a command where i can completly delete everything on the screen, and start new? Like having a menu, and when you select start new game, it deletes all the things on the screen, everything. Because when were trying to get this menu to work, it works, but no matter if we delete the images or do cls, some of the menu stuff still stays on the screen, ant ideas?

Login to post a reply

Server time is: 2025-06-08 07:21:36
Your offset time is: 2025-06-08 07:21:36