Skip to content

Commit a2425da

Browse files
authored
BAEL-8595: Get started with jmonkeyengine (#18263)
1 parent d755812 commit a2425da

File tree

5 files changed

+207
-0
lines changed

5 files changed

+207
-0
lines changed

jmonkeyengine/pom.xml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>jmonkeyengine</artifactId>
7+
8+
<parent>
9+
<artifactId>parent-modules</artifactId>
10+
<groupId>com.baeldung</groupId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
</parent>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>exec-maven-plugin</artifactId>
19+
<version>1.2.1</version>
20+
<configuration>
21+
<executable>java</executable>
22+
<arguments>
23+
<argument>-XstartOnFirstThread</argument>
24+
<argument>-classpath</argument>
25+
<classpath />
26+
<argument>com.baeldung.jmonkeyengine.FirstApplication</argument>
27+
</arguments>
28+
</configuration>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.jmonkeyengine</groupId>
36+
<artifactId>jme3-core</artifactId>
37+
<version>${jmonkeyengine.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.jmonkeyengine</groupId>
41+
<artifactId>jme3-desktop</artifactId>
42+
<version>${jmonkeyengine.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.jmonkeyengine</groupId>
46+
<artifactId>jme3-lwjgl3</artifactId>
47+
<version>${jmonkeyengine.version}</version>
48+
</dependency>
49+
</dependencies>
50+
51+
<properties>
52+
<jmonkeyengine.version>3.7.0-stable</jmonkeyengine.version>
53+
</properties>
54+
55+
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baeldung.jmonkeyengine;
2+
3+
import com.jme3.app.SimpleApplication;
4+
import com.jme3.system.AppSettings;
5+
6+
public class FirstApplication extends SimpleApplication {
7+
8+
public static void main(String[] args) {
9+
FirstApplication app = new FirstApplication();
10+
app.start();
11+
}
12+
13+
public FirstApplication() {
14+
super();
15+
16+
AppSettings settings = new AppSettings(true);
17+
18+
settings.setWidth(1024);
19+
settings.setHeight(768);
20+
settings.setCenterWindow(false);
21+
settings.setWindowXPosition(0);
22+
settings.setWindowYPosition(0);
23+
settings.setTitle("Our First Application");
24+
25+
setSettings(settings);
26+
}
27+
28+
@Override
29+
public void simpleInitApp() {
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.jmonkeyengine;
2+
3+
import com.jme3.app.SimpleApplication;
4+
import com.jme3.material.Material;
5+
import com.jme3.math.ColorRGBA;
6+
import com.jme3.scene.Geometry;
7+
import com.jme3.scene.Node;
8+
import com.jme3.scene.Spatial;
9+
import com.jme3.scene.shape.Box;
10+
11+
public class GeometryApplication extends SimpleApplication {
12+
13+
public static void main(String[] args) {
14+
GeometryApplication app = new GeometryApplication();
15+
app.start();
16+
}
17+
18+
@Override
19+
public void simpleInitApp() {
20+
Box mesh = new Box(1, 2, 3);
21+
22+
Geometry geometry = new Geometry("Box", mesh);
23+
24+
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
25+
material.setColor("Color", ColorRGBA.Red);
26+
geometry.setMaterial(material);
27+
28+
Node rotation = new Node("rotation");
29+
30+
rotation.attachChild(geometry);
31+
rootNode.attachChild(rotation);
32+
}
33+
34+
@Override
35+
public void simpleUpdate(float tpf) {
36+
Spatial rotation = rootNode.getChild("rotation");
37+
rotation.rotate(0, tpf, 0);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.baeldung.jmonkeyengine;
2+
3+
import com.jme3.app.SimpleApplication;
4+
import com.jme3.app.StatsAppState;
5+
import com.jme3.input.KeyInput;
6+
import com.jme3.input.controls.ActionListener;
7+
import com.jme3.input.controls.AnalogListener;
8+
import com.jme3.input.controls.KeyTrigger;
9+
import com.jme3.material.Material;
10+
import com.jme3.math.ColorRGBA;
11+
import com.jme3.scene.Geometry;
12+
import com.jme3.scene.Node;
13+
import com.jme3.scene.Spatial;
14+
import com.jme3.scene.shape.Box;
15+
16+
public class UserInputApplication extends SimpleApplication {
17+
private boolean rotationEnabled = false;
18+
19+
public static void main(String[] args) {
20+
UserInputApplication app = new UserInputApplication();
21+
app.start();
22+
}
23+
24+
public UserInputApplication() {
25+
super(new StatsAppState());
26+
}
27+
28+
@Override
29+
public void simpleInitApp() {
30+
Box mesh = new Box(1, 2, 3);
31+
32+
Geometry geometry = new Geometry("Box", mesh);
33+
34+
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
35+
material.setColor("Color", ColorRGBA.Red);
36+
geometry.setMaterial(material);
37+
38+
Node rotation = new Node("rotation");
39+
40+
rotation.attachChild(geometry);
41+
rootNode.attachChild(rotation);
42+
43+
inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE));
44+
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));
45+
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));
46+
47+
ActionListener actionListener = new ActionListener() {
48+
@Override
49+
public void onAction(String name, boolean isPressed, float tpf) {
50+
if (name.equals("Rotate") && !isPressed) {
51+
rotationEnabled = !rotationEnabled;
52+
}
53+
}
54+
};
55+
56+
AnalogListener analogListener = new AnalogListener() {
57+
@Override
58+
public void onAnalog(String name, float value, float tpf) {
59+
if (name.equals("Left")) {
60+
rotation.rotate(0, -tpf, 0);
61+
} else if (name.equals("Right")) {
62+
rotation.rotate(0, tpf, 0);
63+
}
64+
}
65+
};
66+
67+
inputManager.addListener(actionListener, "Rotate");
68+
inputManager.addListener(analogListener, "Left", "Right");
69+
}
70+
71+
@Override
72+
public void simpleUpdate(float tpf) {
73+
if (rotationEnabled) {
74+
Spatial rotation = rootNode.getChild("rotation");
75+
rotation.rotate(0, 0, tpf);
76+
}
77+
}
78+
79+
}

pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@
679679
<module>jetbrains</module>
680680
<module>jgit</module>
681681
<module>jmh</module>
682+
<module>jmonkeyengine</module>
682683
<module>json-modules</module>
683684
<module>jsoup</module>
684685
<module>jws</module>
@@ -1067,6 +1068,7 @@
10671068
<module>jetbrains</module>
10681069
<module>jgit</module>
10691070
<module>jmh</module>
1071+
<module>jmonkeyengine</module>
10701072
<module>json-modules</module>
10711073
<module>jsoup</module>
10721074
<module>jws</module>

0 commit comments

Comments
 (0)