Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: QuadTree is adding objects to only one children  (Read 2670 times)

0 Members and 1 Guest are viewing this topic.

StDH

  • Jr. Member
  • **
  • Posts: 56
  • {⛺.⛺}
    • View Profile
    • Worst ever ^^
QuadTree is adding objects to only one children
« on: May 10, 2014, 12:15:40 pm »
Initialize it with max_level 1 to have only 4 childrens.
its adding objects to only one children : SouthEast.
I have no idea why.
« Last Edit: May 11, 2014, 09:14:17 am by SDH »
<StDH> Imagine a girl writing you this: My farts smell good
<Slipxy> married.

F2CPP

  • Newbie
  • *
  • Posts: 14
    • View Profile
    • StackOverflow
Re: QuadTree is adding objects to only one children
« Reply #1 on: May 10, 2014, 05:08:13 pm »
as a first step, have you looked at outcome of the position comparisons inside void game::QuadTree::insert(sf::Sprite *other)?

if the position x and y of 'other' is larger than x and y (in that order) of the existing values (from constructor or init()) it would simply end up at SE -> insert(other); i.e. SouthEast as you say

StDH

  • Jr. Member
  • **
  • Posts: 56
  • {⛺.⛺}
    • View Profile
    • Worst ever ^^
Re: QuadTree is adding objects to only one children
« Reply #2 on: May 10, 2014, 05:23:19 pm »
can you show me repaired code ?
<StDH> Imagine a girl writing you this: My farts smell good
<Slipxy> married.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: QuadTree is adding objects to only one children
« Reply #3 on: May 10, 2014, 05:34:10 pm »
Please show some self-initiative. We like to help by giving advice, but it's not our job to debug and fix your code. Especially since this is not a SFML-related problem.

Have you already used a debugger?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

StDH

  • Jr. Member
  • **
  • Posts: 56
  • {⛺.⛺}
    • View Profile
    • Worst ever ^^
Re: QuadTree is adding objects to only one children
« Reply #4 on: May 10, 2014, 05:38:25 pm »
i tried editing code but doesnt work.
<StDH> Imagine a girl writing you this: My farts smell good
<Slipxy> married.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: QuadTree is adding objects to only one children
« Reply #5 on: May 10, 2014, 05:41:39 pm »
Then try further... ::)

Or at least adhere to the forum rules.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

StDH

  • Jr. Member
  • **
  • Posts: 56
  • {⛺.⛺}
    • View Profile
    • Worst ever ^^
Re: QuadTree is adding objects to only one children
« Reply #6 on: May 10, 2014, 05:50:54 pm »
well, i have been trying to solve this whole day so ......
<StDH> Imagine a girl writing you this: My farts smell good
<Slipxy> married.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: QuadTree is adding objects to only one children
« Reply #7 on: May 10, 2014, 06:32:56 pm »
well, i have been trying to solve this whole day so ......
Then you definitely need to work on your bug fixing skills. I assume you haven't used a systematic approach. I suggest you take a debugger, step through the program, compare variable's actual values with your expectations and find out where and why there are differences. If necessary, split the code into smaller parts that you can test on their own and exclude functionality that does not contribute to the error. This way, you can quickly localize where the problem is.

I'm saying this because I think such advice is of much greater value for you than simply saying "in this line there is the error", and next time you have a similar problem, you waste another day.

Also, some general tips that make your code shorter, easier to understand and thus less error-prone: Use std::unique_ptr instead of raw new/delete. You have code duplication (3 methods to insert, get object and count have very similar structure), you should extract a function that returns the correct object depending on the position:
QuadTree& getChildAtPosition(sf::Vector2f position);
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

StDH

  • Jr. Member
  • **
  • Posts: 56
  • {⛺.⛺}
    • View Profile
    • Worst ever ^^
Re: QuadTree is adding objects to only one children
« Reply #8 on: May 10, 2014, 08:50:21 pm »
i solved problem without debugging  :) :D ;D
<StDH> Imagine a girl writing you this: My farts smell good
<Slipxy> married.