【发布时间】:2013-08-22 07:31:09
【问题描述】:
我正在尝试围绕其中心旋转图片并将其缩放到手机的屏幕分辨率(在 android 中)。
这是我的代码:
// ----------------------------------------
// Scaling:
float scaleWidth = 2/screenWidth;
float scaleHeight = 2/screenHeight;
// ----------------------------------------
// Start position of the picture
int x = 60;
int y = 60;
float startX = x*scaleWidth;
float startY = y*scaleHeight;
// End position of the picture
float endX = (x + bmpWallSize) * scaleWidth;
float endY = (y + bmpWallSize) * scaleHeight;
// Center of the bitmap:
float midX = (x + (bmpWallSize/2)) * scaleWidth;
float midY = (y + (bmpWallSize/2)) * scaleHeight;
// ----------------------------------------
// Rotating:
gl.glTranslatef(midX, midY, 0f);
gl.glRotatef(r,0, 0,-1 );
gl.glTranslatef(-midX, -midY, 0);
r++; if (r > 360) r = 1;
不旋转图片看起来很好,但一旦旋转它就会改变大小(正方形变成矩形)。 我认为这是因为我需要在旋转之后而不是之前缩放图片的顶点,但我不知道如何。我google了很多,但找不到答案。感谢您的帮助
【问题讨论】:
-
愚蠢的问题:您是否尝试过切换 X 和 Y 进行缩放?
标签: java android opengl-es-2.0 scaling image-rotation