Package org.spout.api.geo.discrete

Examples of org.spout.api.geo.discrete.Transform


  public EntityObjectMessage(Entity entity, byte type, int throwerId, RepositionManager rm) {
    super(entity);
    this.type = type;
    this.throwerId = throwerId;
    Transform transform = entity.getPhysics().getTransform();
    Point pos = transform.getPosition();

    double p = 32d;
    x = rm.convertX((int) Math.floor(pos.getX() * p));
    y = rm.convertY((int) Math.floor(pos.getY() * p));
    z = rm.convertZ((int) Math.floor(pos.getZ() * p));

    double v = 3.9d;
    Vector3f factor = new Vector3f(v, v, v);

    Vector3f velocity;
    if (entity.getPhysics().isActivated()) {
      velocity = entity.getPhysics().getMovementVelocity(); //TODO: Check if it's alright.
    } else {
      velocity = Vector3f.ZERO;
    }

    velocity = velocity.max(factor.mul(-1)).min(factor);

    double s = 8000d;
    speedX = (short) (velocity.getX() * s);
    speedY = (short) (velocity.getY() * s);
    speedZ = (short) (velocity.getZ() * s);

    final Vector3f axesAngles = transform.getRotation().getAxesAngleDeg();
    pitch = (byte) VanillaByteBufUtils.protocolifyPitch(axesAngles.getX());
    yaw = (byte) VanillaByteBufUtils.protocolifyYaw(axesAngles.getY());
  }
View Full Code Here


   * Gets the transform of this head in the world
   *
   * @return Head transform
   */
  public Transform getHeadTransform() {
    Transform trans = new Transform();
    trans.setPosition(this.getPosition());
    trans.setRotation(getOrientation());
    return trans;
  }
View Full Code Here

      throw new IllegalStateException("Using Vanilla Protocol without using VanillaNetworkSynchronizer");
    }
    if (!position.equals(newPosition)) {
      final Human human = holder.get(Human.class);
      // TODO: live?
      holder.getPhysics().setTransform(new Transform(newPosition, holder.getPhysics().getRotation(), holder.getPhysics().getScale()), false);

      //Don't use client onGround value, calculate ourselves
      //MC Client is on ground if y value is whole number, or half step (e.g 55.0, or 65.5)
      float yDiff = Math.abs(newPosition.getBlockY() - newPosition.getY());
      if (yDiff > 0.4) {
View Full Code Here

  @Override
  public void handleServer(ServerSession session, PlayerLookMessage message) {
    //First look packet is to login/receive terrain, is not a valid rotation
    if (session.getDataMap().get("first_login", 0) == 0) {
      session.getDataMap().put("first_login", 1);
      Transform transform = session.getPlayer().getPhysics().getTransform();
      Player player = session.getPlayer();
      player.getNetwork().callProtocolEvent(new EntityUpdateEvent(player, transform, EntityUpdateEvent.UpdateAction.TRANSFORM, player.getNetwork().getRepositionManager()), player);
      return;
    }

    Player holder = session.getPlayer();

    holder.getPhysics().setTransform(new Transform(holder.getPhysics().getPosition(), Quaternionf.fromAxesAnglesDeg(message.getPitch(), message.getYaw(), 0), holder.getPhysics().getScale()), false);
    Human human = holder.get(Human.class);
    if (human != null) {
      human.setOnGround(message.isOnGround());
      human.getHead().setOrientation(message.getRotation());
    }
View Full Code Here

  }

  @Override
  public List<Message> getUpdateMessages(Entity entity, Transform liveTransform, RepositionManager rm, boolean force) {
    // Movement
    final Transform prevTransform = rm.convert(entity.getPhysics().getTransform());
    final Transform newTransform = rm.convert(liveTransform);

    final boolean looked = entity.getPhysics().isRotationDirty();

    final int lastX = protocolifyPosition(prevTransform.getPosition().getX());
    final int lastY = protocolifyPosition(prevTransform.getPosition().getY());
    final int lastZ = protocolifyPosition(prevTransform.getPosition().getZ());
    final Vector3f lastAxesAngles = prevTransform.getRotation().getAxesAngleDeg();
    final int lastYaw = protocolifyYaw(lastAxesAngles.getY());
    final int lastPitch = protocolifyPitch(lastAxesAngles.getX());

    final int newX = protocolifyPosition(newTransform.getPosition().getX());
    final int newY = protocolifyPosition(newTransform.getPosition().getY());
    final int newZ = protocolifyPosition(newTransform.getPosition().getZ());
    final Vector3f newAxesAngles = newTransform.getRotation().getAxesAngleDeg();
    final int newYaw = protocolifyYaw(newAxesAngles.getY());
    final int newPitch = protocolifyPitch(newAxesAngles.getX());

    final int deltaX = newX - lastX;
    final int deltaY = newY - lastY;
    final int deltaZ = newZ - lastZ;
    final int deltaYaw = newYaw - lastYaw;
    final int deltaPitch = newPitch - lastPitch;

    final List<Message> messages = new ArrayList<Message>();

    /*
     * Two scenarios:
     * - The entity moves more than 4 blocks and maybe changes rotation.
     * - The entity moves less than 4 blocks and maybe changes rotation.
     */
    if (force || deltaX > 128 || deltaX < -128 || deltaY > 128 || deltaY < -128 || deltaZ > 128 || deltaZ < -128) {
      messages.add(new EntityTeleportMessage(entity.getId(), newX, newY, newZ, newYaw, newPitch));
      if (force || looked) {
        messages.add(new EntityYawMessage(entity.getId(), newYaw, newPitch));
      }
    } else if (deltaX != 0 || deltaY != 0 || deltaZ != 0 || deltaYaw != 0 || deltaPitch != 0) {
      if (looked) {
        messages.add(new EntityRelativePositionYawMessage(entity.getId(), deltaX, deltaY, deltaZ, newYaw, newPitch));
      } else if (!prevTransform.getPosition().equals(newTransform.getPosition())) {
        messages.add(new EntityRelativePositionMessage(entity.getId(), deltaX, deltaY, deltaZ));
      }
    }

    // Head movement
View Full Code Here

TOP

Related Classes of org.spout.api.geo.discrete.Transform

Copyright © 2018 www.massapicom. 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.