Java:在JMonkey中绘制三维点
有人能给我举一个例子,说明如何在JmonkeyEngine中绘制10000个x、y、z范围为0..100的随机3D点。有人建议我使用Jmonkey而不是java3D。我对两者都是新手。Java:在JMonkey中绘制三维点,java,java-3d,jmonkeyengine,Java,Java 3d,Jmonkeyengine,有人能给我举一个例子,说明如何在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.
谢谢这是用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.util.Random;
导入java.util.concurrent.Callable;
导入com.jme.math.Vector3f;
导入com.jme.scene.shape.Sphere;
导入com.jme.util.GameTaskQueueManager;
导入com.jmex.editors.swing.settings.GameSettingsPanel;
导入com.jmex.game.StandardGame;
导入com.jmex.game.state.DebugGameState;
导入com.jmex.game.state.GameStateManager;
公共最终类SphereExample{
专用静态最终整数最大值=100;
专用静态最终整数总计=10000;
公共静态游戏(){
final DebugGameState=new DebugGameState(){
@凌驾
公共无效更新(最终浮动时间步){
//更新游戏状态
super.update(timeStep);
}
};
最终随机数=新随机数();
对于(int i=0;i
这是在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.util.Random;
导入java.util.concurrent.Callable;
导入com.jme.math.Vector3f;
导入com.jme.scene.shape.Sphere;
导入com.jme.util.GameTaskQueueManager;
导入com.jmex.editors.swing.settings.GameSettingsPanel;
导入com.jmex.game.StandardGame;
导入com.jmex.game.state.DebugGameState;
导入com.jmex.game.state.GameStateManager;
公共最终类SphereExample{
专用静态最终整数最大值=100;
专用静态最终整数总计=10000;
公共静态游戏(){
final DebugGameState=new DebugGameState(){
@凌驾
公共无效更新(最终浮动时间步){
//更新游戏状态
super.update(timeStep);
}
};
最终随机数=新随机数();
对于(int i=0;i
到目前为止,您得到了什么?按照SDK中包含的一些教程或示例来启动并运行一个应用程序,该应用程序可以渲染一些四边形,并具有摄像头等。到目前为止,您获得了什么?遵循一些教程或示例