jmonkey球体的运行时错误?

时间:2013-06-10 18:17:06

标签: java jmonkeyengine

在jmonkey中,我看到了他们的第一个教程,它是移动一个鼠标移动的盒子,出于好奇,至于玩这个新玩具,我试图用鼠标移动移动一个球体。由于功能几乎相同,我已将Box替换为Sphere。

public void simpleInitApp() {
    //Box b = new Box(Vector3f.ZERO, 1, 1, 1); //example
    //Geometry geom = new Geometry("Box", b);  //example

    Sphere b = new Sphere(1,2,3, true,true);//(Vector3f.ZERO, 1, 1, 1);
    Geometry geom = new Geometry("Sphere", b);


    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(mat);

    rootNode.attachChild(geom);
}

但它编译但不起作用,它在我创建了Sphere实例的那一行返回以下运行时错误:

java.lang.IllegalArgumentException: Negative capacity: -12
    at java.nio.Buffer.<init>(Buffer.java:191)
    at java.nio.ByteBuffer.<init>(ByteBuffer.java:276)
    at java.nio.ByteBuffer.<init>(ByteBuffer.java:284)
    at java.nio.MappedByteBuffer.<init>(MappedByteBuffer.java:89)
    at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:118)
    at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)
    at com.jme3.util.BufferUtils.createFloatBuffer(BufferUtils.java:831)
    at com.jme3.util.BufferUtils.createVector3Buffer(BufferUtils.java:252)
    at com.jme3.scene.shape.Sphere.setGeometryData(Sphere.java:150)
    at com.jme3.scene.shape.Sphere.updateGeometry(Sphere.java:395)
    at com.jme3.scene.shape.Sphere.<init>(Sphere.java:121)
    at mygame.Main.simpleInitApp(Main.java:27)
    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
    at java.lang.Thread.run(Thread.java:722)

Jun 11, 2013 12:10:31 AM com.jme3.renderer.lwjgl.LwjglRenderer cleanup
INFO: Deleting objects and invalidating state
Jun 11, 2013 12:10:31 AM com.jme3.input.lwjgl.LwjglMouseInput destroy
INFO: Mouse destroyed.
Jun 11, 2013 12:10:31 AM com.jme3.input.lwjgl.LwjglKeyInput destroy
INFO: Keyboard destroyed.
Jun 11, 2013 12:10:31 AM com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
INFO: Display destroyed.

可以做些什么?

1 个答案:

答案 0 :(得分:1)

声明球体:Sphere b = new Sphere(1,2,3, true,true);时,前两个参数分别代表zSamples的数量和radialSamples的数量。由于您不能制作边数少于三个的多边形,因此这些值必须至少为3.样本数越多,球体的精度越高。

如果您尝试:

 Sphere b = new Sphere(30,30,1, true,true);

您应该获得所需的结果。