【问题标题】:Java: Plotting 3D points in JMonkeyJava:在 JMonkey 中绘制 3D 点
【发布时间】:2012-05-02 17:06:04
【问题描述】:

谁能给我提供一个如何绘制的例子,比如 JmonkeyEngine 中 x、y、z 范围为 0..100 的 10000 个随机 3D 点。有人建议我使用 Jmonkey 而不是 java3D。我对两者都很陌生。 谢谢

【问题讨论】:

  • 到目前为止你得到了什么?按照 SDK 中包含的一些教程或示例来启动并运行一个应用程序,该应用程序可以渲染一些四边形并具有一个摄像头等。

标签: java java-3d jmonkeyengine


【解决方案1】:

这是在 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;
                        }
                    });
        }
    }
}

【讨论】:

  • 注意; Jmonkey2 正在慢慢贬值,Jmonkey3 在技术上仍处于测试阶段,但它是一个较晚的测试阶段
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-03
  • 2021-03-06
  • 2016-05-28
  • 2015-12-18
  • 2017-04-29
相关资源
最近更新 更多