4
\$\begingroup\$

Example Image

I'm no coder, nor do I try to be. I just had one of those "it's impossible" arguments with folks who love to argue with me before they even understand what the argument is about :)

So I need to know how doable it is and the level of complexity on scales of: Noob LVL to Mediocre to Never-got-laid mad coding skills.

Normally the way people do this is by scaling. But I don't need to preserve the position ratios between objects. What I want to do is = IF the view-port cannot fit all results BUT has space to fit them - juts get them in there (position ratios be damned).

Basically the way I want to do it is the way you would do it in a crowded bar table. Just cram it in. Obviously the other objects move if they are in the way - but if there is space - they fit. (for instance the top orange star has moved down because the blue star was crammed in from outside the view port.

What I'm looking for is an overview explanation about how someone would go about such a thing and how hard it is. I'm pretty sure there is math for that sort of thing - but it's not really an area where i shine... So you don't really need to get into complexities.

Q? Why don't I care about accurate position ratios and directions?

A: Objects in the view port are intractable on click. Representing them displaced from their true positioning is irrelevant so long as you get to interact with them via their functionalities.

\$\endgroup\$
10
  • \$\begingroup\$ You could clamp the x/y positions of the blue stars to the bounding box of the viewport. Moving the orange stars out of the way would take a bit more work but should be easy enough depending on how the star locations are managed. \$\endgroup\$ Jun 2, 2015 at 14:17
  • \$\begingroup\$ This doesn't seem to be gamedev specific -- perhaps try SO or ux.SE? \$\endgroup\$
    – Thomas
    Jun 2, 2015 at 15:10
  • \$\begingroup\$ @Skrundz -It's a clean slate now. We have their ACTUAL positions (x,y for each). We begin with a scaled representation of where they are. Hence depending what you are looking for - some can be found outside of the view port. From that point I want to begging cramming :) Can you elaborate a a little bit about pushing the orange ones out of the way (in terms of some methods). \$\endgroup\$
    – helena4
    Jun 2, 2015 at 15:28
  • 2
    \$\begingroup\$ @AlanWolfe you scale at first. But - You have 5 results right next to each other (x1,y1 x1,y2 x1,y3 etc) and one result at the other end of the map (x3000,y3000), you are at x700,y925 (your origin-starting view port). Don't break scale and show me all of them in a 800x600 presentation that represents a space that can fit 3000 objects vertically and 3000 horizontally - AND maintain each of them a 4x4 pix size - so you can still click each individually - with a minimal separation between each object of 2pix -so they don't all merge into a one seemless blob. You surely can fit 7 objects ...? \$\endgroup\$
    – helena4
    Jun 2, 2015 at 16:16
  • 1
    \$\begingroup\$ @davidvanbrink - sort of - they didn't ask or get answered on how to solve the overlap problem that arises when you try to do that sort of thing. Just getting the stuff in - is pretty simple - you just add/subtract from the x and y until they fall within desired range. Things get more interesting around collision - as you need more rules to resolve all the cases. \$\endgroup\$
    – helena4
    Jun 3, 2015 at 7:45

1 Answer 1

2
\$\begingroup\$

There is of course several ways to do this, and the solutions are very much gamedev related.

One perspective on a solution comes from game physics. Basically you'd start by clamping all data to the rectangular window, letting the data overlap.

Next, you treat each star as having a minimum distance constraint from every other star, so you'd loop through all stars and if a star was too close to any other star you'd either push the star away, or have the two stars push away from each other a small amount.

You'd also want to enforce a constraint that the stars stay on the inside of the walls, and keep a minimum distance, to make sure they stayed in the box.

After one loop of this you may still have overlaps, so you'd repeat the process either until all constraints are met, or until you reached some number of maximum iterations since its possible you could have more stars than you have area for - or that a solution would take too long to converge to.

For highest quality results, you'd move the stars only a very small amount per loop, and you'd have a high maximum loop count. For fast results on the other hand, you'd move them larger amounts and have a lower maximum loop count.

This is 2d physics collision / response at its simplest (:

There is probably a non iterative way to solve this from the physics perspective, but it likely requires inverting a gigantic matrix.

Some other areas of game dev that might have other techniques for you include path finding, flocking behaviors and path planning. Its a common problem in pathing to try to get things from one place to another without overlapping since that means pathing entities get caught in doors etc. You might find some interesting algorithms if you look in that direction.

\$\endgroup\$
4
  • \$\begingroup\$ Yeah well I just couldn't recall an accurate example of where its been done before. -So you think its better to clutter it up all together and then apply rules to it, instead of try to collect distant points then shove them in a desired area? ... At any rate I think this is good enough for me - considering most designers ignore these problems and let you hunt for objects in multiple view ports that rarely have results. (rest assured my game would not have you drag the screen like an idiot for no reason :) \$\endgroup\$
    – helena4
    Jun 2, 2015 at 16:27
  • \$\begingroup\$ Yeah I think clamping then resolving conflicts is the way to go. Going this route, it brings in things that are too far, but it won't disturb things already in the view port if it doesn't need to, which sounds like exactly what you are trying to go for. \$\endgroup\$
    – Alan Wolfe
    Jun 2, 2015 at 16:30
  • \$\begingroup\$ Design perspective has never been the problem :) I'm the designer. Getting these obscure ideas over to coders is the tricky part, especially if they are used to just scaling and don't want to bother listening to alternative views at the moment. With your help I'm better prepared to have this talk tech wise. \$\endgroup\$
    – helena4
    Jun 2, 2015 at 16:35
  • \$\begingroup\$ Awesome! I'm sure you can appeal to one of the programmers to get to write some 2d collision detection/resolution. It sounds like a fun feature to make :p. Good luck! \$\endgroup\$
    – Alan Wolfe
    Jun 2, 2015 at 16:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .