Ejemplo n.º 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;
    }
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 6
0
  private void invalidateWorldModelMatrix() {

    worldMatrixUpdateRequired = true;

    // Propagate to children
    for (Entity child : children) {
      child.invalidateWorldModelMatrix();
    }
  }
Ejemplo n.º 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();
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 9
0
  private void updateOpacity() {

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

    for (Entity child : children) {
      child.updateOpacity();
    }
  }
Ejemplo n.º 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;
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 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;
 }
Ejemplo n.º 13
0
 private float parentOpacity() {
   Entity parent = getParent();
   return parent != null ? parent.getOpacity() : 1.0f;
 }
Ejemplo n.º 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);
 }