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

Author Topic: pixels collision detection is too slow  (Read 2828 times)

0 Members and 1 Guest are viewing this topic.

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
pixels collision detection is too slow
« on: February 06, 2017, 02:25:11 am »
hi every one ;
I want to detect collision by pixels not by rectangles
I know how to do it, but in the end I find my self comparing every point of 463 points with 469 point
when I did this the shape become too slow in moving
is this because pixels collision detection or there is just another reason and if its how can I make is efficient
(it did work put toooooooooo slow )

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: pixels collision detection is too slow
« Reply #1 on: February 06, 2017, 02:48:51 am »
Who knows, without code any statement can be true or false... ::)

Maybe your collision detection code is just implemented inefficiently.
Maybe your collision "domain" is just too large for full on pixel collision.

In the end a pixel perfect collision is pretty much never required. Usually some sort of bounding checking is all you really need. And in the cases where you really do want pixel perfect collisions, you can narrow down the collision area by using some quad tree or similar.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

K.F

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: pixels collision detection is too slow
« Reply #2 on: February 06, 2017, 04:04:15 am »

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: pixels collision detection is too slow
« Reply #3 on: February 06, 2017, 08:52:33 pm »
the criminal was vector
for(;;)
{   {  for(int q=0;q<300;q++)
          for(int w=0;w<300;w++)
          {if(see[0].x==see[0].y);{*qw=2;see[0].x=see[0].x;see[0].y=see[0].y;see[0].x=see[0].y;}
          }
    }
cout<<"I did one\n";
if(GetAsyncKeyState(VK_ESCAPE))
break;
}
 
this is is not the collision code(its just some stupid operations on vector )
but it looks like it
when I just wrote two nested for loops  300*300
it was fast but when I put vector it becomes slow
is this because accessing the heap require more time or what and what is the replacement of vector

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: pixels collision detection is too slow
« Reply #4 on: February 06, 2017, 08:57:09 pm »
Are you in debug mode?
Laurent Gomila - SFML developer

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: pixels collision detection is too slow
« Reply #5 on: February 06, 2017, 09:32:46 pm »
cant understand you

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: pixels collision detection is too slow
« Reply #6 on: February 07, 2017, 05:57:11 am »
I really couldn't understand the difference between them (debug and release mods) ::)
but after putting it in release mode it become very fast from 1.5 second per update to 0.007 seconds  8)

but I have changed the way of pixels collision detection to boolean variables
every pixel have a boolean variable that associated with it.   it is set to false when there is already something in it
true if nothing drawing it self in it and every time I want to move I check if the pixels that I am going to have all
a true value(nothing drawing it self)

and the results was mush mush better

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: pixels collision detection is too slow
« Reply #7 on: February 07, 2017, 03:33:53 pm »
One way to think about it is that in Debug mode, if the program stops somewhere (breakpoint or crash), you can investigate the current state of variables et cetera and you are likely to be given information about the crash but all this can slow down performance whereas in Release mode, everything is optimised to run as quickly/efficiently as possible but with little to no feedback on errors - even major errors such as accessing inappropriate memory may not be even be noticed.

If you are storing many booleans, you may want to consider using an std::vector:
std::vector<bool> pixelFlags;
It is specialised to store eight per byte, which can seriously reduce the storage space needed for larger amounts of pixels.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything