Author Topic: Randomly Generated Terrain... With Problems... (Help!)  (Read 5758 times)

0 Members and 1 Guest are viewing this topic.

Re: Randomly Generated Terrain... With Problems... (Help!)
Ah, there was supposed to be a question mark at the end.
Code: [Select]
std::vector<std::vector<int> > myTwoDVec; //create a 2-dimensional vector, be careful, the space between the two ">" at the end is needed
myTwoDVec.resize(4); //set the size of the first dimension to 4 (now contains 4 vector<int>)
myTwoDVec[0].resize(5,0); //set the size of the first vector of the second dimension to 5
// The values will look like this
// 0     0     0     0     0 //size 5
// empty //size 0
// empty //size 0
// empty //size 0
Code: [Select]
std::vector<std::vector<int> > myTwoDVec; //create a 2-dimensional vector
std::vector<int> tmp;
tmp.resize(5, 2);
myTwoDVec.resize(4, tmp); //set the size of the first dimension to 4 (now contains 4 vector<int>)
// The values will look like this
// 2     2     2     2     2
// 2     2     2     2     2
// 2     2     2     2     2
// 2     2     2     2     2
http://www.cplusplus.com/reference/stl/vector/resize/

You can, of course, change single values with:
Code: [Select]
myTwoDVec[0][1] = 4; //be carefull that the vector is big enough to have this element)
or simply add an element at the end:
Code: [Select]
std::vector<int> tmp;
myTwoDVec.push_back(tmp);
myTwoDVec[0].push_back(6);
http://www.cplusplus.com/reference/stl/vector/push_back/

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Re: Randomly Generated Terrain... With Problems... (Help!)
I think I'm down with most of the syntax and logic, but the array I'm trying to form is to be filled with double-precision numbers. Is there an addtional step for that, or would doing this work:

vector<vector<double> > 2Dvectorname; // This is the main vector "array," where the number of rows shall be initialized and another vector (declared
                                                                  // below) shall be used to control the number of columns.
 
vector<double> columninputs; // This controls the number of columns in the vector array.

Any help is appreciated.  :D If I can get this to work, I'll be golden.
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 
Re: Randomly Generated Terrain... With Problems... (Help!)
Sure, just use double instead of int.
This works with any types, even with classes you have written yourself.

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Re: Randomly Generated Terrain... With Problems... (Help!)
Thanks, that's good to hear!

I just want to say that your assistance has been invaluable, Uchuujinsan.  :)
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 
Re: Randomly Generated Terrain... With Problems... (Help!)
Thaeris, I'm not sure if it helps, but one way to visualise the STL is as comprised of Algorithms, Containers and Adaptors.
A container 'contains' an object (int/double/etc are all special cases of 'object'), an algorithm operates on a container (which could be a flat array also), and an adaptor makes a container behave slightly differently - for example queue is an adaptor to deque (MS STL).

There are some very good summaries around, but I like the cplusplus.com references.

Don't think of them as arrays - they behave quite differently (except for vector, which is fundamentally an array, but has some interesting insertion characteristics)

Hope the above helps with thinking about the STL.
STRONGTEA. Why can't the x86 be sane?

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Re: Randomly Generated Terrain... With Problems... (Help!)
That was mentioned in my textbook, though there doesn't seem to be a tremendous selection of topics on STL templates in the text. It's not bad, however...

I must say though, that I do not believe that the algoritm library is going to be the help I need. I am actually very close to having something that works more like it was intended to, though. With any luck, it will be today.  ;7
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Re: Randomly Generated Terrain... With Problems... (Help!)
(Insert "Yeah" beam here...)

YEAHHHHH!!!

It's not the best, but it works! All the framework is in place for eventually developing a procedural terrain generator.  :yes: :yes: :yes:

Below is a sample image of the initial file generated (the mesh covers four square kilometers), then the same file subdivided, stretched to an aesthetically pleasing shape, and given a texture I had lying around.

You'll need A C++ compiler to run the program in its current state - it's not stand alone. Also, if you choose to try it/play around with it, you'll need a program which supports the file format outputted by the program. Since you probably don't have AC3D, here's a link to the Blender scripts you'll need:

http://www.marginal.org.uk/x-planescenery/tools.html

[attachment deleted by admin]
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 

Offline pecenipicek

  • Roast Chicken
  • 211
  • Powered by copious amounts of coffee and nicotine
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • PeceniPicek's own deviantart page
Re: Randomly Generated Terrain... With Problems... (Help!)
this could easily be modified to output to normal wavefront obj format, no? (pretty much any 3D software can open that)


btw, just to inform you, this compiled without any problems in devc++ by bloodshed.
« Last Edit: December 16, 2009, 08:36:14 pm by pecenipicek »
Skype: vrganjko
Ho, ho, ho, to the bottle I go
to heal my heart and drown my woe!
Rain may fall and wind may blow,
and many miles be still to go,
but under a tall tree I will lie!

The Apocalypse Project needs YOU! - recruiting info thread.

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Re: Randomly Generated Terrain... With Problems... (Help!)
I'm not sure, though I believe you could. I opened up a wavefront object file with a text editor to see the format, and indeed you can read it to a degree. However, it's not as sensible as object 700 format, which is why I didn't go for it right away. A project for a different time, maybe?

Anyway, I'd assume it would open and compile with any C++ compiler, so devc++ certainly should work, and it did, too!

Thus, after all that, all it needs is a better elevation algorithm and it will be much better. That might have to wait, though. With the other things I need to finish up, this might be what I turn in.

EDIT:

Yalp. Turned it in.  :D

Also, playing with some terrain derived from an output mesh. Even though the algorithm to date is uber-simple, the randomness of the mesh means a few stretches of the verticies here and there can result in a tremendously organic-looking piece of land. Just start draging things about and you'll soon have a nice piece of 3D artwork... maybe. This is one of the few instances where subdivisions are not only practical, but perhaps necessary to achive a level of realism. After the initial stretching of the terrain, I'll subdivide it, reduce it, then subdivide and reduce again. Because subdivisions + reducing operations produce non-uniform triangles, this helps the landscape become more random and thus hopefully more realistic.

[attachment deleted by admin]
« Last Edit: December 17, 2009, 01:47:30 pm by Thaeris »
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: Randomly Generated Terrain... With Problems... (Help!)
Impressive stuff :)

If you want to set yourself a challenge, you could always have a go at a poly-reduction system over distance ;)

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Randomly Generated Terrain... With Problems... (Help!)
I think there may be a name for this, (maybe Perlin noise?) but...

What if you start with a low-res grid (2x2 or so), randomize completely, then scale it up x2, and randomize by about half the amount? Repeat a few times...

 

Offline Flipside

  • əp!sd!l£
  • 212
Re: Randomly Generated Terrain... With Problems... (Help!)
http://www.gameprogrammer.com/fractal.html

You can get more information on basic procedural generation from here :)