所以我在我的顯示屏中有以下調用。顯示方法不會調用除loadIdentity之外的任何狀態更改方法。顯示方法然後調用以下內容。Jogl推/流行矩陣不工作或我誤解
gl.glPushMatrix();
gl.glRotated(m_angle, 1.0, 1.0, 0.0);
m_angle += 5;
cubeBySquare(gl,0.2);
gl.glTranslated(0.5, 0.0 , 0.0);
cubeByVertex(gl,0.2);
gl.glPopMatrix();
兩種方法如下所示 - 基本上一個嘗試使用旋轉來繪製一個立方體和翻譯(cubeBySquare)和其他成功地通過指定所有頂點的顯式(cubeByVertex)繪製的立方體。
protected void cubeBySquare(GL2 gl,double side)
{
/*
* front - blue
*
* draw the square and leave it where it is on XY plane
*/
gl.glPushMatrix();
gl.glColor3d(0.0,0.0,1.0);
square(gl,side);
gl.glPopMatrix();
/*
* back - green
*
* draw square and push it backwards on the Z axis
*/
gl.glPushMatrix();
gl.glColor3d(0.0,1.0,0.0);
gl.glTranslated(0.0 , 0.0 , -side);
square(gl,side);
gl.glPopMatrix();
/*
* lhs - cyan
*
* draw square and rotate -90 around Y axis
*/
gl.glPushMatrix();
gl.glColor3d(0.0,1.0,1.0);
gl.glRotated(-90, 0.0, 1.0, 0.0);
square(gl,side);
gl.glPopMatrix();
/*
* rhs - red
*
* draw square, rotate -90 aeound Y axis, translate to rhs on X axis
*/
gl.glPushMatrix();
gl.glColor3d(1.0,0.0,0.0);
gl.glRotated(-90, 0.0, 1.0, 0.0);
gl.glTranslated(side, 0.0 , 0.0);
square(gl,side);
gl.glPopMatrix();
/*
* top - mauve
*
* draw square, rotate -90 around X axis, translate along Y axis
*/
gl.glPushMatrix();
gl.glColor3d(1.0,0.0,1.0);
gl.glRotated(90, 1.0, 0.0, 0.0);
gl.glTranslated(0.0 , side , 0.0);
square(gl,side);
gl.glPopMatrix();
/*
* bottom - yellow
*
* draw square, rotate -90 around X-axis
*/
gl.glPushMatrix();
gl.glColor3d(1.0,1.0,0.0);
gl.glRotated(-90, 1.0, 0.0, 0.0);
square(gl,side);
gl.glPopMatrix();
}
protected void cubeByVertex(GL2 gl,double side)
{
gl.glBegin(GL_QUADS); // of the color cube
// Front - blue
gl.glColor3d(0.0, 0.0, 1.0);
gl.glVertex3d(0.0 , 0.0 , 0.0);
gl.glVertex3d(side, 0.0 , 0.0);
gl.glVertex3d(side, side, 0.0);
gl.glVertex3d(0.0 , side, 0.0);
// Back - green
gl.glColor3d(0.0, 1.0, 0.0);
gl.glVertex3d(0.0 , 0.0 , -side);
gl.glVertex3d(side, 0.0 , -side);
gl.glVertex3d(side, side, -side);
gl.glVertex3d(0.0 , side, -side);
// Left - cyan
gl.glColor3d(0.0, 1.0, 1.0);
gl.glVertex3d(0.0 , 0.0 , 0.0);
gl.glVertex3d(0.0 , 0.0 , -side);
gl.glVertex3d(0.0 , side, -side);
gl.glVertex3d(0.0 , side, 0.0);
// Right - red
gl.glColor3d(1.0, 0.0, 0.0);
gl.glVertex3d(side, 0.0 , 0.0);
gl.glVertex3d(side, 0.0 , -side);
gl.glVertex3d(side, side, -side);
gl.glVertex3d(side, side, 0.0);
// Top - mauve
gl.glColor3d(1.0, 0.0, 1.0);
gl.glVertex3d(0.0 , side, 0.0);
gl.glVertex3d(side, side, 0.0);
gl.glVertex3d(side, side, -side);
gl.glVertex3d(0.0 , side, -side);
// Bottom - yellow
gl.glColor3d(1.0, 1.0, 0.0);
gl.glVertex3d(0.0 , 0.0 , 0.0);
gl.glVertex3d(side, 0.0 , 0.0);
gl.glVertex3d(side, 0.0 , -side);
gl.glVertex3d(0.0 , 0.0 , -side);
gl.glEnd(); // of the color cube
}
結果是意外的,因爲您可以在圖像中看到。我試圖看看我的邏輯錯在哪裏,但我找不到任何意想不到的事情。它看起來像推/爆矩陣並不真正清除堆棧中的矩陣。這可能意味着我沒有正確使用它 - 但它看起來像我在網上找到的大多數分層繪圖示例。
看起來沒有辦法在這裏包含一個圖像,這使得解釋笨拙。
基本上THR cubeBySquare版本的旋轉和平移遍佈商店,不是我期待的 - 想以前的旋轉和平移的影響更近的endering即使我已經每平方米由推括號/彈出矩陣
您可以包含各種圖像,只需點擊工具欄上的圖像按鈕 –