繁体   English   中英

Java:在JMonkey中绘制3D点

[英]Java: Plotting 3D points in JMonkey

有人可以给我提供一个如何绘制示例的例子,在JmonkeyEngine中说10000个x,y,z范围为0..100的随机3D点。 建议我使用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;
                        }
                    });
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM