當我可以自己排列位置數學時,推動/彈出矩陣來轉換形狀的目的是什麼?我可以理解使用上述矩陣做更困難的操作(例如旋轉),但爲什麼要特別翻譯?我爲什麼要使用glTranslate?
public void render()
{
positionX++;
GL.PushMatrix();
GL.Translate(positionX, positionY, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Begin(PrimitiveType.Quads);
GL.Vertex2(0, 0);
GL.Vertex2(0 + widthX, 0);
GL.Vertex2(0 + widthX, 0 + widthY);
GL.Vertex2(0, 0 + widthY);
GL.PopMatrix();
GL.End();
}
與
public void render()
{
positionX++;
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Begin(PrimitiveType.Quads);
GL.Vertex2(positionX, positionY);
GL.Vertex2(positionX + widthX, positionY);
GL.Vertex2(positionX + widthX, positionY + widthY);
GL.Vertex2(positionX, positionY + widthY);
GL.End();
}
一般來說,矩陣的使用允許輕鬆地鏈接操作。不知道這是*的原因,或者它是否回答你的問題。 – BradleyDotNET 2014-12-01 22:38:15
你不應該;該函數與GL.Begin和GL.End函數一起被棄用 – 2014-12-01 22:40:47
在'glTranslatef'後面添加'glRotatef(45,0,0,1)',並運行程序。現在將'glRotatef'移動到'glTranslatef'之前,然後重新運行你的程序。 – 2014-12-01 22:43:19