gpt4 book ai didi

java - jmonkey sphere 运行时错误?

转载 作者:行者123 更新时间:2023-12-01 14:28:08 36 4
gpt4 key购买 nike

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

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.

可以做什么?

最佳答案

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

如果你尝试:

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

您应该获得所需的结果。

关于java - jmonkey sphere 运行时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17030259/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com