0
我目前使用LWJGL創建一個簡單的2D遊戲。我想創建一些對象來讓事情變得更簡單。目前只需繪製一個Quad對象就可以正常工作,但後來我決定實現一種繪製Quad對象的方式。在OpenGL中旋轉Quad無法正確顯示(rotatef)
這是到目前爲止的代碼用於繪製旋轉四:
@Override
public void draw(float angle) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// translate the quad to the origin before rotation
glTranslatef(-(this.x + (this.w/2)), -(this.y + (this.h/2)), 0);
glRotatef(angle, (this.x + (this.w/2)), (this.y + (this.h/2)), 0);
// translate the quad back to its original position
glTranslatef((this.x + (this.w/2)), (this.y + (this.h/2)), 0);
glColor4f(this.color.getRed(), this.color.getAlpha(), this.color.getBlue(), this.color.getAlpha());
glBegin(GL_QUADS);
glVertex2f(this.x, this.y);
glVertex2f(this.x + this.w, this.y);
glVertex2f(this.x + this.w, this.y + this.h);
glVertex2f(this.x, this.y + this.h);
glEnd();
}
我這樣做是爲了畫一個四 四Q =新的四(10,10,100,100); // new Quad(x,y,w,h) q.draw(Math.PI); //它是180度,但喜歡它
它不繪製Quad和這是如何繪製
我不知道這到底是怎麼回事。
作爲一個方面的問題
難道是一樣的效果,如果我只是使用2D旋轉矩陣來計算新的x和y,然後簡單地計算出其它的X和Y的?
哦,我明白了,感謝那尼科。我現在覺得這很愚蠢 – PurityLake