Calculate collision with rotate()

Problems with Canvas, OpenGL, etc...

Calculate collision with rotate()

Postby Duckemai » Wed May 18, 2011 9:08 pm

Hi,

I am currently working on a 2D Game with square bitmaps that move over the androidscreen. The corners and edges of the bitmaps are transparent, in the middle you see a frog ;-). Now I am faced with the collision calculation, so that the frogs must stop after contact with other frogs. But I have a problem to calculate the collision after using the function rotate(). I need rotate(), to turn the frogs to the direction they are looking.
To calculate a collision with horizontal bitmaps is easy:

int firstXRangeStart = x_Coordinate;
int firstXRangeEnd = firstXRangeStart + widthBitmap;

But does somebody know how to perform a collision calculation when bitmaps are not just horizontal, because they are rotated through an angle? At the moment I use always a horizontal BoundingBox. But this is very unexact.

Thank you very much
Duckemai
Duckemai
Freshman
Freshman
 
Posts: 4
Joined: Sat Aug 21, 2010 10:13 am

Top

Re: Calculate collision with rotate()

Postby mark@project8games.com » Wed May 18, 2011 10:16 pm

http://en.wikipedia.org/wiki/Separating_axis_theorem is probably your best bet. You'll need to maintain the bounds of your bitmaps as separate objects, and also rotate them as you rotate your bitmap (ideally you'll have an single GameEntity object which has a single rotate() method, which rotates both its bounds and drawable)
User avatar
mark@project8games.com
Developer
Developer
 
Posts: 41
Joined: Tue Mar 02, 2010 8:33 pm

Re: Calculate collision with rotate()

Postby Duckemai » Thu May 19, 2011 9:42 pm

Thanks for the answer.
If I use your suggestion, then I still have the problem to compare the rotated bounds and the rotated drawable to recognize, whenever they are in contact. The link you send about this theme seems to be very difficult. Or do you know another way to determine, whenever 2 objects collide?
Duckemai
Freshman
Freshman
 
Posts: 4
Joined: Sat Aug 21, 2010 10:13 am

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 2 guests