Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (726)
Games in Android Showcase (216)
games submitted by our members
Games in WIP (796)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Image Collision Detection Recommendations  (Read 1240 times)
0 Members and 1 Guest are viewing this topic.
Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Posted 2016-12-15 11:37:22 »

I currently have a working implementation of image collision detection for .pngs with alpha and making sure their non-alpha pixels collide. It is very slow however.

This is the example I originally learned from. I've got various versions of this for my code. Partial collision and 100% collision. 100% collision takes longer as it requires going though every pixel to ensure total collision.

This is done at loading a new game. Detecting collision between 1000ish+ images ranging from 10x10-300x300 takes upwards of 40 seconds. If I turn off collision, the load time drops to a few seconds.

Can anyone suggest a faster way to detect collision between images contents? Or is this actually a decent speed? I'd expect we can do better.
Offline SteveSmith
« Reply #1 - Posted 2016-12-15 13:09:06 »

As a very general idea which may not apply here, could you do something like:-

1. Take a blank image/byte array thingie that's big enough to hold both images at their relative positions
2. Copy the pixel bits of the first image into a new array grid, making transparent pixels as zero and and anything else is collideable.
3. AND (as in not OR/XOR etc..) the bits of the second image into the same grid.
4. See if any of the bits in the new array are != 0.

Just a thought really.  I don't how fast doing the above would be, but I'm hoping there are functions that can handle whole areas of a byte array without having to do each pixel manually.

Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #2 - Posted 2016-12-15 15:08:53 »

Yea, if the functions you mention at the end exist, that seems like a viable strategy. If those functions don't exist, it seems like the load would be the same since we have to deal with each pixel then.

I think OpenGL might have something I could use (some form of buffer object), but that would come again to why I am here. I'm looking myself, but if someone knows of a way to do this with OpenGL, I'd greatly appreciate such guidance.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tariqbroadnax

Junior Devvie


Medals: 1
Exp: 3 years



« Reply #3 - Posted 2016-12-16 16:27:35 »

I am assuming that each your images have a location. Try partitioning your space into sections and only do collision to entities within the same sections. Use the bound of image to determine which sections to play entities in.


Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #4 - Posted 2016-12-16 17:14:00 »

I am assuming that each your images have a location. Try partitioning your space into sections and only do collision to entities within the same sections. Use the bound of image to determine which sections to play entities in.
The present method operates in stages. 1) Test the bounds of the two image rectangles in coordinate space. If passes, 2) scan through each relevant pixel of the relevant pixel subsets. If no conditions are violated, return happy.

No irrelevant pixels are tested presently. Some sort of operation like what SteveSmith said is all I can think would work here. I don't have that sorted yet tho.
Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #5 - Posted 2016-12-19 12:29:46 »

FWIW, I ended up using multithreading on the chunks of image collision tests. This made the time acceptable.  Cool
Offline princec

« JGO Spiffy Duke »


Medals: 904
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2016-12-19 15:24:25 »

I bet there's a way to do this on a GPU super-fast Smiley

Cas Smiley

Offline CommanderKeith
« Reply #7 - Posted 2016-12-20 00:38:16 »

One method that might be more efficient if your images don't change, they're just rotated and translated, is to make a polygon out of the image outline. Maybe make lines between border pixels. I think that there are libraries that do this, but I can't remember their name. JTS can then simplify the polygon by turning Collinear points into one straight line, then just do an intersection test of these lines in the polygon against other polygons' lines.

Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #8 - Posted 2016-12-20 06:09:19 »

The polygons idea sounds very good. Probably the kind of answer I should be doing. These are all static images. If I had something to make these into polys, I could keep those poly files or that information and just use that.

I'm looking into it, but if you have or remember any further information, it's well appreciated.


Edit - I haven't gotten to look into this fully, but this looks cool.
Offline CommanderKeith
« Reply #9 - Posted 2016-12-20 10:50:25 »

Here are some good alternatives:
http://stackoverflow.com/questions/1861382/convert-png-to-svg

Back when I tried to do this only Potrace seemed decent:
http://potrace.sourceforge.net/

But these days even Inkscape has an option to do vectorising of bitmaps.

This java library looks promising, but I haven't tried it:
https://github.com/jankovicsandras/imagetracerjava7


Pages: [1]
  ignore  |  Print  
 
 

 
Archive (284 views)
2017-04-27 17:45:51

buddyBro (474 views)
2017-04-05 03:38:00

CopyableCougar4 (923 views)
2017-03-24 15:39:42

theagentd (935 views)
2017-03-24 15:32:08

Rule (948 views)
2017-03-19 12:43:22

Rule (916 views)
2017-03-19 12:42:17

Rule (918 views)
2017-03-19 12:36:21

theagentd (965 views)
2017-03-16 05:07:07

theagentd (891 views)
2017-03-15 22:37:06

theagentd (687 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!