Package bomb

Source Code of bomb.BombPhysicalObject

package bomb;

import java.util.Random;
import javafx.scene.media.AudioClip;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Quat4d;
import javax.vecmath.Vector3d;
import mainPac.PhysicalObject;
import mainPac.SimulationEntity;
import physics.QuatUtil;

public class BombPhysicalObject extends PhysicalObject {

    private static final Vector3d GRAVITY = new Vector3d(0, 0.02, 0);
    private static final Vector3d FORWARD = new Vector3d(1, 0, 0);
    private static final Vector3d LEFT = new Vector3d(-1, 0, 0);
    private static final Vector3d UP = new Vector3d(0, -1, 0);
    private Vector3d orientationUp;
    private Vector3d orientationForward;
    private double attackAngle;
    private Random rand = new Random();

    public BombPhysicalObject() {
    }

    @Override
    public void stepSimulation() {
        calculateValues();
        super.stepSimulation();
        speed.add(GRAVITY);
        align();
    }

    private void calculateValues() {
        orientationForward = QuatUtil.rotateVector(FORWARD, orientation);
        orientationUp = QuatUtil.rotateVector(UP, orientation);
        attackAngle = orientationUp.angle(speed) - Math.PI / 2.0;
    }

    private void align() {
        if (Math.abs(attackAngle) < 0.25) {
            return;
        }
        Quat4d quat = new Quat4d();
        quat.set(new AxisAngle4d(0, 0, 1, attackAngle * 0.01));
        rotationSpeed.mul(quat);
    }

    public void launch() {
        setRotationSpeed(new Quat4d(0,0,0,1));
        Quat4d q = new Quat4d();
        double angle= -Math.PI/2.0-(rand.nextDouble()-0.5);
        q.set(new AxisAngle4d(0, 0, 1, angle));
        setOrientation(q);
        orientationForward = QuatUtil.rotateVector(FORWARD, orientation);
        orientationForward.scale(8);
        setSpeed(orientationForward);
    }
}
TOP

Related Classes of bomb.BombPhysicalObject

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.