Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mygame;
- import com.jme3.app.SimpleApplication;
- import com.jme3.material.Material;
- import com.jme3.math.Vector3f;
- import com.jme3.scene.Geometry;
- import com.jme3.scene.shape.Box;
- import com.jme3.math.ColorRGBA;
- import com.jme3.input.KeyInput;
- import com.jme3.input.MouseInput;
- import com.jme3.input.controls.ActionListener;
- import com.jme3.input.controls.AnalogListener;
- import com.jme3.input.controls.KeyTrigger;
- import com.jme3.input.controls.MouseButtonTrigger;
- import com.jme3.light.AmbientLight;
- import com.jme3.light.DirectionalLight;
- import com.jme3.light.PointLight;
- import com.jme3.math.FastMath;
- import com.jme3.math.Quaternion;
- import com.jme3.scene.Node;
- import com.jme3.scene.Spatial;
- import com.jme3.scene.shape.Sphere;
- import com.jme3.texture.Texture;
- import com.jme3.util.TangentBinormalGenerator;
- import java.util.LinkedList;
- import java.util.List;
- /** Sample 5 - how to map keys and mousebuttons to actions */
- public class Main extends SimpleA {
- public static void main(String[] args) {
- Main app = new Main();
- app.start();
- }
- //protected Geometry player;
- Boolean isRunning = true;
- float angle;
- Geometry lightMdl;
- Vector3f posLuz = new Vector3f(0, -2, -2);
- private PointLight pl;
- @Override
- public void simpleInitApp() {
- flyCam.setMoveSpeed(5f);
- pl = new PointLight();
- pl.setColor(ColorRGBA.White);
- pl.setPosition(posLuz);
- pl.setRadius(4f);
- rootNode.addLight(pl);
- AmbientLight al = new AmbientLight();
- al.setColor(ColorRGBA.White);
- rootNode.addLight(al);
- //rootNode.attachChild(fazBloco(0,0,0));
- this.lightMdl = miniBloco(posLuz);
- Geometry bloco1 = fazBloco(0,0,0);
- // Geometry bloco2 = fazBlocoToon(2,2,0);
- rootNode.attachChild(bloco1);
- // rootNode.attachChild(bloco2);
- //rootNode.attachChild(fazBloco(6,0,0));
- rootNode.attachChild(lightMdl);
- DirectionalLight sun = new DirectionalLight();
- sun.setDirection(posLuz);
- sun.setColor(ColorRGBA.White);
- rootNode.addLight(sun);
- initKeys(); // load my custom keybinding
- }
- public Geometry fazBlocoToon(int x, int y, int z) {
- Box boxshape1 = new Box(new Vector3f(x, y, z), 3, 0.5f, 1);
- Geometry g = new Geometry("BoxToon", boxshape1);
- Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
- Texture t = assetManager.loadTexture("Textures/bloco.png");
- m.setTexture("ColorRamp", t);
- m.setBoolean("UseMaterialColors", true);
- m.setColor("Specular", ColorRGBA.Black);
- m.setColor("Diffuse", ColorRGBA.White);
- m.setBoolean("VertexLighting", true);
- g.setMaterial(m);
- return g;
- }
- public Geometry fazBloco(int x, int y, int z) {
- Box boxshape1 = new Box(new Vector3f(x, y, z), 3, 0.5f, 1);
- Geometry cube = new Geometry("My Textured Box", boxshape1);
- //TangentBinormalGenerator.generate(boxshape1);
- Material mat_stl = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
- Texture tex_ml = assetManager.loadTexture("Textures/bloco.png");
- mat_stl.setTexture("DiffuseMap", tex_ml);
- // mat_stl.setFloat("m_Shininess", 12);
- mat_stl.setBoolean("m_UseMaterialColors", true);
- //mat_stl.setTexture("m_ColorRamp", assetManager.loadTexture("Textures/ColorRamp/cloudy.png"));
- //
- // mat.setBoolean("m_VTangent", true);
- // mat.setBoolean("m_Minnaert", true);
- // mat.setBoolean("m_WardIso", true);
- mat_stl.setBoolean("m_VertexLighting", true);
- // mat.setBoolean("m_LowQuality", true);
- mat_stl.setBoolean("m_HighQuality", true);
- mat_stl.setColor("m_Ambient", ColorRGBA.Black);
- mat_stl.setColor("m_Diffuse", ColorRGBA.Gray);
- mat_stl.setColor("m_Specular", ColorRGBA.Gray);
- cube.setMaterial(mat_stl);
- return cube;
- }
- public Geometry miniBloco(Vector3f v) {
- Box boxshape1 = new Box(v, 0.5f, 0.5f, 0.5f);
- Geometry cube = new Geometry("My Textured Box", boxshape1);
- //TangentBinormalGenerator.generate(boxshape1);
- Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- Texture tex_ml = assetManager.loadTexture("Textures/bloco.png");
- mat_stl.setTexture("m_ColorMap", tex_ml);
- cube.setMaterial(mat_stl);
- this.lightMdl = cube;
- return cube;
- }
- /** Custom Keybinding: Map named actions to inputs. */
- private void initKeys() {
- // You can map one or several inputs to one named action
- inputManager.addMapping("Pause", new KeyTrigger(KeyInput.KEY_P));
- inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));
- inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));
- inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE),
- new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
- // Add the names to the action listener.
- inputManager.addListener(actionListener, new String[]{"Pause"});
- // inputManager.addListener(analogListener, new String[]{"Left", "Right", "Rotate"});
- }
- private ActionListener actionListener = new ActionListener() {
- public void onAction(String name, boolean keyPressed, float tpf) {
- if (name.equals("Pause") && !keyPressed) {
- isRunning = !isRunning;
- }
- }
- };
- @Override
- public void simpleUpdate(float tpf) {
- // cam.setLocation(new Vector3f(2.0632997f, 1.9493936f, 2.6885238f));
- // cam.setRotation(new Quaternion(-0.053555284f, 0.9407851f, -0.17754152f, -0.28378546f));
- angle += tpf;
- angle %= FastMath.TWO_PI;
- pl.setPosition(new Vector3f(FastMath.cos(angle) * 2f, 1, FastMath.sin(angle) * 2f));
- posLuz = pl.getPosition();
- this.lightMdl.setLocalTranslation(posLuz);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement