Finding the exact point of collision.
BlitzMax Forums/BlitzMax Programming/Finding the exact point of collision.
| ||
I would like to be able to acquire the exact pixel point of a collision between two images. I need to derive the exact "x,y" locations of the pixels detected in the collision. So, If I were to have image "A" collide with image "B" I could know the exact location (x,y) of the pixels involved in the collision. This would be very helpful in deriving the cosine angle in my project. Edit - I would be open to modifying the Bmax 2d Mod. Thanks |
| ||
there are many ways. some are efficient and some are not but most involve some sort of trickery. Take Max2d module it uses a pretty efficient quad collision but the test becomes exponentially slow as the image become larger. you can use a polygon outline that would be more efficient but wound not be as accurate. You can make a function that looks in to the colors of the image's pixmap based on the direction of travel and after collision move back one pixel at a time until you are at the exact position. Either way most of them involve final pixel movement(adjustment) to get it right. Can you provide a more detailed example of what you want to do? maybe I or someone here might be able to help you figure it out. |
| ||
Jesse, I was hoping to hijack the Max2d mod in someway. As understand you that is not possible? How is Max2d testing for pixel perfect collisions? It would be nice to calculate the normal on-the-fly based on the two images pixel points of collision. I would like each image to be represented as a sphere. The problem is the best I can hope for in Bmax is the center point of an image. So if I were to have a sphere collide into a rectangle the radius of the sphere would be uniform; the rectangle radius would not. The sphere colliding at one end of the long axis of the rectangle will be a longer distance from the center then say the the same sphere colliding on the long axis at the middle. This "Pool" example my help to shed some light on what I am getting at: http://www.blitzbasic.com/codearcs/codearcs.php?code=415 My "Plan B" is to supply the normals in a look-up table or such for every 2d image. This example I found interesting at first blush. http://www.blitzbasic.com/codearcs/codearcs.php?code=998 The project I am working on is sort-of like Subspace (multi-player 2d space shoot'em up). So I have things bouncing off of things. My biggest issue is to accoplish the above in the most efficient/fast way possible. Thanks, |
| ||
This 2D Inertia Example is what I am using as a basis for my games 2D physics. Here: http://redeyeware.zxq.net/codebmax/main.html And the Example Download: http://redeyeware.zxq.net/codebmax/2d_ineria.zip I hope some find it useful. So I'll be adding the above idea to this in essence. :) |
| ||
I found this thread on Far Seer Physics; not bad. http://blitzbasic.com/Community/posts.php?topic=78349#888954 I found it to be a tad slow. Has anyone used this? Could not get through to the authors blog. Is there any official site? Anyway very cool. Thanks, |
| ||
have you looked into chipmun physics. Brucey made a moduel for it: http://code.google.com/p/maxmods/downloads/detail?name=chipmunk_1_03_win32_bin.zip&can=2&q= or box 2d: http://code.google.com/p/maxmods/downloads/detail?name=box2d_1_04_src.zip&can=2&q= hre is a video of a game made with box2d: http://www.youtube.com/watch?v=FZHZFAlGJ6c and the thread: http://www.blitzmax.com/Community/posts.php?topic=85122 either one should be faster. Last edited Wednesday 6th of October 2010 02:46:02 AM GMT |
| ||
To add public top left coordinate of most recent collision in max2d.bmx, add this above the Private (line 1179)Global CollisionX,CollisionY Private and make following changes before both return -1 calls at around line 1422 and 1442 If LineBuffer[x] CollisionX=startx+x;CollisionY=y;Return -1 . . . If LineBuffer[x] CollisionX=startx+x;CollisionY=y;Return -1 Last edited Wednesday 6th of October 2010 05:55:45 AM GMT |
| ||
Jesse, All very cool! I had just checkout all of the above except the video which was also cool. But, as it turns out the Line vs. circle example will work out just fine for now. It is "way fast" and will work well with my omnidirectional scrolling map. Ultimately it comes down to speed. I have my 2d physics approximation running much faster then Box2d (for my application) will. I do plan to use Box2d in the future. Check out the pics of the alpha client/server and level editor. Here: http://redeyeware.zxq.net/ Thank you for all the help. :) @Skidracer ..... Hello! I'll try the above out and report! :) Thanks, |