【发布时间】:2010-10-21 17:05:11
【问题描述】:
我正在尝试使用 OGL ES 旋转 2D 图像。加载后我可以在屏幕上移动它,但是当试图通过它的中心旋转图像时,它有一个奇怪的行为,因为旋转中心是屏幕左下角,而不是图像本身的中心。
谷歌搜索我读到我可以推送当前矩阵,更改我需要的任何内容(翻译坐标,旋转图像等),然后将矩阵弹出回到之前的矩阵状态......我做到了但仍然没有像我正在寻找的那样工作(但至少现在看起来它进行旋转的原始坐标不是左下角......)
有什么想法吗?任何人都可以发现我的问题在哪里?
任何帮助将不胜感激!谢谢!!
void drawImage(Image *img)
{
GLfloat fX = (GLfloat)img->x;
GLfloat fY = (GLfloat)(flipY(img->m_height+img->y));
GLfloat coordinates[] = { 0, img->m_textureHeight, img->m_textureWidth, img->m_textureHeight, 0, 0, img->m_textureWidth, 0 };
GLfloat vertices[] =
{
fX, fY, 0.0,
img->m_width+fX, fY, 0.0,
fX, img->m_height+fY, 0.0,
img->m_width+fX, img->m_height+fY, 0.0
};
//Push and change de matrix, translate coords, rotate and scale image and then pop the matrix
glPushMatrix(); //push texture matrix
glTranslatef((int)fX, (int)fY, 0.0); //translate texture matrix
// rotate
if (img->rotation != 0.0f )
glRotatef( -img->rotation, 0.0f, 0.0f, 1.0f );
// scale
if (img->scaleX != 1.0f || img->scaleY != 1.0f)
glScalef( img->scaleX, img->scaleY, 1.0f );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glColor4f(1.0, 0.0, 0.0, 1.0);
glBindTexture(GL_TEXTURE_2D, img->m_name);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();
}
【问题讨论】:
-
我做到了,但没有正常工作。抱歉......现在它工作了;)
标签: c++ image opengl-es rotation