2012-08-15 5 views
1

타일링 된 평면 위로 움직이는 카메라를 만들고 싶습니다. 카메라는 XY 평면에서만 움직이며 항상 똑바로 보입니다. 직교 투영으로 의사 2D 렌더러를 기대합니다. 내 문제는 카메라를 번역하는 방법을 모른다는 것입니다. 몇 가지 조사를 한 후에 OpenGL에 "카메라"와 같은 것이없고 전 세계를 번역해야한다는 생각이 들었습니다. Matrix.setLookAtM 함수에서 눈 위치와 뷰 중심 좌표를 변경하면 결과가 왜곡됩니다. 전체 MVP- 매트릭스 번역도 작동하지 않습니다.GLES2.0에서 카메라를 번역하는 방법은 무엇입니까?

현재 아이디어가 부족합니다. 버텍스 버퍼에서 매 프레임마다 모든 버텍스를 직접 변환해야합니까? 그건 나에게 그럴듯하게 보이지 않는다.

나는 GLSurfaceView 파생 및 설정에 다음과 같은 기능을 구현하고 현장 업데이트 : 눈 위치를 변경

public void onSurfaceChanged(GL10 unused, int width, int height) { 

    GLES20.glViewport(0, 0, width, height); 
    float ratio = (float) width/height; 

    // Setup the projection Matrix for an orthogonal view 
    Matrix.orthoM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7); 

} 

public void onDrawFrame(GL10 unused) { 

    // Draw background color 
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 

    //Setup the camera 
    float[] camPos = { 0.0f, 0.0f, -3.0f }; //no matter what else I put in here the camera seems to point 
    float[] lookAt = { 0.0f, 0.0f, 0.0f }; // to the coordinate center and distorts the square 

    // Set the camera position (View matrix) 
    Matrix.setLookAtM(vMatrix, 0, camPos[0], camPos[1], camPos[2], lookAt[0], lookAt[1], lookAt[2], 0f, 1f, 0f); 

    // Calculate the projection and view transformation 
    Matrix.multiplyMM(mMVPMatrix, 0, projMatrix, 0, vMatrix, 0); 

    //rotate the viewport 
    Matrix.setRotateM(mRotationMatrix, 0, getRotationAngle(), 0, 0, -1.0f); 
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0); 

    //I also tried to translate the viewport here 
    // (and several other places), but I could not find any solution 

    //draw the plane (actually a simple square right now) 
    mPlane.draw(mMVPMatrix); 

} 

답변

3

을 그냥 왜곡 된 결과를 초래보기 센터는 "바라보기"α- 함수에서 조정합니다.

Android 튜토리얼에서 얻은 것이라면 코드에 버그가 있다고 생각합니다.

(IT here에 대한 코멘트를 만든) 다음과 같은 수정을 시도해보십시오

  1. 사용 setLookatM은 카메라가 할 위치를 가리 키도록. 이 제대로 카메라를 회전하지 않는 한, " gl_Position = uMVPMatrix * vPosition;"

  2. 내가 //rotate the viewport 섹션도 제거해야한다고 생각 것 : " gl_Position = vPosition * uMVPMatrix;"
    에 :

  3. 쉐이더에서
  4. gl_Position 라인

    에서 변경 . setlookat 함수에서 카메라 방향을 변경할 수 있습니다.

+0

예, 언급 한 공식 샘플의 코드를 기반으로합니다. 당신의 수정은 매력처럼 작동합니다. 감사! – Andre

관련 문제