Rotate a bitmap around a registration point?

Put your problem here if it does not fit any of the other categories.

Rotate a bitmap around a registration point?

Postby Jorenm » Fri Dec 11, 2009 2:51 am

Right now this is what I'm using:

Code: Select all
       Matrix matrix = new Matrix();
       Float angle = new Double(Math.toDegrees(Math.atan2(targetY - shipY, targetX - shipX))).floatValue();
       matrix.postRotate(angle + 90);
       Bitmap bitmap = Bitmap.createBitmap(loader.getBitmap(mBitmap), 0, 0,
                mWidth, mHeight, matrix, true);
       int width = bitmap.getWidth();
       int height = bitmap.getHeight();       
       canvas.drawBitmap(bitmap, shipX + mX - width/2, shipY + mY - height/2, null);

It's rotating a turret bitmap to target a ship, but the rotation looks weird because it's not rotation based on a registration point that makes sense for the bitmap. Is there anyone who knows how to accomplish what I want?

Also, if anyone knows any way to improve any of the above code, it's very welcome.
Junior Developer
Junior Developer
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests