Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  Rotational Collsion Detection  (Read 2979 times)
0 Members and 1 Guest are viewing this topic.
Offline Androider

Senior Newbie





« Posted 2012-01-17 18:19:24 »

I am working on a game in Android and I currently have pixel perfect collision detection working. It first checks bounding boxes and if that returns true then checks the overlap of pixels. All works great except when I rotate my image. The collision detection is still using the old un-rotated 2d pixel array. So my question is how I should go about rotating the indexes of the pixels to match that of the current rotation of the image?

Thanks in advance, I find this subject very interesting to work on!
Offline pitbuller
« Reply #1 - Posted 2012-01-17 21:07:36 »

Ask your self a question do you really need pixel perfect collision detection. Actual device screen is usually so small that its just not worth it. Pixel perfect collision detection is performance is really bad and the gains are usually neglible. Just compose your game objects from primitives: circles, rectangles, maybe even polygons. Then math is lot more robust and more performant.
Also keep in mind that there is ton of difference size screens in Android scene. How you deal with that if your game logic is based on pixels? What happen when you want animated characters? Do collision events based on current animation state and cause jerky movement.

I desing all my game sizes on meters, this is just lot more natural and work perfectly well on every screen size and every scenario. If I decide that I need more accurate graphics and I double all picture sizes that do not cause any changes on logic layer.
Offline Androider

Senior Newbie





« Reply #2 - Posted 2012-01-17 21:22:15 »

I do realize that the collision detection like this is going to hinder the performance a bit. But it only needs to occur if there is a bounding box collision so I really don't think that it will be that bad. And I have seen many android games that have implemented it and it works/looks great. I currently am not worried about animated sprites at all, that will be next.

Currently my game has some collisions that do not look good at all because it is not pixel perfect. I don't necessarily need it on all of the images either. Just one because it has a pointy edge with a lot of transparent pixels around it. It is quite obvious when a collision occurs that shouldn't.

I appreciate your thoughts @pitbuller I need to keep a lot of things in mind when doing this for sure.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pjt33
« Reply #3 - Posted 2012-01-17 22:00:12 »

How are you rendering the rotated images? In particular:

1. Are you using anti-aliasing? If so, you're going to need to define how pixel-perfect collision should work...
2. Is the angle quantised?
3. Do you pre-render anything to a back-buffer? If not, is the memory vs performance tradeoff the reason why not?
Offline Androider

Senior Newbie





« Reply #4 - Posted 2012-01-18 00:06:37 »

I am not using any anti-aliasing to do the rendering. When I display an image on screen it is using the Android Bitmap object(which is very similar to the standard Image class when doing Java Graphics). The rendering is done via a Canvas object which in turn is basically the same as the Graphics2D class in standard Java Graphics. I am not doing anything other than calling a draw method on the Bitmap object via the Canvas. I currently have a 2D array of pixels that I retrieved from the Bitmap and what I am looking to do is as the image is rotated, I need to rotate the pixels in the 2D array to match the specific rotation.

I don't know if this helps at all. What do you mean by "Is the angle quantised?" Thanks! I appreciate your thoughts on this!
Offline pitbuller
« Reply #5 - Posted 2012-01-18 00:37:58 »

Just read pixel, if its opaque add transformation to that coordinate(local texture coordinate) and then check sprite position + transformed pixel against geometry that you want.

Still I disagree the need of pixel perfect collision detection. Pixel perfect collision just means that you divide your object to size*size number of rects and bruteforce all possible collisions. Non naive implementation would use just as many rectangles that are needed for accurate collision detection. Bounding boxes are your friend learn to use them right.
Pixel perfect collision might work good enough for object vs static objects and only when you don't need collision forces but it's just not scalable or offers anything that would not be possile with other means.

I personally use Auriel Ribbon's box2d editor. http://code.google.com/p/box2d-editor/
I take my game object image and draw outlines and rest is magic. I would suggest you to think something similar in future.
Offline Androider

Senior Newbie





« Reply #6 - Posted 2012-01-18 03:53:24 »

@pitbuller I think you have missed the point on your comment. I know what I need for my game. I am using bounding box collision to detect a collision and from there on out I only brute force the overlapping rects created by the bounding boxes until there is a pixel overlap at the same x and y coordinate. I have that fine. I was hoping to get some help to understand how to transform a 2D array by a certain value of degrees. Whether it be an Android solution or not. It is a necessity that I implement this in my game and I need it to be perfect for the game to be played properly. More importantly I am very interested in learning how to do this and also the math behind it.
Offline pitbuller
« Reply #7 - Posted 2012-01-18 10:58:50 »

@pitbuller I think you have missed the point on your comment. I know what I need for my game. I am using bounding box collision to detect a collision and from there on out I only brute force the overlapping rects created by the bounding boxes until there is a pixel overlap at the same x and y coordinate. I have that fine. I was hoping to get some help to understand how to transform a 2D array by a certain value of degrees. Whether it be an Android solution or not. It is a necessity that I implement this in my game and I need it to be perfect for the game to be played properly. More importantly I am very interested in learning how to do this and also the math behind it.
I allready gave an answer how to do it.
Quote
Just read pixel, if its opaque add transformation to that coordinate(local texture coordinate) and then check sprite position + transformed pixel against geometry that you want.

Offline Androider

Senior Newbie





« Reply #8 - Posted 2012-01-18 14:25:59 »

Oh thanks that really explains it well. Glad I know how to do it now. lol
Offline co_Opernicus

Senior Newbie





« Reply #9 - Posted 2012-04-17 16:44:53 »

I have a friend who made a game engine in Delphi and the other day he showed me how he deals with this type of collisions:

 On every frame he calculates a "bounding polygon" of the sprite and uses it as a sort of bounding box, checking if it overlaps with other sprites. The result was amazingly precise... You don't have to make a perfect silouette of the sprite for the sake of performance, but calculating the relevant points that cover the current frame and joining them would be enough. Maybe on Android it's too much calculation per frame, I don't know, but you could try that approach.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tberthel
« Reply #10 - Posted 2012-04-17 19:48:23 »

Rectangles and circles are good enough.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (55 views)
2014-04-15 18:08:23

BurntPizza (53 views)
2014-04-15 03:46:01

UprightPath (66 views)
2014-04-14 17:39:50

UprightPath (49 views)
2014-04-14 17:35:47

Porlus (66 views)
2014-04-14 15:48:38

tom_mai78101 (90 views)
2014-04-10 04:04:31

BurntPizza (151 views)
2014-04-08 23:06:04

tom_mai78101 (247 views)
2014-04-05 13:34:39

trollwarrior1 (204 views)
2014-04-04 12:06:45

CJLetsGame (211 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!