Java:在 JMonkey 中绘制 3D 点

标签 java java-3d jmonkeyengine

有人可以给我提供一个如何在 JmonkeyEngine 中绘制 10000 个随机 3D 点(x、y、z 范围为 0..100)的示例吗?有人建议我使用 Jmonkey 而不是 java3D。我对两者都是新手。 谢谢

最佳答案

这是用 JMonkey2 制作的。下面的代码在 0 到 100 之间生成了 10000 个球体。这最终形成一个几乎满了的盒子。使用WASD控制相机。

package wall;

import java.util.Random;
import java.util.concurrent.Callable;

import com.jme.math.Vector3f;
import com.jme.scene.shape.Sphere;
import com.jme.util.GameTaskQueueManager;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;

public final class SphereExample {

    private static final int MAX = 100;
    private static final int TOTAL = 10000;

    public static void setupGame() {
        final DebugGameState state = new DebugGameState() {
            @Override
            public void update(final float timeStep) {

                // Update the game state
                super.update(timeStep);
            }
        };
        final Random random = new Random();
        for (int i = 0; i < TOTAL; i++) {
            final Sphere sphere = new Sphere("sphere", 5, 5, 1);
            sphere.setLocalTranslation(random.nextInt(MAX),
                    random.nextInt(MAX), random.nextInt(MAX));
            sphere.updateRenderState();
            state.getRootNode().attachChild(sphere);
        }

        GameStateManager.getInstance().attachChild(state);
        state.setActive(true);

    }

    public static void main(final String[] args) throws Exception {

        final StandardGame game = new StandardGame("Points");

        if (GameSettingsPanel.prompt(game.getSettings())) {

            game.start();

            GameTaskQueueManager.getManager().update(
                    new Callable<Void>() {
                        @Override
                        public Void call() throws Exception {
                            setupGame();
                            game.getCamera() // moves the camera to the middle
                                             // of the spheres
                                    .setFrame(
                                            new Vector3f(50.0f,
                                                    50.0f, 50.0f),
                                            new Vector3f(-1.0f, 0.0f,
                                                    0.0f),
                                            new Vector3f(0.0f, 1.0f,
                                                    0.0f),
                                            new Vector3f(0.0f, 0.0f,
                                                    -1.0f));
                            game.getCamera().update();
                            game.getCamera().apply();
                            return null;
                        }
                    });
        }
    }
}

关于Java:在 JMonkey 中绘制 3D 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10418433/

相关文章:

java - 对于 OWL A 级;获取 A 为其域的所有属性

java - Xpages:在 EL 中的 CacheBean 中调用 java 方法时出错

java - 在 Activity 之间传递 LinkedList

处理jgroups集群中节点故障的Java代码

java - jMonkeyEngine - 像在第一人称游戏中一样用鼠标旋转

java - 键盘输入 JOGL

java - 将 Java 3d 对象写入自定义文件类型

algorithm - 如何定位相机以使我的主要对象完全可见并适合屏幕?

java - J-猴子子类

java - JMonkey - 向十字线方向射击