public void updateViewMatrix(){
  mDevicePosition=mModelMatCalculator.getTranslation();
switch (viewId) {
case FIRST_PERSON:
    float[] invertModelMat=new float[MATRIX_4X4];
  Matrix.setIdentityM(invertModelMat,0);
float[] temporaryMatrix=new float[MATRIX_4X4];
Matrix.setIdentityM(temporaryMatrix,0);
Matrix.setIdentityM(mViewMatrix,0);
Matrix.invertM(invertModelMat,0,mModelMatCalculator.getModelMatrix(),0);
Matrix.multiplyMM(temporaryMatrix,0,mViewMatrix,0,invertModelMat,0);
System.arraycopy(temporaryMatrix,0,mViewMatrix,0,16);
break;
case THIRD_PERSON:
Matrix.setLookAtM(mViewMatrix,0,mDevicePosition[0] + mCameraPosition[0],mCameraPosition[1] + mDevicePosition[1],mCameraPosition[2] + mDevicePosition[2],mDevicePosition[0],mDevicePosition[1],mDevicePosition[2],0f,1f,0f);
break;
case TOP_DOWN:
Matrix.setLookAtM(mViewMatrix,0,mDevicePosition[0] + mCameraPosition[0],mCameraPosition[1],mCameraPosition[2] + mDevicePosition[2],mDevicePosition[0] + mCameraPosition[0],mCameraPosition[1] - 5,mCameraPosition[2] + mDevicePosition[2],0f,0f,-1f);
break;
default :
viewId=THIRD_PERSON;
return;
}
}

public void updateViewMatrix ( ) { mDevicePosition = mModelMatCalculator . getTranslation ( ) ; switch ( viewId ) { case FIRST_PERSON : float [ ] invertModelMat = new float [ MATRIX_4X4 ] ; Matrix . setIdentityM ( invertModelMat , 0 ) ; float [ ] temporaryMatrix = new float [ MATRIX_4X4 ] ; Matrix . setIdentityM ( temporaryMatrix , 0 ) ; Matrix . setIdentityM ( mViewMatrix , 0 ) ; Matrix . invertM ( invertModelMat , 0 , mModelMatCalculator . getModelMatrix ( ) , 0 ) ; Matrix . multiplyMM ( temporaryMatrix , 0 , mViewMatrix , 0 , invertModelMat , 0 ) ; System . arraycopy ( temporaryMatrix , 0 , mViewMatrix , 0 , 16 ) ; break ; case THIRD_PERSON : Matrix . setLookAtM ( mViewMatrix , 0 , mDevicePosition [ 0 ] + mCameraPosition [ 0 ] , mCameraPosition [ 1 ] + mDevicePosition [ 1 ] , mCameraPosition [ 2 ] + mDevicePosition [ 2 ] , mDevicePosition [ 0 ] , mDevicePosition [ 1 ] , mDevicePosition [ 2 ] , 0f , 1f , 0f ) ; break ; case TOP_DOWN : Matrix . setLookAtM ( mViewMatrix , 0 , mDevicePosition [ 0 ] + mCameraPosition [ 0 ] , mCameraPosition [ 1 ] , mCameraPosition [ 2 ] + mDevicePosition [ 2 ] , mDevicePosition [ 0 ] + mCameraPosition [ 0 ] , mCameraPosition [ 1 ] - 5 , mCameraPosition [ 2 ] + mDevicePosition [ 2 ] , 0f , 0f , - 1f ) ; break ; default : viewId = THIRD_PERSON ; return ; } }
update the view matrix of the renderer to follow the position of the device in the current perspective .
