저는 OpenGL과 관련된 작업을하고 있습니다. 지금까지 내가 GL_LINES를 사용하여 상상의 "테두리"를 그리는 뷰포트를 얻었습니다. 그것은 다음과 같은 setLookAt
세트로, 다음과 같습니다OpenGL - 자체 비전 회전?
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, 5, 0, 0, 0, 0, 1, 0);
내 프러스 텀이 설정됩니다 Matrix.frustumM(mProjectionMatrix, 0, -2, 2, -2, 2, 1, 11);
그래서 나는 "큐브"내부 어딘가에 위치하고 있습니다.
지금 내가 성취하고자하는 것은 사용자가 주변을 둘러 보도록하는 것입니다. onTouchEvents를 캡처하여 렌더러에 x/y 방향의 움직임을 전달합니다. 내가하는 일은 터치 리스너로부터받은 특정 각도로 그려진 모든 선을 회전시키는 것입니다.
그것은 다음과 같습니다
그래서 큐브는 대신 그것에서 오는 어디 내가 모르는 어떤 점을 중심으로, 시청자 또는 눈 중앙을 중심으로 회전되지 않습니다.내 문제는 : 뷰어의 중심/위치에서 개체를 어떻게 회전시킬 수 있습니까? setLookAtM에서 가져온 mViewMatrix
을 회전해야합니까? 그렇다면 간단히 Matrix.setRotateM(mViewMatrix, ...)
을 사용 하시겠습니까?
라인의 드로잉 방법은 다음과 같습니다 : 기능에서
public void draw(float[] mViewMatrix, float[] mProjectionMatrix) {
Matrix.multiplyMM(mViewProjectionMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);
GLES20.glUseProgram(iProgId);
lineBuffer.position(0);
GLES20.glVertexAttribPointer(iPosition, 3, GLES20.GL_FLOAT, false, 0, lineBuffer);
GLES20.glEnableVertexAttribArray(iPosition);
colorBuffer.position(0);
GLES20.glVertexAttribPointer(iColor, 3, GLES20.GL_FLOAT, false, 0, colorBuffer);
GLES20.glEnableVertexAttribArray(iColor);
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.rotateM(mModelMatrix, 0, rotX, 1, 0, 0);
Matrix.rotateM(mModelMatrix, 0, -rotY, 0, 1, 0);
Matrix.setIdentityM(mViewProjectionMatrix, 0);
Matrix.multiplyMM(mViewProjectionMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
//GLES20.glUniformMatrix4fv(iVPMatrix, 1, false, mMVPMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewProjectionMatrix, 0);
GLES20.glUniformMatrix4fv(iVPMatrix, 1, false, mMVPMatrix, 0);
//GLES20.glDrawElements(GLES20.GL_LINES, mVertices.length/2, GLES20.GL_UNSIGNED_SHORT, indexBuffer);
GLES20.glDrawArrays(GLES20.GL_LINES, 0, mVertices.length/2);
}
"둘러보기"를 원할 경우보기 매트릭스를 회전해야합니다. – vbo