Re: [pygame] Help: improve new module documentation. Read this, and give me comments.
An alternate to this, might be to keep an array of the distance to the first pixel from each for, top, right, bottom, left e.g. the top one is an array of the y distance to the first pixel; this would be checked against the other objects corresponding top and bottom arrays; probably a whole lot cheaper than checking every pixel against every other pixel. (it's late so I've probably written this down without making it make sense) On 22/01/2008, FT <[EMAIL PROTECTED]> wrote: > Hi! > > A thought, I am sure you probably have tried it. But you mention the > vector, and you know the direction, thus you can reduce the field of > mask/test then check less pixels in the upcoming collision point(s). Just a > thought, just requires that vector and how to write that vector. Knowing the > image at start and it's direction, then only looking at that point and the > look-ahead pixels of that point/area. > > Only a thought, yet have not read /looked at any code to know what you > guys have done. > > Bruce > > > Yeah I have generated my own masks in pure python for per pixel or > special effects, and it is super slow. I have to precalculate all the > masks or there is nothing doing. This module sounds great! > > The only point of confusion is the point of intersection. Very rarely > is only one point intersecting. Which point exactly is the > intersecting point? With rects you could say its the corner, or you > could have a vector that determines how far out to move it, based on > the center of the rect, so it's not intersecting etc, but with a mask > there is no "corner", and likely not a "center" either. > > On Jan 22, 2008 1:55 PM, Ian Mallett <[EMAIL PROTECTED]> wrote: > > Sorry, don't have time to give a good answer about the documentation, > > but a pixel perfect collision detector is great! The one I wrote for > > a game a while ago works, but is not to portable... > > I > > > >
Re: [pygame] Help: improve new module documentation. Read this, and give me comments.
Hi! A thought, I am sure you probably have tried it. But you mention the vector, and you know the direction, thus you can reduce the field of mask/test then check less pixels in the upcoming collision point(s). Just a thought, just requires that vector and how to write that vector. Knowing the image at start and it's direction, then only looking at that point and the look-ahead pixels of that point/area. Only a thought, yet have not read /looked at any code to know what you guys have done. Bruce Yeah I have generated my own masks in pure python for per pixel or special effects, and it is super slow. I have to precalculate all the masks or there is nothing doing. This module sounds great! The only point of confusion is the point of intersection. Very rarely is only one point intersecting. Which point exactly is the intersecting point? With rects you could say its the corner, or you could have a vector that determines how far out to move it, based on the center of the rect, so it's not intersecting etc, but with a mask there is no "corner", and likely not a "center" either. On Jan 22, 2008 1:55 PM, Ian Mallett <[EMAIL PROTECTED]> wrote: > Sorry, don't have time to give a good answer about the documentation, > but a pixel perfect collision detector is great! The one I wrote for > a game a while ago works, but is not to portable... > I >
Re: [pygame] Help: improve new module documentation. Read this, and give me comments.
Yeah I have generated my own masks in pure python for per pixel or special effects, and it is super slow. I have to precalculate all the masks or there is nothing doing. This module sounds great! The only point of confusion is the point of intersection. Very rarely is only one point intersecting. Which point exactly is the intersecting point? With rects you could say its the corner, or you could have a vector that determines how far out to move it, based on the center of the rect, so it's not intersecting etc, but with a mask there is no "corner", and likely not a "center" either. On Jan 22, 2008 1:55 PM, Ian Mallett <[EMAIL PROTECTED]> wrote: > Sorry, don't have time to give a good answer about the documentation, > but a pixel perfect collision detector is great! The one I wrote for > a game a while ago works, but is not to portable... > I >
Re: [pygame] Help: improve new module documentation. Read this, and give me comments.
Sorry, don't have time to give a good answer about the documentation, but a pixel perfect collision detector is great! The one I wrote for a game a while ago works, but is not to portable... I
[pygame] Help: improve new module documentation. Read this, and give me comments.
Hello, There is a new module going into pygame called mask - for per pixel collision detection and 1 bit per pixel representation of Surfaces. However the documentation could do with some more work. So comments please? Here it is, at this link: http://rene.f0o.com/~rene/stuff/mask.txt Or I've pasted the docs it below. Cheers! pygame.mask pygame module for image masks. Useful for fast pixel perfect collision detection. A Mask uses 1bit per pixel to store which parts collide. New in pygame 1.8. pygame.mask.from_surface Returns a Mask from the given surface. pygame.mask.from_surface(Surface, threshold = 127) -> Mask Makes the transparent parts of the Surface not set, and the opaque parts set. The alpha of each pixel is checked to see if it is greater than the given threshold. If the Surface is color keyed, then threshold is not used. pygame.Mask pygame object for representing 2d bitmasks pygame.Mask((width, height): return Mask get_size Returns the size of the mask. Mask.get_size() -> width,height get_at Returns nonzero if the bit at (x,y) is set. Mask.get_at((x,y)) -> int Coordinates start at (0,0) is top left - just like Surfaces. set_at Sets the position in the mask given by x and y. Mask.set_at((x,y),value) overlap Returns the point of intersection if the masks overlap with the given offset - or None if it does not overlap. Mask.overlap(othermask, offset) -> x,y The overlap tests uses the following offsets (which may be negative): ++--.. |A | yoffset | +-+--.. +--|B |xoffset | | : : overlap_area Returns the number of overlapping 'pixels'. Mask.overlap_area(othermask, offset) -> numpixels You can see how many pixels overlap with the other mask given. This can be used to see in which direction things collide, or to see how much the two masks collide. get_bounding_rects Returns a list of bounding rects of regions of set pixels. Mask.get_bounding_rects() -> Rects This gets a bounding rect of connected regions of set pixels. A bounding rect is one for which each of the connected pixels is inside the rect.