0

In jmonkey I have seen their first tutorial, it was moving a box on mouse movement, out of curiosity and as for playing with this new toy I have tried to move a Sphere using mouse movement. Since the functionality is almost same I have replaced Box with 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);
}

But it compile but does not work, it returns following run time error on that line where I have created an instance of 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.

what can be done?

4

1 回答 1

1

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

如果你试试:

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

你应该得到想要的结果。

于 2013-06-16T08:07:30.887 回答