設置圖片圍繞旋轉中心點(OPENGL | ES)

http://www.cnblogs.com/IamEasy_Man/archive/2009/12/14/1624143.html

假設要畫一個32*32的圖像在點(x, y), 並讓此點以圖像的中心旋轉,那麼用如下代碼就可以實現 
// 圍繞中心旋轉
GLfloat vertices[] = 
{
- imageWidth/2, - imageHeight/2, 
  imageWidth/2, - imageHeight/2, 
- imageWidth/2,   imageHeight/2,
  imageWidth/2,   imageHeight/2 
};

// 圍繞底部中心旋轉
//GLfloat vertices[] = 
// {
// - imageWidth/2, 0.0, 
//   imageWidth/2, 0.0, 
// - imageWidth/2, imageHeight,
//   imageWidth/2, imageHeight 
// };

glLoadIdentity();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glPushMatrix();
glTranslatef(x, y, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glScalef(xScale, yScale, 1.0f);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();


如果希望改變旋轉的方向,例如從順時針改爲逆時針,可以通過glRotatef(angle, 0.0f, 0.0f, 1.0f)中angle的正負符號
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章