public void setToInterpolateState(
      EntityRef entity, CharacterStateEvent a, CharacterStateEvent b, long time) {
    float t = (float) (time - a.getTime()) / (b.getTime() - a.getTime());
    Vector3f newPos = BaseVector3f.lerp(a.getPosition(), b.getPosition(), t);
    Quat4f newRot = BaseQuat4f.interpolate(a.getRotation(), b.getRotation(), t);
    LocationComponent location = entity.getComponent(LocationComponent.class);
    location.setWorldPosition(newPos);
    location.setWorldRotation(newRot);
    entity.saveComponent(location);

    CharacterMovementComponent movementComponent =
        entity.getComponent(CharacterMovementComponent.class);
    movementComponent.mode = a.getMode();
    movementComponent.setVelocity(a.getVelocity());
    movementComponent.grounded = a.isGrounded();
    if (b.getFootstepDelta() < a.getFootstepDelta()) {
      movementComponent.footstepDelta =
          t * (1 + b.getFootstepDelta() - a.getFootstepDelta()) + a.getFootstepDelta();
      if (movementComponent.footstepDelta > 1) {
        movementComponent.footstepDelta -= 1;
      }
    } else {
      movementComponent.footstepDelta =
          t * (b.getFootstepDelta() - a.getFootstepDelta()) + a.getFootstepDelta();
    }
    entity.saveComponent(movementComponent);

    extrapolateCharacterComponent(entity, b);
    setPhysicsLocation(entity, newPos);
  }
 private void extrapolateLocationComponent(
     EntityRef entity, CharacterStateEvent state, Vector3f newPos) {
   LocationComponent location = entity.getComponent(LocationComponent.class);
   location.setWorldPosition(newPos);
   location.setWorldRotation(state.getRotation());
   entity.saveComponent(location);
 }
 private void followToParent(final CharacterStateEvent state, EntityRef entity) {
   LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
   if (!locationComponent.getParent().equals(EntityRef.NULL)) {
     Vector3f velocity = new Vector3f(locationComponent.getWorldPosition());
     velocity.sub(state.getPosition());
     state.getVelocity().set(velocity);
     state.getPosition().set(locationComponent.getWorldPosition());
   }
 }
Example #4
0
 @ReceiveEvent
 public void onPlaySound(PlaySoundEvent playSoundEvent, EntityRef entity) {
   LocationComponent location = entity.getComponent(LocationComponent.class);
   if (location != null) {
     audioManager.playSound(
         playSoundEvent.getSound(),
         location.getWorldPosition(),
         playSoundEvent.getVolume(),
         AudioManager.PRIORITY_NORMAL);
   } else {
     audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume());
   }
 }
 private PlayerStoreBuilder createPlayerStore(Client client, EntityRef character) {
   LocationComponent location = character.getComponent(LocationComponent.class);
   Vector3f relevanceLocation;
   if (location != null) {
     relevanceLocation = location.getWorldPosition();
   } else {
     relevanceLocation = new Vector3f();
   }
   Long characterId;
   if (character.exists()) {
     characterId = character.getId();
   } else {
     characterId = null;
   }
   return new PlayerStoreBuilder(characterId, relevanceLocation);
 }
 /**
  * Sets the state of the given entity to the state represented by the CharacterStateEvent. The
  * state of the entity is determined by its LocationComponent (location and orientation of physics
  * body), CharacterMovementComponent (velocity and various movement state variables) and
  * CharacterComponent for pitch and yaw (used for the camera).
  *
  * @param entity
  * @param state
  */
 public void setToState(EntityRef entity, CharacterStateEvent state) {
   LocationComponent location = entity.getComponent(LocationComponent.class);
   CharacterMovementComponent movementComp = entity.getComponent(CharacterMovementComponent.class);
   CharacterComponent characterComponent = entity.getComponent(CharacterComponent.class);
   if (location == null || movementComp == null || characterComponent == null) {
     return;
   }
   location.setWorldPosition(state.getPosition());
   location.setWorldRotation(state.getRotation());
   entity.saveComponent(location);
   movementComp.mode = state.getMode();
   movementComp.setVelocity(state.getVelocity());
   movementComp.grounded = state.isGrounded();
   movementComp.footstepDelta = state.getFootstepDelta();
   entity.saveComponent(movementComp);
   characterComponent.pitch = state.getPitch();
   characterComponent.yaw = state.getYaw();
   entity.saveComponent(characterComponent);
   setPhysicsLocation(entity, state.getPosition());
 }
  public static void setToExtrapolateState(EntityRef entity, CharacterStateEvent state, long time) {
    float t = (time - state.getTime()) * 0.0001f;
    Vector3f newPos = new Vector3f(state.getVelocity());
    newPos.scale(t);
    newPos.add(state.getPosition());
    LocationComponent location = entity.getComponent(LocationComponent.class);
    location.setWorldPosition(newPos);
    location.setWorldRotation(state.getRotation());
    entity.saveComponent(location);

    CharacterMovementComponent movementComponent =
        entity.getComponent(CharacterMovementComponent.class);
    movementComponent.mode = state.getMode();
    movementComponent.setVelocity(state.getVelocity());
    movementComponent.grounded = state.isGrounded();
    entity.saveComponent(movementComponent);

    CharacterComponent characterComponent = entity.getComponent(CharacterComponent.class);
    characterComponent.pitch = state.pitch;
    characterComponent.yaw = state.yaw;
    entity.saveComponent(characterComponent);
    setPhysicsLocation(entity, newPos);
  }