我正在制作一个简单的App,以在相机视图中的某个距离处显示一个多维数据集,当旋转手机时,该场景将不在场景中。我正在使用Vuforia AR显示相机背景。下面是渲染功能。背景变得很好。虽然我正在显示的多维数据集是静态的(它看起来看起来有些距离,但不会超出场景)。我很困惑如何在旋转手机时使多维数据集脱离场景。任何帮助,将不胜感激。谢谢
public void renderVideoBackground()
{
if(currentView == VIEW.VIEW_POSTPROCESS)
return;
int vbVideoTextureUnit = 0;
// Bind the video bg texture and get the Texture ID from Vuforia
videoBackgroundTex.setTextureUnit(vbVideoTextureUnit);
if (!mRenderer.updateVideoBackgroundTexture(videoBackgroundTex))
{
Log.e(LOGTAG, "Unable to update video background texture");
return;
}
float[] vbProjectionMatrix = Tool.convert2GLMatrix(
mRenderingPrimitives.getVideoBackgroundProjectionMatrix(currentView, COORDINATE_SYSTEM_TYPE.COORDINATE_SYSTEM_CAMERA)).getData();
if (Device.getInstance().isViewerActive()) {
float sceneScaleFactor = (float)getSceneScaleFactor();
scaleM(vbProjectionMatrix, 0, sceneScaleFactor, sceneScaleFactor, 1.0f);
}
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
GLES20.glDisable(GLES20.GL_CULL_FACE);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
Mesh vbMesh = mRenderingPrimitives.getVideoBackgroundMesh(currentView);
// Load the shader and upload the vertex/texcoord/index data
GLES20.glUseProgram(vbShaderProgramID);
GLES20.glVertexAttribPointer(vbVertexHandle, 3, GLES20.GL_FLOAT, false, 0, vbMesh.getPositions().asFloatBuffer());
GLES20.glVertexAttribPointer(vbTexCoordHandle, 2, GLES20.GL_FLOAT, false, 0, vbMesh.getUVs().asFloatBuffer());
GLES20.glUniform1i(vbTexSampler2DHandle, vbVideoTextureUnit);
// Render the video background with the custom shader
// enable the vertex arrays
GLES20.glEnableVertexAttribArray(vbVertexHandle);
GLES20.glEnableVertexAttribArray(vbTexCoordHandle);
// Pass the projection matrix to OpenGL
GLES20.glUniformMatrix4fv(vbProjectionMatrixHandle, 1, false, vbProjectionMatrix, 0);
// render call
GLES20.glDrawElements(GLES20.GL_TRIANGLES, vbMesh.getNumTriangles() * 3, GLES20.GL_UNSIGNED_SHORT,
vbMesh.getTriangles().asShortBuffer());
//Model View matrix for the cube.
float[] modelViewMatrix = new float[16];
modelViewMatrix[0] =1;
modelViewMatrix[5] =1;
modelViewMatrix[10] =1;
modelViewMatrix[15] =1;
//translate and scale
translateM(modelViewMatrix, 0, 0f, 0f, 1.0f);
scaleM(modelViewMatrix,0,
0.2f,0.2f,0.2f);
//mvp
float temp[] = new float[16];
multiplyMM(temp, 0, vbProjectionMatrix, 0, modelViewMatrix, 0);
GLES20.glVertexAttribPointer(vbVertexHandle, 3, GLES20.GL_FLOAT,
false, 0, mCube.getVertices());
GLES20.glVertexAttribPointer(vbTexCoordHandle, 2,
GLES20.GL_FLOAT, false, 0, mCube.getTexCoords());
// activate texture 0, bind it, and pass to shader
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texturess);
// pass the model view matrix to the shader
GLES20.glUniformMatrix4fv(vbProjectionMatrixHandle, 1, false,temp, 0);
// draw the cube
GLES20.glDrawElements(GLES20.GL_TRIANGLES,
mCube.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
mCube.getIndices());
//disable the vertex arrays
GLES20.glDisableVertexAttribArray(vbVertexHandle);
GLES20.glDisableVertexAttribArray(vbTexCoordHandle);
Shader.checkGLError("Rendering of the video background failed");
}