problem with fast image

Blitz3D Forums/Blitz3D Programming/problem with fast image

vivaigiochi(Posted 2012) [#1]
When load one or two image with loadimageex i can't use command like imagecollide, blit's say image don't exists. How can solve?
I use some tyoe for contain the image and so

Local image1%=tmpblock\imgoff ;first image loaded with loadimageex
Local image2%=blk\imgoff ; second image
;Stop
If ImagesCollide (image1,tmpblock\x,tmpblock\y,tmpblock animvalue,image2,blk\x,blk\y,0)=0
blk\y=blk\y+1
EndIf


Yasha(Posted 2012) [#2]
blit's say image don't exists


That's because it doesn't - FastImage loads images into a completely different drawing engine from the regular Blitz3D LoadImage, so the resulting handle doesn't point to a legitimate Blitz3D image object.

If you're not using rotation, you should be able to simply use RectsOverlap with the X and Y values of the images, and their widths and heights multiplied by the scale (if you're using scale). If you're using rotation as well, then it gets a little more complicated... and if you want pixel-perfect collision, it gets really complicated indeed and won't be easy at all.

Your best bet is to not use images for collision, but instead to work out some simplified method involving underlying shapes that are simplified versions of what the images represent, and use a purely mathematical collision system based on those. But it depends what you want to do.


vivaigiochi(Posted 2012) [#3]
i need image collision because they are the image that i use..really i want pixel perfect collision, i have noted that fastlib use a different format and i ask to the author the same question, but it's really strange because fastlib extend the use of this image...or at this time i think it limited because i can't use blit'z command..it's absurd.


pc_tek(Posted 2012) [#4]
I believe that the equivalent to 'ImagesCollide' using the FastImage library is 'TestImage'.


vivaigiochi(Posted 2012) [#5]
No! it's test only if a point is inside an image...it's not the same of imagecollide. No i wil try to overlay the image with a collision system..


Guy Fawkes(Posted 2012) [#6]
Does this have a pixel perfect collision system?


vivaigiochi(Posted 2012) [#7]
NO pixel perfect collision system provided. fast image estends only the capabilitis of blitz related visualization of image... i need a pixel perfect collision system, i try to overlay with npoly but it isn't pixel perfect...


Yasha(Posted 2012) [#8]
I have only one idea to suggest that would work with scale and rotation (if you're not using both of these at once, you can simplify the technique):

1) SetColor 255, 0, 0
2) Draw the first shape (on an empty buffer - do this before the drawing step in your frame)
3) SetColor 0, 255, 0
4) Draw the second shape correctly scaled, rotated and positioned relative to the first, on the same nearly-empty buffer
5) Do some fast-check for yellow pixels
6) Cls before the next collision check, or drawing the frame

To check for yellow pixels, you could (this may not be the fastest way) calculate the screen-aligned bounding rect for the area where the two images overlap (I couldn't tell you the maths for this offhand, but it's not that hard), and do a simple For x/For y/ReadPixelFast within this space.

This would be too slow to use for hundreds of objects all colliding with each other (in fact, it would probably be too slow to use for more than two objects), so you would definitely want to combine it with a simpler method - even something as simple as a radius check - to filter out the obvious non-collisions first. I would still suggest that you consider alternatives to pixel-perfect options (e.g. something involving 2D hulls, perhaps?).

Last edited 2012


vivaigiochi(Posted 2012) [#9]
solved i overlay with a collision system modified to fit my needs.
But i wait an answer from the autor of fastlibs...he will say sure that the lib's exists only for fast visualization of image..it's right...