• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MARS_999

Random location of space objects how to keep a specified min distance?

9 posts in this topic

I am currenlty randomly generating positions for my space objects. e.g. asteroids, planets, ect...

What I have so far is a distance check, but I think I need some kind of STL algorithm or something that automates running through a vector or list of obejcts over and over until all objects have been tested against each other....

Any ideas?

Thanks!
0

Share this post


Link to post
Share on other sites
This is actually an interesting problem if you want to solve it efficiently. There is a trivial method but which takes O(n^2) time (generating each object at random and checking against all existing ones until no collision occurs). Another, smarter method is to generate an AABB and subdivide it at random (making sure each subdivision has a minimum volume) generating some form of tree structure, and once you're subdivided enough, place planets at random in any of the leafs - guaranteed to be collision-free, but since you use AABB's some patterns can appear.

Of course, if you don't care about performance, and if there is no STL method for doing this, you can wrap the naive algorithm around a vector relatively easily if you have the generation method and the collision method. Here's an example with arrays, since I don't do C++...

[CODE]
// generates a random, collision-free position for all objects
for (int t = 0; t < objectCount; t++)
{
do { objects[t].randomizePosition(); } while (Collides(t));
}

// checks collision of object at index t with all previous objects
bool Collides(int t)
{
for (int k = 0; k < t; k++)
if (collision(objects[t], objects[k])) return true;

return false;
}
[/CODE]
1

Share this post


Link to post
Share on other sites
Have you thought about approximating solar system formation?

I've been thinking about how to do this in my upcoming space simulator. I plan on starting with a density distribution of materials and where they exist relative to the host star in the accretion disc - this will probably be randomly generated within certain parameters (dense stuff near the star). I'll probably figure out some kind of clumping algorithm that will form orbiting bodies wherever there are local maxima in the material density. Finally, I'll use a distance check to see if there are any objects that cross or come near to each others orbits, these objects will be assumed to collide at some point and so I either combine the materials from each into a single body or produce many small bodies, the result of an explosive collision. This algorithm continues until the distance between the orbits is greater than some threshold.

This should produce results that if not accurate are at least plausible based on our current understanding of how solar systems form. If you're not going for realism, the AABB method discussed by Bacterius seems like a good way to do it.
0

Share this post


Link to post
Share on other sites
Yeah I thought about just using bounding spheres, also but wasn't sure if there was anything in the STL algorithm lib that would do some testing and sort of std::pair<Obj*, pos> an iterate over the pairs until they were at a minimum distance from each other....

Good ideas guys! I will try the bounding volumes first....

Thanks!
0

Share this post


Link to post
Share on other sites
Some thoughts about my terrain generation (large objects). I subdivide the area into cells (+ some spacing between cells). Each cell can contain one randomly placed object, the spacing between the objects guarantees, that you don't get overlapping objects. This is similiar to the AABB approach. Even better would be a [url="http://en.wikipedia.org/wiki/Voronoi_diagram"]voronio cell[/url] generation which will break up patterns more. You can place your objects randomly within the boundaries of a voronio cell to avoid intersection testing.
2

Share this post


Link to post
Share on other sites
all of the suggestions above are slow, or wrong
poisson-disc is one array lookup and possibly an &
google it, im sure it works in 3d as well, and it does (EDIT): http://devmag.org.za/2009/05/03/poisson-disk-sampling/ Edited by Kaptein
1

Share this post


Link to post
Share on other sites
[quote]Some thoughts about my terrain generation (large objects). I subdivide the area into cells (+ some spacing between cells). Each cell can contain one randomly placed object, the spacing between the objects guarantees, that you don't get overlapping objects. This is similiar to the AABB approach. Even better would be a voronio cell generation which will break up patterns more. You can place your objects randomly within the boundaries of a voronio cell to avoid intersection testing.[/quote]

I like this idea, and it can be made very simple and fast.

Suppose the minimum distance you want is 'd': No two object closer than 'd' points from each other. Store created objects on a sparse grid discritized at intervals of 'd.' A hashtable can handle the sparse grid at both storage and time O(n), where n is number of objects.

[CODE]
ht = new HashTable(); //key for the hashtable is a triplet of integer coordinates , value is the object stored

for (a=0; a< numobjects; a++)
{
bool reject = true;

while (reject == true)
{

vec3 objectpos = random_position_in_3d();

//quantize down to a discreet grid coordinates, which are just increments of 'd'
int x = objectpos.x/d;
int y = objectpos.y/d;
int z = objectpos.z/d;

reject = false;
// now check this spot in the grid, and all the immediate neighbors
for (i=-1;i<=1;i++)
{
for (j=0;j<=1;j++)
{
for (k=0;k<=k;k++)
{
if ( obj2 = ht.get( new int_triplet(x+i, y+j, z+k ) ) //if there's on object here, it may be within 'd' of the new object
{
if (distance (objectpos , obj2.pos) < d)
reject = true;
}
}
}
}
} //loop back and pick a new position if we rejected
//this should be a rare occurance, unless the RNG is bad, OR you are putting in so many objects the grid is filling up

someobject obj = new someobject( objectpos, "some star");

ht.put(new int_triplet(x,y,z) , obj);

}


[/CODE]

Note the above will only work well if the space is very sparse, and you want random points with a respected minimum distance. If you want something more uniformly spaced, use the poisson-disc mentioned above.

edit: adjust the code a bit
edit: give up getting the braces to line up; they really do look straight in the editor! Edited by DracoLacertae
1

Share this post


Link to post
Share on other sites
Ok the poisson-disc method sounds interesting... Anyone know of a lib that has a built in generator for this? Or examples? I really don't want to code this up when it should be a standard lib tool by now.... C++11 have something for this? And I would like to have negative values if possible? Reason is my Sun sits at 0,0,0 and looking down in a standard math grid left is negative and right positive ect... I want to position them with e.g. -1024, -1024 or 1024,1024

And from what I seen so far if I have a lamda value of say 1000 the numbers all return around 1000.... So how can I do position e.g. 20 objects around a 2048,2048 grid so they all don't sit around 1000?

Thanks! Edited by MARS_999
0

Share this post


Link to post
Share on other sites
DracoLacertae

Ok I think I have something in theory that works, but need to check it out later tonight. I will post back once I verify the code is working.

Thanks!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0