Android Open Source - android-plotter Surface Initializer






From Project

Back to project page android-plotter.

License

The source code is released under:

Apache License

If you think the Android project android-plotter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.solovyev.android.plotter.meshes;
//from  w  w  w . j  a  v a 2 s .  co m
import android.graphics.RectF;
import org.solovyev.android.plotter.Dimensions;

import javax.annotation.Nonnull;

class SurfaceInitializer {

  @Nonnull
  private final BaseSurface surface;

  @Nonnull
  private final Data data;

  SurfaceInitializer(@Nonnull BaseSurface surface, @Nonnull Data data) {
    this.data = data;
    this.surface = surface;
  }

  @Nonnull
  public static SurfaceInitializer createForGraph(@Nonnull BaseSurface surface, @Nonnull Dimensions.Graph graph) {
    return new SurfaceInitializer(surface, Data.create(graph.rect));
  }

  @Nonnull
  public static SurfaceInitializer create(@Nonnull BaseSurface surface, @Nonnull RectF bounds) {
    return new SurfaceInitializer(surface, Data.create(bounds));
  }

  public void init(@Nonnull Arrays arrays) {
    arrays.init(3 * data.totalVertices(), data.totalVertices());

    final float dx = data.dx();
    final float dy = data.dy();

    final float[] point = new float[3];

    int vertex = 0;
    for (int yi = 0; yi < data.yVertices; yi++) {
      final float y = data.bounds.top + yi * dy;
      final boolean yEven = yi % 2 == 0;

      for (int xi = 0; xi < data.xVertices; xi++) {
        final boolean xEven = xi % 2 == 0;
        int ii = xi * (data.yVertices - 1) + xi;
        int iv = yi * (data.xVertices - 1) + yi;
        if (xEven) {
          ii += yi;
        } else {
          ii += (data.yVertices - 1 - yi);
        }
        if (yEven) {
          iv += xi;
        } else {
          iv += (data.xVertices - 1 - xi);
        }

        final float x;
        if (yEven) {
          // going right
          x = data.bounds.left + xi * dx;
        } else {
          // going left
          x = data.bounds.right - xi * dx;
        }

        final float z = surface.z(x, y, xi, yi);

        point[0] = x;
        point[1] = y;
        point[2] = z;

        scale(point);
        rotate(point);

        arrays.indices[ii] = (short) iv;
        arrays.vertices[vertex++] = point[0];
        arrays.vertices[vertex++] = point[2];
        arrays.vertices[vertex++] = point[1];
      }
    }
  }

  protected void rotate(float[] point) {
  }

  protected void scale(float[] point) {
  }

  final static class Data {

    @Nonnull
    final RectF bounds = new RectF();
    int xVertices;
    int yVertices;

    @Nonnull
    public static Data create(@Nonnull RectF bounds) {
      return create(bounds, 20, 20);
    }

    @Nonnull
    public static Data create(@Nonnull RectF bounds, int xVertices, int yVertices) {
      final Data data = new Data();
      data.bounds.set(bounds);
      data.xVertices = xVertices;
      data.yVertices = yVertices;
      return data;
    }

    private float dy() {
      return bounds.height() / (yVertices - 1);
    }

    private float dx() {
      return bounds.width() / (xVertices - 1);
    }

    private int totalVertices() {
      return xVertices *yVertices;
    }
  }

  public static class GraphSurfaceInitializer extends SurfaceInitializer {

    @Nonnull
    private final Dimensions.Graph graph;

    public GraphSurfaceInitializer(@Nonnull BaseSurface surface, @Nonnull Dimensions.Graph graph) {
      super(surface, Data.create(graph.rect));
      this.graph = graph;
    }

    @Override
    protected void scale(float[] point) {
      point[0] = graph.toScreenX(point[0]);
      point[1] = graph.toScreenY(point[1]);
      point[2] = graph.toScreenZ(point[2]);
    }
  }
}




Java Source Code List

com.android.texample.GLText.java
com.android.texample.SpriteBatch.java
com.android.texample.TexampleRenderer.java
com.android.texample.TextureRegion.java
com.android.texample.Vertices.java
org.solovyev.android.plotter.Angle.java
org.solovyev.android.plotter.AxisStyle.java
org.solovyev.android.plotter.Check.java
org.solovyev.android.plotter.Color.java
org.solovyev.android.plotter.DefaultPlotter.java
org.solovyev.android.plotter.Dimensions.java
org.solovyev.android.plotter.Frustum.java
org.solovyev.android.plotter.Function0.java
org.solovyev.android.plotter.Function1.java
org.solovyev.android.plotter.Function2.java
org.solovyev.android.plotter.Function.java
org.solovyev.android.plotter.LineStyle.java
org.solovyev.android.plotter.MeshConfig.java
org.solovyev.android.plotter.MultisampleConfigChooser.java
org.solovyev.android.plotter.PinchZoomTracker.java
org.solovyev.android.plotter.PlotData.java
org.solovyev.android.plotter.PlotFunction.java
org.solovyev.android.plotter.PlotRenderer.java
org.solovyev.android.plotter.PlotView.java
org.solovyev.android.plotter.Plot.java
org.solovyev.android.plotter.Plotter.java
org.solovyev.android.plotter.PlottingView.java
org.solovyev.android.plotter.Spf.java
org.solovyev.android.plotter.SuperFunction.java
org.solovyev.android.plotter.TouchHandler.java
org.solovyev.android.plotter.ZoomLevels.java
org.solovyev.android.plotter.Zoomer.java
org.solovyev.android.plotter.app.MainActivity.java
org.solovyev.android.plotter.app.PlotterApplication.java
org.solovyev.android.plotter.meshes.Arrays.java
org.solovyev.android.plotter.meshes.AxisGrid.java
org.solovyev.android.plotter.meshes.Axis.java
org.solovyev.android.plotter.meshes.BaseCube.java
org.solovyev.android.plotter.meshes.BaseCurve.java
org.solovyev.android.plotter.meshes.BaseMesh.java
org.solovyev.android.plotter.meshes.BaseSurface.java
org.solovyev.android.plotter.meshes.DimensionsAwareSwapper.java
org.solovyev.android.plotter.meshes.DimensionsAware.java
org.solovyev.android.plotter.meshes.DoubleBufferGroup.java
org.solovyev.android.plotter.meshes.DoubleBufferMesh.java
org.solovyev.android.plotter.meshes.FunctionGraph2d.java
org.solovyev.android.plotter.meshes.FunctionGraph3d.java
org.solovyev.android.plotter.meshes.FunctionGraphSwapper.java
org.solovyev.android.plotter.meshes.FunctionGraph.java
org.solovyev.android.plotter.meshes.Graph.java
org.solovyev.android.plotter.meshes.Group.java
org.solovyev.android.plotter.meshes.IndicesOrder.java
org.solovyev.android.plotter.meshes.ListGroup.java
org.solovyev.android.plotter.meshes.ListPool.java
org.solovyev.android.plotter.meshes.Mesh.java
org.solovyev.android.plotter.meshes.Meshes.java
org.solovyev.android.plotter.meshes.Pool.java
org.solovyev.android.plotter.meshes.Scene.java
org.solovyev.android.plotter.meshes.SolidCube.java
org.solovyev.android.plotter.meshes.SurfaceInitializer.java
org.solovyev.android.plotter.meshes.WireFrameCube.java