问题
How do I change the teapot with a text content in Vuforia's Image Target example?
The example is available at : https://developer.vuforia.com/resources/sample-apps/image-targets-sample-app
回答1:
I tried to access the links mbrenon gave. Unfortunately they didn't load.
My solution:
The reason why you have a Teapot is because Vuforia is using that class as the image to be shown. In order to have a plane text, I created my own PlaneTextClass.
Go to src->main->java->com.qualcomm.vuforia.samples->SampleApplication->utils. There you could find the objects you can use.
Add a class named "TextPlane" and extended from "MeshObject"
public class TextPlane extends MeshObject { private final static double planeVertices[] = { -50f, -50f, 0.0f, 50f, -50f, 0.0f, 50f, 50f, 0.0f, -50f, 50f, 0.0f }; private final static double planeTexcoords[] = { 0, 0, 1, 0, 1, 1, 0, 1 }; private final static double planeNormals[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 }; private final static short planeIndices[] = { 0, 1, 2, 0, 2, 3 }; private Buffer mVertBuff; private Buffer mTexCoordBuff; private Buffer mNormBuff; private Buffer mIndBuff; public TextPlane(){ mVertBuff = fillBuffer(planeVertices); mTexCoordBuff = fillBuffer(planeTexcoords); mNormBuff = fillBuffer(planeNormals); mIndBuff = fillBuffer(planeIndices); } @Override public Buffer getBuffer(BUFFER_TYPE bufferType) { Buffer result = null; switch (bufferType) { case BUFFER_TYPE_VERTEX: result = mVertBuff; break; case BUFFER_TYPE_TEXTURE_COORD: result = mTexCoordBuff; break; case BUFFER_TYPE_INDICES: result = mIndBuff; break; case BUFFER_TYPE_NORMALS: result = mNormBuff; default: break; } return result; } @Override public int getNumObjectVertex() { return planeVertices.length / 3; } @Override public int getNumObjectIndex() { return planeIndices.length; }}
If you want to change the size of the image, change the values in PlaneVertices[].
Go to src->main->java->com.qualcomm.vuforia.samples->VuforiaSamples->app->ImageTargets->ImageTargetRenderer.java
Add your new class in ImageTargetRenderer.java:
private TextPlane mTextPlane;
- Initilize mTextPlane inside the method initRendering()
mTextPlane = new TextPlane();
- Replace the teapot code with you new textplane code:
Replace this:
GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
false, 0, mTeapot.getVertices());
GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
false, 0, mTeapot.getNormals());
GLES20.glVertexAttribPointer(textureCoordHandle, 2,
GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());
with this:
GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
false, 0, mTextPlane.getVertices());
GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
false, 0, mTextPlane.getNormals());
GLES20.glVertexAttribPointer(textureCoordHandle, 2,
GLES20.GL_FLOAT, false, 0, mTextPlane.getTexCoords());
- Replace this:
GLES20.glDrawElements(GLES20.GL_TRIANGLES,
mTeapot.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
mTeapot.getIndices());
With this:
GLES20.glDrawElements(GLES20.GL_TRIANGLES,
mTextPlane.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
mTextPlane.getIndices());
- Try it. It should work!
来源:https://stackoverflow.com/questions/17939607/vuforia-how-to-change-teapot-with-a-text-in-the-image-targets-example