我有一個點雲,我已經在Android OpenGL-ES上呈現。我可以正確翻譯它(我認爲),但是當我旋轉它時,我無法使它像想要的那樣工作。我希望它圍繞點雲的中心旋轉(我有這個3D點),但我不知道該怎麼做。Android OpenGL ES:針對任意軸旋轉?
public void onDrawFrame(GL10 gl) {
// Clears the screen and depth buffer.
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Replace the current matrix with the identity matrix
gl.glLoadIdentity();
// Translates 4 units into the screen.
GLU.gluLookAt(gl, eyeX, eyeY, eyeZ,
centerX, centerY, centerZ,
upX, upY, upZ);
// rotate
gl.glRotatef(_xAngle, 1f, 0f, 0f);
gl.glRotatef(_yAngle, 0f, 1f, 0f);
gl.glRotatef(_zAngle, 0f, 0f, 1f);
gl.glTranslatef(_xTranslate, _yTranslate, _zTranslate);
// Draw things
ptCloud.draw(gl);
aBox.draw(gl);
}
我更改_translate和_angle變量以響應用戶交互,並且OpenGl將依次對它們進行操作。您可以看到我在我的透視設置後立即在我的prCloud上運行繪圖程序。我會告訴你的是:
public void draw(GL10 gl) {
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glPointSize(0.5f);
gl.glDrawArrays(GL10.GL_POINTS, 0, numVertices);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
還有創建表面的方法,因爲我不知道這是否會影響任何東西:
public void onSurfaceChanged(GL10 gl, int width, int height) {
// Sets the current view port to the new size.
gl.glViewport(0, 0, width, height);
// Select the projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
// Reset the projection matrix
gl.glLoadIdentity();
// Calculate the aspect ratio of the window
GLU.gluPerspective(gl, 45.0f, (float) width/(float) height, 0.001f,
1000000.0f);
// Select the modelview matrix
gl.glMatrixMode(GL10.GL_MODELVIEW);
// Reset the modelview matrix
gl.glLoadIdentity();
}
這裏是我的LOOKAT默認變量:
private float eyeX = 20;
private float eyeY = -150;
private float eyeZ = 60;
private float centerX = 0;
private float centerY = 0;
private float centerZ = 0;
private float upX = 0;
private float upY = 0;
private float upZ = 1;
點數已被縮放到(0,0,0)到(120,180,38)的範圍內。我也不知道如何找到一個眼位置,將顯示整個模型提供隨機最大點值...
任何人都可以猜測爲什麼它不會旋轉我期望?
其實,這有助於我將其旋轉對點(0,0,0 )。如何針對任意點(如點雲的中心)旋轉它? – RedLeader
..加油吧。轉到旋轉前的點。旋轉。轉換爲該點的否定。 – RedLeader
@RedLeader另一種選擇是在做轉換之前先對glPushMatrix進行glPopMatrix,然後在完成時將glPopMatrix恢復到當你說推矩陣時的圖形狀態,所以你不必將點的負值 –