diff --git a/jmonkeyengine/pom.xml b/jmonkeyengine/pom.xml new file mode 100644 index 000000000000..8d45d338c2cf --- /dev/null +++ b/jmonkeyengine/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + jmonkeyengine + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + java + + -XstartOnFirstThread + -classpath + + com.baeldung.jmonkeyengine.FirstApplication + + + + + + + + + org.jmonkeyengine + jme3-core + ${jmonkeyengine.version} + + + org.jmonkeyengine + jme3-desktop + ${jmonkeyengine.version} + + + org.jmonkeyengine + jme3-lwjgl3 + ${jmonkeyengine.version} + + + + + 3.7.0-stable + + + + diff --git a/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/FirstApplication.java b/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/FirstApplication.java new file mode 100644 index 000000000000..35880f10f85a --- /dev/null +++ b/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/FirstApplication.java @@ -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() { + } +} diff --git a/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/GeometryApplication.java b/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/GeometryApplication.java new file mode 100644 index 000000000000..0d5fee607ede --- /dev/null +++ b/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/GeometryApplication.java @@ -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); + } +} diff --git a/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/UserInputApplication.java b/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/UserInputApplication.java new file mode 100644 index 000000000000..309e69ca85f0 --- /dev/null +++ b/jmonkeyengine/src/main/java/com/baeldung/jmonkeyengine/UserInputApplication.java @@ -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); + } + } + +} diff --git a/pom.xml b/pom.xml index fb5d831d4273..78091fe55032 100644 --- a/pom.xml +++ b/pom.xml @@ -683,6 +683,7 @@ jetbrains jgit jmh + jmonkeyengine json-modules jsoup jws @@ -1070,6 +1071,7 @@ jetbrains jgit jmh + jmonkeyengine json-modules jsoup jws