Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  quadtrees and moving objects  (Read 1289 times)
0 Members and 1 Guest are viewing this topic.
Offline thalador

Senior Newbie





« Posted 2007-05-10 14:27:09 »

Hi,

I need a pointer on the whole quadtree thing.. Imagine there is a 2d space shooter game consisting of a lot of asteroids, ships, baseships and so on. The whole "world" is at least, say 100 x 100 Screens big, the user can fly around as he likes. My first thought was to divide the space with a quadtree to optimize the amount of draw calls. In every node would be a couple of game objects. Due to the nature of space shooter the objects move. If one object leaves a node I just have to delete it from the old and move it to a new one and so on. Thats not the problem. But what happens if I got a big baseship or something similiar that moves from one node to another ( see attachment)

There is a point in time, when I have to move the object from one node to another. At first glance I would say that is when the center of the object is now in the new node. But if I move the ship in that moment, it is clipped from screen but it should be seen a bit longer.

So my question is: How do you handle this, and is a quadtree the right tool for moving objects?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2007-05-10 15:07:00 »

Put the item that overlaps nodes, in the 'parent' node (recursively, until it fits in 1 node) - then not only leafs have objects stored.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #2 - Posted 2007-05-12 12:52:00 »

Sounds like a problem for scenegraphy engine.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Member





« Reply #3 - Posted 2007-05-12 15:00:47 »

Just check every node that's adjacent to the screen for sprites in them that need to be drawn.

Even if you used the top-left corner (or whatever) instead of the center of the sprite for determining which node the sprite is in, you would still have the same problem in some cases.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2007-05-12 15:03:48 »

If the item overlaps X nodes, you'd have to render a LOT of nodes outside the screen. To prevent that, use my previously posted solution.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline thalador

Senior Newbie





« Reply #5 - Posted 2007-05-12 15:22:06 »

Thanks for your comments.
I will try to implement the method Riven suggested.

Recently I thought about another tree to implement a scenegraph: R Tree The wiki entry is not so good, so if you want to know more read this paper.
This tree is made to handle spatial data in multiple dimensions.. in this case it's only 2 dimensional and would hold rectangles. The nodes itself can overlap and their boundaries can grow, if you add new items to a node. The tree supports searching in areas for example questions like: which nodes are inside this arbitrary rectangle. If a nodes covered area gets to big, it's splitted up in smaller nodes similiar to quadtrees.
Advantages: moving objects just cause a node to grow, the don't leave the node -> this means you have to check the size from time to time, if it's to big -> split nodes
Disadvantages: I guess collision detection doesn't work so well, or is harder to implement

I didn't test this kind of tree yet, I just had spend a couple of moments to think about it.. what do you guys think?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!