Skip to content

Instantly share code, notes, and snippets.

@larien
Last active March 13, 2019 01:27
Show Gist options
  • Save larien/cd481195f97d14ad09342078a406b403 to your computer and use it in GitHub Desktop.
Save larien/cd481195f97d14ad09342078a406b403 to your computer and use it in GitHub Desktop.
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
*
* @author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
/**
* A white, directional light source
*/
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
Spatial ninja = createNinja(i, j);
rootNode.attachChild(ninja);
}
}
}
public Spatial createNinja(int x, int z){
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
ninja.scale(0.02f);
ninja.setLocalTranslation(new Vector3f(-x*2,0,z*2));
ninja.move(5, 0, 0);
return ninja;
}
@Override
public void simpleUpdate(float tpf) {
rootNode.move(0, 0, tpf);
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
createBox(ColorRGBA.randomColor(), 1, 1, 1);
createBox(ColorRGBA.randomColor(), 1, 4, 1);
}
public void createBox(ColorRGBA color, int x, int y, int z) {
Box b = new Box(1, 1, 1);
// Sphere s = new Sphere(1, 1, 1)
Geometry geom = new Geometry("Box", b);
geom.setLocalTranslation(new Vector3f(x,y,z));
geom.scale(0.5f);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", color);
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
@Override
public void simpleUpdate(float tpf) {
rootNode.getChild("Box").move(0, 0, tpf);
if (Math.abs(rootNode.getChild("Box").getLocalTranslation().z) > 10){
tpf--;
}
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
*
* @author normenhansen
*/
public class Main2 extends SimpleApplication {
public static void main(String[] args) {
Main2 app = new Main2();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
Node n1 = new Node("pivot1");
Node n2 = new Node("pivot2");
for(int i=0; i<5;i++){
Geometry p = getBacon("bn1"+i);
p.setLocalTranslation(i*2, 0, 0);
n1.attachChild(p);
p = getBacon("bn2"+i);
p.setLocalTranslation(0, i*2, 0);
n2.attachChild(p);
}
rootNode.attachChild(n1);
rootNode.attachChild(n2);
}
public Geometry getBacon(String name){
/**
* An unshaded textured cube. Uses texture from jme3-test-data library!
*/
Box boxMesh = new Box(1f, 1f, 1f);
Geometry boxGeo = new Geometry("A Textured Box", boxMesh);
Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture monkeyTex = assetManager.loadTexture("Textures/bacon.jpg");
boxMat.setTexture("ColorMap", monkeyTex);
boxGeo.setMaterial(boxMat);
return boxGeo;
}
@Override
public void simpleUpdate(float tpf) {
// rootNode.getChild("Box").rotate(0, 0, tpf); // rotaciona caixa
rootNode.rotate(tpf, tpf, tpf); // rotaciona o nó raiz e seus filhos, em torno da origem
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
*
* @author normenhansen
*/
public class Main2 extends SimpleApplication {
public static void main(String[] args) {
Main2 app = new Main2();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
Node n1 = new Node("pivot1");
Node n2 = new Node("pivot2");
for(int i=0; i<5;i++){
Geometry p = getBacon("bn1"+i);
p.setLocalTranslation(i*2, 0, 0);
n1.attachChild(p);
p = getBacon("bn2"+i);
p.setLocalTranslation(0, i*2, 0);
n2.attachChild(p);
}
rootNode.attachChild(n1);
rootNode.attachChild(n2);
}
public Geometry getBacon(String name){
/**
* An unshaded textured cube. Uses texture from jme3-test-data library!
*/
Box boxMesh = new Box(1f, 1f, 1f);
Geometry boxGeo = new Geometry("A Textured Box", boxMesh);
Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture monkeyTex = assetManager.loadTexture("Textures/bacon.jpg");
boxMat.setTexture("ColorMap", monkeyTex);
boxGeo.setMaterial(boxMat);
return boxGeo;
}
@Override
public void simpleUpdate(float tpf) {
// rootNode.getChild("Box").rotate(0, 0, tpf); // rotaciona caixa
rootNode.rotate(tpf, tpf, tpf); // rotaciona o nó raiz e seus filhos, em torno da origem
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
*
* @author normenhansen
*/
public class Main3 extends SimpleApplication {
public static void main(String[] args) {
Main3 app = new Main3();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
/**
* A white, directional light source
*/
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
// Material defaultMat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
// ninja.setMaterial(defaultMat);
ninja.scale(0.02f);
ninja.rotate(0, FastMath.PI, 0);
rootNode.attachChild(ninja);
Spatial ferrari = assetManager.loadModel("Models/Ferrari/Car.mesh.xml");
ferrari.rotate(0, FastMath.PI, 0);
ferrari.setLocalTranslation(new Vector3f(-5,1,1));
rootNode.attachChild(ferrari);
}
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
*
* @author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
/**
* A white, directional light source
*/
DirectionalLight sun = new DirectionalLight();
sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
ninja.scale(0.02f);
ninja.rotate(1, FastMath.PI, 0);
rootNode.attachChild(ninja);
Spatial ferrari = assetManager.loadModel("Models/Ferrari/Car.mesh.xml");
ferrari.rotate(-1, FastMath.PI, 0);
ferrari.setLocalTranslation(new Vector3f(-3,1,1));
rootNode.attachChild(ferrari);
Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
elephant.scale(0.02f);
elephant.rotate(2, FastMath.PI, 0);
elephant.setLocalTranslation(new Vector3f(3,1,1));
rootNode.attachChild(elephant);
Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
teapot.rotate(-2, FastMath.PI, 0);
teapot.setLocalTranslation(new Vector3f(8,1,1));
rootNode.attachChild(teapot);
Spatial boat = assetManager.loadModel("Models/Boat/boat.mesh.xml");
boat.rotate(0, FastMath.PI, 0);
boat.setLocalTranslation(new Vector3f(-8,1,1));
rootNode.attachChild(boat);
}
@Override
public void simpleUpdate(float tpf) {
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment