Beispiel #1
0
  /**
   * Called at every frame update.
   *
   * @param frame Frame information
   */
  public void update(FrameInput frame) {

    // Notify to components
    for (Component component : components.values()) {
      component.update(frame);
    }

    // Notify to children
    for (Entity child : children) {
      child.update(frame);
    }

    // Update local model matrix if necessary.
    if (localMatrixUpdateRequired) {
      updateLocalMatrix();
      invalidateWorldModelMatrix();
      localMatrixUpdateRequired = false;
    }

    // Update world model matrix if necessary.
    if (worldMatrixUpdateRequired) {
      updateWorldModelMatrix();
      worldMatrixUpdateRequired = false;

      // Update native side values
      worldModelMatrix.get(matrixValues);
      setWorldModelMatrix(nativePointer.get(), matrixValues);
    }

    // Update opacity if necessary.
    if (updateOpacityRequired) {
      updateOpacity();
      updateOpacityRequired = false;
    }
  }
Beispiel #2
0
  /**
   * Create Entity from {@link Drawable}. New Entity has plane geometry.
   *
   * @param drawable Drawable for surface.
   * @return new Entity
   */
  public static Entity from(Drawable drawable) {

    final Entity entity = new Entity();
    entity.add(SurfaceRendererComponent.from(drawable));
    entity.add(GeometryComponent.from(drawable));

    return entity;
  }
Beispiel #3
0
  /**
   * Create Entity from {@link View}. New Entity has plane geometry.
   *
   * @param view View for surface.
   * @return new Entity
   */
  public static Entity from(View view) {

    final Entity entity = new Entity();
    entity.add(SurfaceRendererComponent.from(view));
    entity.add(GeometryComponent.from(view));

    return entity;
  }
Beispiel #4
0
 /**
  * Add child {@link Entity}.
  *
  * @param child Child entity.
  * @return {@code true} if Successfully added. Otherwise {@code false}.
  */
 public boolean add(Entity child) {
   final boolean added = children.add(child);
   if (added) {
     child.parent = this;
     child.setApp(app);
   }
   return added;
 }
Beispiel #5
0
  /**
   * For internal use only.
   *
   * @param app
   */
  void setApp(MeganekkoApp app) {
    this.app = app;

    // Propagate to children
    for (Entity child : children) {
      child.setApp(app);
    }
  }
Beispiel #6
0
  private void invalidateWorldModelMatrix() {

    worldMatrixUpdateRequired = true;

    // Propagate to children
    for (Entity child : children) {
      child.invalidateWorldModelMatrix();
    }
  }
Beispiel #7
0
  /** @return {@code true} if this entity and ancestors are all visible. Otherwise {@code false}. */
  public boolean isShown() {

    if (!visible) return false;

    // Check parent visibility
    Entity parent = getParent();
    if (parent == null) return true;

    return parent.isShown();
  }
Beispiel #8
0
  /**
   * For internal use only.
   *
   * @param surfacesPointer {@code &res.Surfaces}
   */
  void collectSurfaceDefs(long surfacesPointer) {

    // Not visible
    if (!visible) return;

    addSurfaceDef(nativePointer.get(), surfacesPointer);

    for (Entity child : children) {
      child.collectSurfaceDefs(surfacesPointer);
    }
  }
Beispiel #9
0
  private void updateOpacity() {

    SurfaceRendererComponent surfaceRendererComponent =
        getComponent(SurfaceRendererComponent.class);
    if (surfaceRendererComponent != null) {
      surfaceRendererComponent.setOpacity(getRenderingOpacity());
    }

    for (Entity child : children) {
      child.updateOpacity();
    }
  }
Beispiel #10
0
  /**
   * Find {@link Entity} from children. Typically, id is {@code R.id.xxx} value.
   *
   * @param id ID
   * @return Found Entity or {@code null} if it has no matched Entity with id.
   */
  @Nullable
  public Entity findById(int id) {

    if (this.id == id) return this;

    for (Entity child : children) {
      Entity found = child.findById(id);
      if (found != null) return found;
    }

    return null;
  }
Beispiel #11
0
  /** Update world model matrix. */
  public void updateWorldModelMatrix() {

    // parentMatrix * worldModelMatrix
    Entity parent = getParent();
    if (parent != null) {
      Matrix4f parentMatrix = parent.getWorldModelMatrix();
      parentMatrix.mul(localMatrix, worldModelMatrix);
    } else {

      // worldModelMatrix = localMatrix
      worldModelMatrix.set(localMatrix);
    }
  }
Beispiel #12
0
 /**
  * Remove child {@link Entity}.
  *
  * @param child Child entity.
  * @return {@code true} if Successfully removed. Otherwise {@code false}.
  */
 public boolean remove(Entity child) {
   final boolean removed = children.remove(child);
   if (removed) {
     child.parent = null;
   }
   return removed;
 }
Beispiel #13
0
 private float parentOpacity() {
   Entity parent = getParent();
   return parent != null ? parent.getOpacity() : 1.0f;
 }
Beispiel #14
0
 /**
  * Remove this from scene graph.
  *
  * @return {@code true} if Successfully removed. Otherwise {@code false}.
  * @since 3.0.17
  */
 public boolean remove() {
   return parent != null && parent.remove(this);
 }