Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Convert image to a number of squares?

  1. #11

    Re: Convert image to a number of squares?

    Haven't had much time for programming the last two days, but I've managed to throw this together so far:

    The sprite:


    With 4x4 pixels boxes (can be set to any size):


    You can click on boxes to remove them in order to "fine tune" the result. Now I just need to join the boxes into larger boxes. I believe a pretty simple algorithm can do this. And then output the coordinates of the boxes to a file I can then copy/paste into my game.

    I'm currently having trouble getting the alpha value of pixels, though: http://www.pascalgamedevelopment.com...=5915.msg48074
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  2. #12

    Re: Convert image to a number of squares?

    i'm trying to use a convex hull algorithm to generate a collision polygon

    it's working fine with your sprite, but i still have to do some more tests
    From brazil (:

    Pascal pownz!

  3. #13

    Re: Convert image to a number of squares?

    What about this:

    • Trace around the edge of the image to produce a polygon data structure
    • First do a simple radius (or square) check to see if your "near", this is your non-precision check.
    • If you're near, then do a 2D line intersection check along the poly points. This will be the precision check. If you get a intersection you've collided and now have the hit pos that can be used for other things.
    • Way faster than pixel perfect for example and very accurate as compared to a radius/square check. This turned out to work very well for me.


    [br]The algo for tracing the sprite was a mind twist and took a very long time to get working. In the end a guy I met on line from Russia help me to finally get this working and it formed the basis of the PolyPoint collision system in Quantum Engine. There are a few params that allow fine tuning of the algo (alpha threshold, stepback, etc). All in all, the algo can auto trace a very complex shaped image. It's tightly integrated with my engine at this point and pulling it out is not as easy any more without a lot of dependencies.

    However, maybe if you make a tool that will allow you to lay down line segments around your mage and save out this data, then you can apply the same steps outline above for collision detection. At least it's another option to explore.

    Update: I see arthurprs has a convex hull algo working. There is the polygon data that you can use.
    Jarrod Davis
    Technical Director @ Piradyne Games

  4. #14

    Re: Convert image to a number of squares?

    In the latest version of my image editor for phoenix there is a Collision drawing tool to create collision shapes for an image and then exporting them to a xml file.

    If you feel this could be useful i can wrap up a new version of it tonight.

    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  5. #15

    Re: Convert image to a number of squares?

    I appreciate all the feedback, but like I said before, I've already decided to use my boxes approach, as it's fast as heck.

    Quote Originally Posted by Andreaz
    In the latest version of my image editor for phoenix there is a Collision drawing tool to create collision shapes for an image and then exporting them to a xml file.

    If you feel this could be useful i can wrap up a new version of it tonight.
    This sounds very neat, Andreaz, and thanks for the offer, but I'm seeking to automate the box drawing functionality so I don't have to draw the collision boxes manually. My goal is basically to be able to place the program in a folder with the images 1-64.png (for the 64 angles my sprites can point). When the program is run it will load each image one by one, do the automatic collision boxes and export all the data to a text file, so all I have to do is a quick copy/paste.
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  6. #16

    Re: Convert image to a number of squares?

    I've got a pretty nice program up and running now:



    The algorithm to join boxes works pretty well and you can fine tune the settings to make the smallest number of boxes per image.
    Laserbrain Studios - Currently developing Hidden Asset!
    Ascii Sector
    - Real-time roguelike in space!

  7. #17

    Re: Convert image to a number of squares?

    here is the result of my current code



    it used 25 points (blue dots) to cover the sprite

    i still have to try some optimizations to reduce the resulting hull connection points
    From brazil (:

    Pascal pownz!

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •