1
General / Re: Collision Detection Run-time bug (Following along with the SFML BOOK)
« on: August 26, 2013, 12:26:09 pm »
EDIT 2: I found the bug which was little like I knew it would be since all the most painful bugs for me seem to be little mistakes. The problem was in checkSceneCollision() I was calling child->checkNodeCollision() on every child instead of child->checkSceneCollision().
Thanks for the help (It always helps me to explain the problem in detail to someone else to help myself wrap my head around what is going wrong. I really should by myself a little rubber ducky ;p) and again very great book was worth every penny.
I believe most of the code except a few name changes is the same from the book and the downloadable source code. Though more then likely I might have missed a key concept.
Thank you for this suggestion. I took your advice and it seems the reason why collision() always is returning false is because rhs.getBoundingRect() is always returning a 0, 0, 0, 0 rectangle... It seems rhs never holds a bounding rect that is not 0. It seems as though lhs always holds the bounding rects for the objects in the game and never rhs.
Going to try to research this a bit further in the code. Thank you for the help. Would also like to thank you for writing the SFML book ;p Probably one of the best Game Development books I have ever read and has taught me a lot of neat concepts I never knew about.\
EDIT: So I looked into it a bit more before work and I believe I found out what is happening (Correct me if I am wrong). I believe it is only checking the against the parent nodes and their children (Which would explain why rhs.getBoundingRect() always returns a 0,0,0,0 rectangle because it is a just a parent node which holds that group of on screen entities).
So for example I have a scene graph which looks like this
Root
|
/ \
/ \
Background Air
/\
/ \
/ \
player enemies
/ \
player enemy
bullets bullets
So Root has the children background (Background sprite) and Air(Which is just a normal scene node which will hold all the entities that in the Air). Background has no children. Air has has a bunch of children (The player and all the enemies on the screen). Player has children when he is firing projectiles and enemies have children when they are firing projectiles.
So if it is only checking children to parent for collision it would never check for player to enemy collision or player bullet to enemy collision and so on. Which is why no collisions are registering I believe.
I think the collision checks are looking like this
Root - Root = No collision
Background - Root = No collision
Air - Root = No Collision
Player - Air = No collision
Enemy1 - Air = No collision
Enemy2 - Air = No collision
...
...
That is just what I think is happen though I could be wrong since this is a weak spot of mine in programming.
Also this is how checkSceneCollision() is called inside world.
sceneGraph is the root node for the scene graph and is of type SceneNode and collisionPairs is a set of pointers of SceneNodes.
Now I am even more confused about what the problem is and how to fix it ;p Looks like I will be researching this for awhile .
Thanks for the help (It always helps me to explain the problem in detail to someone else to help myself wrap my head around what is going wrong. I really should by myself a little rubber ducky ;p) and again very great book was worth every penny.
Quote
Since the code originates from the SFML book, can you clarify where it differs? As collision works in the book, these are the places where you can start searching for the bug.
I believe most of the code except a few name changes is the same from the book and the downloadable source code. Though more then likely I might have missed a key concept.
Quote
You say collision() always returns false -- check the values of the involved rectangles (either using standard output or the debugger).
Thank you for this suggestion. I took your advice and it seems the reason why collision() always is returning false is because rhs.getBoundingRect() is always returning a 0, 0, 0, 0 rectangle... It seems rhs never holds a bounding rect that is not 0. It seems as though lhs always holds the bounding rects for the objects in the game and never rhs.
Going to try to research this a bit further in the code. Thank you for the help. Would also like to thank you for writing the SFML book ;p Probably one of the best Game Development books I have ever read and has taught me a lot of neat concepts I never knew about.\
EDIT: So I looked into it a bit more before work and I believe I found out what is happening (Correct me if I am wrong). I believe it is only checking the against the parent nodes and their children (Which would explain why rhs.getBoundingRect() always returns a 0,0,0,0 rectangle because it is a just a parent node which holds that group of on screen entities).
So for example I have a scene graph which looks like this
Root
|
/ \
/ \
Background Air
/\
/ \
/ \
player enemies
/ \
player enemy
bullets bullets
So Root has the children background (Background sprite) and Air(Which is just a normal scene node which will hold all the entities that in the Air). Background has no children. Air has has a bunch of children (The player and all the enemies on the screen). Player has children when he is firing projectiles and enemies have children when they are firing projectiles.
So if it is only checking children to parent for collision it would never check for player to enemy collision or player bullet to enemy collision and so on. Which is why no collisions are registering I believe.
I think the collision checks are looking like this
Root - Root = No collision
Background - Root = No collision
Air - Root = No Collision
Player - Air = No collision
Enemy1 - Air = No collision
Enemy2 - Air = No collision
...
...
That is just what I think is happen though I could be wrong since this is a weak spot of mine in programming.
Also this is how checkSceneCollision() is called inside world.
sceneGraph.checkSceneCollision(sceneGraph, collisionPairs);
sceneGraph is the root node for the scene graph and is of type SceneNode and collisionPairs is a set of pointers of SceneNodes.
Now I am even more confused about what the problem is and how to fix it ;p Looks like I will be researching this for awhile .