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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - bebewr

Pages: [1]
1
General / Re: The right way to detect collisions of many objects
« on: June 08, 2016, 04:45:58 pm »
What you need is space partitioning, for example a quad-tree.

Thanks for feedback, this is what I needed

Does your game have 500 bullets at once? And did you actually notice performance issues?

I'm trying to write a primitive engine for future projects, so I've been testing different amounts of objects. I couldn't see the perfomance issues by my eyes, but keeping in mind, that the final program would be much bigger,  the time needed to process one frame was just too big.

2
General / The right way to detect collisions of many objects
« on: June 08, 2016, 02:11:26 pm »
Hello guys, the answer to my question might be obvious to you, but i have some doubts about the right way I should detect collisions in my program.
So far, I've created three classes: Player, Projectile and Mob.
I move Player object and shoot with Projectile objects,putting them into std::vector projectilesvector. Mobs spawn randomly and they are saved in std::vector mobsvector. In every game loop I check all Projectiles object's and Mob's objects, if they intersect:

for( int i = 0; i < projectilesvector.size(); i++ )
{
        for( int j = 0; j < mobsvector.size(); j++ )
       {
        //   if ( projectilesvector[i] intersects mobsvector[j] ) collision detected
       }
}
 

For example, with 500 projectiles and 100 mobs I have to make it through 50000 loops, which takes substantial amount of time.
I wonder if there is a faster way to check collisions, without nested loops.

Pages: [1]
anything