我正在尝试编写一些代码来在Android上绘制一个空的纹理房间,使用基于libgdx框架构建的库。该库包含一些对象定义,特别是我正在使用的纹理长方体。
这是我的创建方法:
public void create() {
// create new perspective camera with FOV = 67
_camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
_camera.translate(0, 0, 10);
_camera.lookAt(new Vector3(0,0,1));
_camera.near = 0.1f;
_camera.far = 100f;
// load texture for box
_texture = new Texture(Gdx.files.internal("data/checker.jpg"));
// create box
_box = new TexturedCuboid(new Vector3(0,0,10), new Quaternion(Vector3.Z, 0), new Vector3(10,10,10), _texture,new Vector2(1.0f,1.0f), true);
// repeat texture
_box.setTextureWrapMethod(TextureWrap.Repeat, TextureWrap.Repeat);
// apply linear filtering to texture
_box.setTextureFilter(TextureFilter.Linear, TextureFilter.Linear);
// create light vector
_light = new Light(0.0f, 1.0f, -1.0f, 0.2f, 1000.0f);
// load shaders
_shader = new ShaderProgram(Gdx.files.internal("shaders/simple.vert"), Gdx.files.internal("shaders/simple.frag"));
}
当我尝试执行代码时,我从调试器中收到此错误:
1-17 15:33:01.445: E/AndroidRuntime(3386): FATAL EXCEPTION: GLThread 285
java.lang.NoSuchMethodError:nl.uu.MobileVRLib.meshes.TexturedCuboid.setVertices
这是texturedCuboid构造函数:
public TexturedCuboid(final Vector3 position, final Quaternion orientation, final Vector3 size, final Texture texture, final Vector2 textureSize, boolean boxMode) {
// Call constructor.
super(position, orientation, size, texture, true, 24, 36, textureSize, VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.TexCoords(0));
// Set box mode.
_boxMode = boxMode;
// We can now create our vertices.
createVerticesCustom();
}
最后引发异常的代码:
private void createVerticesCustom() {
// Assign the vertices locations, normals and the texture coordinates u v.
setVertices(new float[] {
// Front
-0.5f, 0.5f, 0.5f, 0, 0, (_boxMode ? -1 : 1), 0, 0,
-0.5f, -0.5f, 0.5f, 0, 0, (_boxMode ? -1 : 1), 0, 1,
0.5f, 0.5f, 0.5f, 0, 0, 1, (_boxMode ? -1 : 1), 0,
0.5f, -0.5f, 0.5f, 0, 0, 1, (_boxMode ? -1 : 1), 1,
// Back
0.5f, 0.5f, -0.5f, 0, 0, (_boxMode ? 1 : -1), 0, 0,
0.5f, -0.5f, -0.5f, 0, 0, (_boxMode ? 1 : -1), 0, 1,
-0.5f, 0.5f, -0.5f, 0, 0, (_boxMode ? 1 : -1), 1, 0,
-0.5f, -0.5f, -0.5f, 0, 0, (_boxMode ? 1 : -1), 1, 1,
// Top
-0.5f, 0.5f, -0.5f, 0, (_boxMode ? -1 : 1), 0, 0, 0,
-0.5f, 0.5f, 0.5f, 0, (_boxMode ? -1 : 1), 0, 0, 1,
0.5f, 0.5f, -0.5f, 0, (_boxMode ? -1 : 1), 0, 1, 0,
0.5f, 0.5f, 0.5f, 0, (_boxMode ? -1 : 1), 0, 1, 1,
// Bottom
0.5f, -0.5f, 0.5f, 0, (_boxMode ? 1 : -1), 0, 0, 0,
0.5f, -0.5f, -0.5f, 0, (_boxMode ? 1 : -1), 0, 0, 1,
-0.5f, -0.5f, 0.5f, 0, (_boxMode ? 1 : -1), 0, 1, 0,
-0.5f, -0.5f, -0.5f, 0, (_boxMode ? 1 : -1), 0, 1, 1,
// Left
-0.5f, 0.5f, -0.5f, (_boxMode ? 1 : -1), 0, 0, 0, 0,
-0.5f, -0.5f, -0.5f, (_boxMode ? 1 : -1), 0, 0, 0, 1,
-0.5f, 0.5f, 0.5f, (_boxMode ? 1 : -1), 0, 0, 1, 0,
-0.5f, -0.5f, 0.5f, (_boxMode ? 1 : -1), 0, 0, 1, 1,
// Right
0.5f, 0.5f, 0.5f, (_boxMode ? -1 : 1), 0, 0, 0, 0,
0.5f, -0.5f, 0.5f, (_boxMode ? -1 : 1), 0, 0, 0, 1,
0.5f, 0.5f, -0.5f, (_boxMode ? -1 : 1), 0, 0, 1, 0,
0.5f, -0.5f, -0.5f, (_boxMode ? -1 : 1), 0, 0, 1, 1
});
if (_boxMode) {
setIndices(new short[] {
// front
2, 3, 1, 2, 1, 0,
// back
6, 7, 5, 6, 5, 4,
// top
10, 11, 9, 10, 9, 8,
// bottom
12, 13, 14, 13, 15, 14,
// left
18, 19, 17, 18, 17, 16,
// right
22, 23, 21, 22, 21, 20 });
}
else {
setIndices(new short[] {
// front
0, 1, 2, 1, 3, 2,
// back
4, 5, 6, 5, 7, 6,
// top
8, 9, 10, 9, 11, 10,
// bottom
14, 15, 13, 14, 13, 12,
// left
16, 17, 18, 17, 19, 18,
// right
20, 21, 22, 21, 23, 22 });
}
}
}
我无法弄清楚为什么会引发异常。有任何想法吗?我确信该库正在运行,因为它已在另一个项目中成功使用。