Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Vertex/Polygon Based collision

Author
Message
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 4th Apr 2010 06:04 Edited at: 4th Apr 2010 06:12
Hey, for my little game I've been working on, I had to create my own little collision system, because the dbSpriteHit() and the dbSpriteCollision() functions would not work at all for it, and Pixel Perfect collision would be way too slow.

So I came up with the idea, Why not create a bunch of verticies, then create a polygon with them, then track each pixel between each of the verticies?

And thus, my little Vertex/Polygon Collision system was born, some screenshots:









I'll try to get the files uploaded tomorrow, but I want to fine tune them a bit and write a tiny tutorial for using it. Attached to this post is .exe in the screenshots, it should run fine.

One more cool thing about this, "dbDot()" is the only DarkGDK function in the whole thing, so this could work easily in other Graphic libraries like Allegro, SDL, SFML, etc.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!

Attachments

Login to view attachments
xbandages
14
Years of Service
User Offline
Joined: 30th Mar 2010
Location: Michigan
Posted: 4th Apr 2010 07:13
I think you are having better luck than me. I'm uploading my pixel perfect demo in my thread. Feel free to check it out, i'm downloading yours
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 4th Apr 2010 11:29
This looks great.

I've heard that the drawing functions are really slow, someone made a plug-in for dbPro with drawing functions that are alot quicker(Cloggy, I think), I don't think we have anything like that for GDK but if you find you need more speed you may want to look into it as dbDot may be slow, although it may not be, I have never really tested this for myself.

This is going to be really useful though, people have been asking for more accurate 2D collisions since day one.

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 4th Apr 2010 16:56
Quote: "I've heard that the drawing functions are really slow, someone made a plug-in for dbPro with drawing functions that are alot quicker(Cloggy, I think), I don't think we have anything like that for GDK but if you find you need more speed you may want to look into it as dbDot may be slow, although it may not be, I have never really tested this for myself."


dbDot() is only used for when you want to draw a polygon, so you can have the polygon hidden if you want.

I'll get the files up here after church today.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 4th Apr 2010 18:35
Of course, you only need to draw it to set it up?

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 4th Apr 2010 19:00
Quote: "Of course, you only need to draw it to set it up?"


I'm a little confused on your question, do you mean Do you need to draw it to set up the polygon?

No, you don't need to. Drawing is only for debugging collision issues and making sure you got the verticies down right. You can draw the polygon only if you want to.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 4th Apr 2010 19:30
Okay guys, as promised, the header files.

Be sure to read the "how to use.txt" file and take a look at the "polyDemo.cpp" in the "examples" folder to understand how it works.

Any questions, feel free to ask.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!

Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 5th Apr 2010 01:58
Ha ha, I get it now I think, sorry, I have done next to nothing in 2D.

xbandages
14
Years of Service
User Offline
Joined: 30th Mar 2010
Location: Michigan
Posted: 7th Apr 2010 02:48 Edited at: 7th Apr 2010 02:49
Have you tried having the objects fix themselves after a collision with this system yet? I'm very curious on how yours works. Also would like a system like this for less complicated sprites and such.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 7th Apr 2010 03:53
Quote: "
Have you tried having the objects fix themselves after a collision with the system yet?
"


Um, what? Could you elaborate a bit more on this? I'm confused.

Quote: "
I'm very curious on how yours works.
"


The basic jist of the system is that you create a set of verticies for a polygon, then you create the Polygon for collisions with those verticies. Then while the "CollisionPolygon" class's constructor is going, it figures out each pixel between each verticies (it draws a bunch of imaginary lines), and logs each pixel.

After you have two polygons setup, you check for collision of the polygons with the command:
"polyCollision(CollisionPolygon* poly1, CollisionPolygon* poly2)"
by taking one pixel from the polygon of poly1, and seeing if another pixel in poly2 shares the same X and Y values. If then, a collision, if not, no collision.

Quote: "
Also would like a system like this for less complicated sprites and such.
"


Could you rephrase what you said here?



Anyways, since last night, I've been working on a program that will allow you to plot the needed verticies and then save them to a file. I'm only having issues on using <fstream> right now since I'm relatively new to it.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
xbandages
14
Years of Service
User Offline
Joined: 30th Mar 2010
Location: Michigan
Posted: 7th Apr 2010 04:14
Question rephrase: Have you made a function that uses your collision system for 2D games? As in, once it detects the collision, it then locates where on the object the collision happened (probably between two vertices in your case) and then pushes the object away from the other one so there is no longer an overlap.

If you would like to see this in as an example, check out my collision system.

As for the fstream, I can help you with that. I'm new to it as well, but I was able to export my bitmasks to a txt file in order to confirm it worked.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 7th Apr 2010 05:04
Um, well for your first question. It doesn't currently have a function like that, but it should be really simple to add, but as for the "push away" part, I think that is something that should be left up to the game programmer, since It is my belief that this collision system should only detect collisions, not alter any values.

For <fstream>, my only issue is with writing to files, I do have all my data that needs to be written, but I have issues with writing it.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
xbandages
14
Years of Service
User Offline
Joined: 30th Mar 2010
Location: Michigan
Posted: 7th Apr 2010 05:33
Yes, I believe that what happens after the detection is up to the programmer as well....but it is a nice addition none the less (used for only certain occasions).

And as for fstream, do you have any code that you need help with? I don't know if I can help you with it unless you were trying to use it already. So if you have code you want help with, please post.
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 8th Apr 2010 06:22
Eh, I figured out what I needed to do with <fstream>, it's now working fine.

And on related news:

I got done making an application that lets you load up an image, and then plot verticies, then saves them to a file, and generates all the needed code to create a polygon for collisions.

I need to still fine-tune the application, I'll try to get it up tomorrow, it's kinda late here.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 8th Apr 2010 14:28
What's the point of using polygons, and then converting it to pixels to do the actual collision?

Why not just run a line intersection algorithm between each line?

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 8th Apr 2010 22:40
Quote: "What's the point of using polygons, and then converting it to pixels to do the actual collision?

Why not just run a line intersection algorithm between each line?"


Well, I don't know how to really do a line intersection algorithm, using the pixel method was much easier.

And on top of that, the pixels give me a bit more flexibility.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Apr 2010 03:13 Edited at: 13th Apr 2010 03:14
As eventually promised, here is the Vertex Plotting utility.

http://www.cuddleware.com/files/utilities/VertexPlotter.zip

Quick how-to on how to use this:

1. Load up a file in the same directory, make sure the picture is in the same directory of the .exe .

2. Enter in a valid variable name.

3. Plot your verticies, you can use the arrow keys to move the image, and you can use the W, A, S, and D, keys to move your mouse (this is in case you're having issues with pin-pointing a certain pixel).

4. Press the "P" key to see a preview of the poly.

5. Exit the program, upon exiting it will create a file with all the needed vertex data, verticies, and polygon. Just paste into a program and use the function "PolyCollision()" for detection.

Simple enough.

If anyone has any question on how to use this utility, just ask.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
xbandages
14
Years of Service
User Offline
Joined: 30th Mar 2010
Location: Michigan
Posted: 13th Apr 2010 06:41
The email you sent me didn't work for some reason....but this download worked great!

I just tried uploading the image and plotted the vertices....very nice!
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Apr 2010 20:46 Edited at: 20th Apr 2010 20:48
Quote: "using the pixel method was much easier"


Line intersection is both simpler and many, many times faster

http://tinyurl.com/y4nmdfh

Login to post a reply

Server time is: 2024-07-07 01:25:59
Your offset time is: 2024-07-07 01:25:59