コード例 #1
0
  private void manage(Entity e, float elapsedTime) {
    Model model = e.get(Model.class);
    if (!model.isCreated()) return;

    PlanarStance stance = e.get(PlanarStance.class);
    Spatial s = SpatialPool.models.get(e.getId());

    // translation
    s.setLocalTranslation(TranslateUtil.toVector3f(stance.getCoord().get3D(stance.getElevation())));

    // rotation
    Quaternion r = new Quaternion();
    Point3D pu = stance.getUpVector();
    Point3D pv = stance.getPlanarVector();
    Vector3f u = TranslateUtil.toVector3f(pu).normalize();
    Vector3f v = TranslateUtil.toVector3f(pv).normalize();
    r.lookAt(v, u);

    // we correct the pitch of the unit because the direction is always flatten
    // this is only to follow the terrain relief
    double angle = Math.acos(pu.getDotProduct(pv) / (pu.getNorm() * pv.getNorm()));
    r =
        r.mult(
            new Quaternion()
                .fromAngles(
                    (float) (-angle + AngleUtil.RIGHT + model.getPitchFix()),
                    (float) (model.getRollFix()),
                    (float) (model.getYawFix())));

    s.setLocalRotation(r);
  }
コード例 #2
0
  private void manage(Entity e, float elapsedTime) {
    Physic ph = e.get(Physic.class);
    PlanarStance stance = e.get(PlanarStance.class);
    MotionCapacity capacity = e.get(MotionCapacity.class);

    Point2D velocityToApply = e.get(PlanarVelocityToApply.class).getVector();
    velocityToApply = velocityToApply.getMult(1 / ph.stat.mass);

    Point2D newVelocity = ph.velocity.getAddition(velocityToApply);
    newVelocity = newVelocity.getTruncation(capacity.maxSpeed);
    Point2D newCoord = stance.getCoord().getAddition(newVelocity.getMult(elapsedTime));

    setComp(e, new Physic(newVelocity, ph.stat, ph.spawnerException));
    setComp(
        e,
        new PlanarStance(
            newCoord, stance.getOrientation(), stance.getElevation(), stance.getUpVector()));
    setComp(e, new PlanarVelocityToApply(Point2D.ORIGIN));
  }