[SDL] Fast Way To Check If Certain Pixel is Inside Certain Surface

Vassilis Virvilis vasvir at iit.demokritos.gr
Tue Jul 4 04:54:04 PDT 2006


Phantom Lord wrote:
> Hi, i'm working on a particle engine (pixel-based, for now) and i'd
> implement the following code for checking if the pixel is inside that
> Certain Surface:
> 
> for(int i=surface->clip_rect.x; i<surface->clip_rect.w; i++)
>   for(int j=surface->clip_rect.y; j<surface->clip_rect.h; j++)
>      if(particle.x == i && particle.y == j) do something.
> 

if ((particle.x >= surface->clip_rect.x) &&
     (particle.x < surface->clip_rect.x + surface->clip_rect.w) &&
     (particle.y >= surface->clip_rect.y) &&
     (particle.y < surface->clip_rect.y + surface->clip_rect.h)) {
     do_something();
}

      .bill




More information about the SDL mailing list