merge the new developmentbranch into the test branch #39
@@ -42,7 +42,8 @@ public enum Asset {
|
||||
tankShoot("Models/tank/tank_shoot_bot.obj", "Models/tank/tank_diff.png"),
|
||||
tankShootTop("Models/tank/tank_shoot_top.obj", "Models/tank/tank_diff.png"),
|
||||
treesSmallBackground("Models/treeSmall/small_trees_background.obj", "Models/treeSmall/treeSmall_diff.png", 1.2f),
|
||||
treesBigBackground("Models/treeBig/big_trees_background.obj", "Models/treeBig/treeBig_diff.png", 1.2f)
|
||||
treesBigBackground("Models/treeBig/big_trees_background.obj", "Models/treeBig/treeBig_diff.png", 1.2f),
|
||||
shell
|
||||
;
|
||||
|
||||
private final String modelPath;
|
||||
|
||||
@@ -3,11 +3,16 @@
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.queue.RenderQueue;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.shape.Box;
|
||||
import pp.mdga.client.Asset;
|
||||
import pp.mdga.client.InitControl;
|
||||
import pp.mdga.client.MdgaApp;
|
||||
import pp.mdga.client.acoustic.MdgaSound;
|
||||
@@ -16,6 +21,7 @@
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static com.jme3.material.Materials.LIGHTING;
|
||||
import static com.jme3.material.Materials.UNSHADED;
|
||||
|
||||
public class ShellAnimation extends ActionControl {
|
||||
@@ -28,12 +34,14 @@ public ShellAnimation(TankTopControl tankTopControl, MdgaApp app, Runnable actio
|
||||
super(actionAfter);
|
||||
this.tankTopControl = tankTopControl;
|
||||
this.app = app;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initSpatial() {
|
||||
tankTopControl.rotate(spatial.getLocalTranslation(), this::shoot);
|
||||
app.getAcousticHandler().playSound(MdgaSound.TURRET_ROTATE);
|
||||
app.getRootNode().attachChild(createShell());
|
||||
}
|
||||
|
||||
private Vector3f getShootPos(){
|
||||
@@ -67,14 +75,33 @@ private void shoot(){
|
||||
ColorRGBA.Black
|
||||
);
|
||||
|
||||
Geometry test = new Geometry("test", new Box(0.25f,0.25f,0.25f));
|
||||
test.setMaterial(new Material(app.getAssetManager(), UNSHADED));
|
||||
test.addControl(new MoveControl(shootPos, spatial.getLocalTranslation(),
|
||||
()->{
|
||||
app.getRootNode().detachChild(test);
|
||||
hitExplosion();
|
||||
}, FLYING_HEIGHT, FLYING_DURATION, false));
|
||||
app.getRootNode().attachChild(test);
|
||||
Spatial shell = createShell();
|
||||
shell.addControl(new ShellControl(this::hitExplosion, shootPos, spatial.getLocalTranslation(), FLYING_HEIGHT, FLYING_DURATION));
|
||||
app.getRootNode().attachChild(shell);
|
||||
}
|
||||
|
||||
private Spatial createShell(){
|
||||
Spatial model = app.getAssetManager().loadModel(Asset.shell.getModelPath());
|
||||
model.scale(.16f);
|
||||
model.setLocalTranslation(tankTopControl.getSpatial().getLocalTranslation());
|
||||
|
||||
Vector3f shootPos = tankTopControl.getSpatial().getLocalTranslation();
|
||||
Vector3f targetPos = spatial.getLocalTranslation();
|
||||
Vector3f direction = targetPos.subtract(shootPos).normalize();
|
||||
|
||||
Quaternion rotation = new Quaternion();
|
||||
rotation.lookAt(direction, new Vector3f(1,0,0)); // Assuming UNIT_Y is the up vector
|
||||
|
||||
model.setLocalRotation(rotation);
|
||||
model.rotate(FastMath.HALF_PI,0,0);
|
||||
|
||||
Material mat = new Material(app.getAssetManager(), LIGHTING);
|
||||
mat.setBoolean("UseMaterialColors", true);
|
||||
ColorRGBA color = ColorRGBA.fromRGBA255(143,117,0,255);
|
||||
mat.setColor("Diffuse", color);
|
||||
mat.setColor("Ambient", color);
|
||||
model.setMaterial(mat);
|
||||
return model;
|
||||
}
|
||||
|
||||
private void hitExplosion(){
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package pp.mdga.client.animation;
|
||||
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import pp.mdga.client.InitControl;
|
||||
|
||||
public class ShellControl extends ActionControl {
|
||||
private final Vector3f shootPos;
|
||||
private final Vector3f endPos;
|
||||
private final float height;
|
||||
private final float duration;
|
||||
private Vector3f oldPos;
|
||||
|
||||
public ShellControl(Runnable runnable, Vector3f shootPos, Vector3f endPos, float height, float duration){
|
||||
super(runnable);
|
||||
this.shootPos = shootPos;
|
||||
this.endPos = endPos;
|
||||
this.height = height;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initSpatial() {
|
||||
spatial.addControl(new MoveControl(
|
||||
shootPos,
|
||||
endPos,
|
||||
()->{
|
||||
spatial.removeControl(this);
|
||||
spatial.removeFromParent();
|
||||
action();
|
||||
},
|
||||
height,
|
||||
duration,
|
||||
false
|
||||
));
|
||||
oldPos = spatial.getLocalTranslation().clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
Vector3f direction = spatial.getLocalTranslation().subtract(oldPos).normalize();
|
||||
if (direction.lengthSquared() > 0) {
|
||||
spatial.getLocalRotation().lookAt(direction, Vector3f.UNIT_X);
|
||||
spatial.rotate(FastMath.HALF_PI,0,0);
|
||||
}
|
||||
oldPos = spatial.getLocalTranslation().clone();
|
||||
}
|
||||
}
|
||||
BIN
Projekte/mdga/client/src/main/resources/Models/shell/shell.j3o
Normal file
BIN
Projekte/mdga/client/src/main/resources/Models/shell/shell.j3o
Normal file
Binary file not shown.
Reference in New Issue
Block a user