/**
*
*/
package net.cis.client.game;
import net.cis.client.game.scenery.ctrl.ShotController;
import net.cis.client.game.scenery.factory.SkyBoxFactory;
import com.jme3.app.SimpleApplication;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.Spatial.CullHint;
/**
* @author Matze
*
*/
public class TestShot extends SimpleApplication implements ActionListener {
/*
* (non-Javadoc)
*
* @see com.jme3.app.SimpleApplication#simpleInitApp()
*/
@Override
public void simpleInitApp() {
initializeScenery();
initializeInput();
}
private void initializeScenery() {
// Skybox
rootNode.attachChild(SkyBoxFactory.createSimpleSkyBox(assetManager));
// Asteroid
Spatial asteroid = assetManager.loadModel("spaceobject/asteroid/dusty/Asteroid.mesh.xml");
asteroid.setLocalTranslation(10.0f, -5.0f, -2.0f);
Material mat_asteroid = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_asteroid.setTexture("ColorMap",
assetManager.loadTexture("spaceobject/asteroid/dusty/asteroidtextur_512.jpg"));
asteroid.setMaterial(mat_asteroid);
rootNode.attachChild(asteroid);
// Light
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
rootNode.addLight(sun);
}
private void initializeInput() {
inputManager.addMapping("Shoot", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, "Shoot");
}
protected Geometry makeSphere(String name, float radius) {
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 50);
Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Smoke/Smoke.png"));
fire.setMaterial(mat_red);
fire.setImagesX(15);
fire.setEndColor(new ColorRGBA(0f, 0f, 1f, 1f));
fire.setStartColor(new ColorRGBA(0f, 1f, 1f, 0.5f));
fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, .5f, 0));
fire.setGravity(0, 0, 0);
fire.setLowLife(1f);
fire.setHighLife(1.1f);
fire.getParticleInfluencer().setVelocityVariation(1f);
// Cylinder quad = new Cylinder(10, 10, 1f,3f);
// Geometry sphereG = new Geometry(name, quad);
// Material material = new Material(assetManager,
// "Common/MatDefs/Misc/Unshaded.j3md");
// Texture texture = assetManager
// .loadTexture("Effects/Explosion/shockwave.png");
// material.setTexture("ColorMap", texture);
// material.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);
// material.setTexture("GlowMap", texture);
// material.setColor("Color", new ColorRGBA(0f, 0f, 1f, 1f));
// sphereG.setMaterial(material);
//
// sphereG.setQueueBucket(Bucket.Transparent);
//
// return sphereG;
return fire;
}
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("Shoot") && !isPressed) {
Geometry shot = makeSphere("shot", 0.2f);
shot.setLocalTranslation(cam.getDirection());
shot.addControl(new ShotController(1f, 0.01f, cam.getDirection()));
rootNode.attachChild(shot);
shot.setCullHint(CullHint.Never);
}
}
public static void main(String[] args) {
new TestShot().start();
}
}