这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions jmonkeyengine/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>jmonkeyengine</artifactId>

<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-XstartOnFirstThread</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.baeldung.jmonkeyengine.FirstApplication</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jmonkeyengine</groupId>
<artifactId>jme3-core</artifactId>
<version>${jmonkeyengine.version}</version>
</dependency>
<dependency>
<groupId>org.jmonkeyengine</groupId>
<artifactId>jme3-desktop</artifactId>
<version>${jmonkeyengine.version}</version>
</dependency>
<dependency>
<groupId>org.jmonkeyengine</groupId>
<artifactId>jme3-lwjgl3</artifactId>
<version>${jmonkeyengine.version}</version>
</dependency>
</dependencies>

<properties>
<jmonkeyengine.version>3.7.0-stable</jmonkeyengine.version>
</properties>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.baeldung.jmonkeyengine;

import com.jme3.app.SimpleApplication;
import com.jme3.system.AppSettings;

public class FirstApplication extends SimpleApplication {

public static void main(String[] args) {
FirstApplication app = new FirstApplication();
app.start();
}

public FirstApplication() {
super();

AppSettings settings = new AppSettings(true);

settings.setWidth(1024);
settings.setHeight(768);
settings.setCenterWindow(false);
settings.setWindowXPosition(0);
settings.setWindowYPosition(0);
settings.setTitle("Our First Application");

setSettings(settings);
}

@Override
public void simpleInitApp() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.baeldung.jmonkeyengine;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

public class GeometryApplication extends SimpleApplication {

public static void main(String[] args) {
GeometryApplication app = new GeometryApplication();
app.start();
}

@Override
public void simpleInitApp() {
Box mesh = new Box(1, 2, 3);

Geometry geometry = new Geometry("Box", mesh);

Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", ColorRGBA.Red);
geometry.setMaterial(material);

Node rotation = new Node("rotation");

rotation.attachChild(geometry);
rootNode.attachChild(rotation);
}

@Override
public void simpleUpdate(float tpf) {
Spatial rotation = rootNode.getChild("rotation");
rotation.rotate(0, tpf, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.baeldung.jmonkeyengine;

import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

public class UserInputApplication extends SimpleApplication {
private boolean rotationEnabled = false;

public static void main(String[] args) {
UserInputApplication app = new UserInputApplication();
app.start();
}

public UserInputApplication() {
super(new StatsAppState());
}

@Override
public void simpleInitApp() {
Box mesh = new Box(1, 2, 3);

Geometry geometry = new Geometry("Box", mesh);

Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", ColorRGBA.Red);
geometry.setMaterial(material);

Node rotation = new Node("rotation");

rotation.attachChild(geometry);
rootNode.attachChild(rotation);

inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));

ActionListener actionListener = new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("Rotate") && !isPressed) {
rotationEnabled = !rotationEnabled;
}
}
};

AnalogListener analogListener = new AnalogListener() {
@Override
public void onAnalog(String name, float value, float tpf) {
if (name.equals("Left")) {
rotation.rotate(0, -tpf, 0);
} else if (name.equals("Right")) {
rotation.rotate(0, tpf, 0);
}
}
};

inputManager.addListener(actionListener, "Rotate");
inputManager.addListener(analogListener, "Left", "Right");
}

@Override
public void simpleUpdate(float tpf) {
if (rotationEnabled) {
Spatial rotation = rootNode.getChild("rotation");
rotation.rotate(0, 0, tpf);
}
}

}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@
<module>jetbrains</module>
<module>jgit</module>
<module>jmh</module>
<module>jmonkeyengine</module>
<module>json-modules</module>
<module>jsoup</module>
<module>jws</module>
Expand Down Expand Up @@ -1070,6 +1071,7 @@
<module>jetbrains</module>
<module>jgit</module>
<module>jmh</module>
<module>jmonkeyengine</module>
<module>json-modules</module>
<module>jsoup</module>
<module>jws</module>
Expand Down