Android Open Source - splott Surface






From Project

Back to project page splott.

License

The source code is released under:

MIT License

If you think the Android project splott 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 com.wordsaretoys.splott.plotter;
//from w w  w. j av a 2  s  .  com
import com.wordsaretoys.rise.geometry.Camera;
import com.wordsaretoys.rise.geometry.Vector;
import com.wordsaretoys.rise.glwrapper.Mesh;
import com.wordsaretoys.rise.glwrapper.Shader;
import com.wordsaretoys.rise.meshutil.IndexBuffer;
import com.wordsaretoys.rise.meshutil.SurfaceMapper;
import com.wordsaretoys.rise.meshutil.VertexBuffer;
import com.wordsaretoys.rise.utility.Asset;
import com.wordsaretoys.splott.parser.Vm;

public class Surface {

  VertexBuffer vertex;
  IndexBuffer index;
  Mesh mesh;
  Shader shader;
  Vm vm;
  GlView parent;

  /**
   * ctor; creates GL objects
   * must be called in GL context
   */
  public Surface(GlView parent) {
    
    this.parent = parent;
    
    shader = new Shader();
    shader.build(
          Asset.getTextAsset(parent.getContext(), "surfaceVert.glsl"),
          Asset.getTextAsset(parent.getContext(), "surfaceFrag.glsl")
        );

    int[] attr = {
      shader.getAttributeId("position"), 3
    };
    mesh = new Mesh(attr);
      
    vertex = new VertexBuffer();
    index = new IndexBuffer();
  }

  /**
   * generate the mesh
   */
  public void create(Vm vm) {
    this.vm = vm;
    
    vertex.reset();
    index.reset();
    
    new Thread() {
      @Override public void run() {
        
        new Mapper().generate(-5, -5, -5, 5, 5, 5, 0.25f, 0);
        parent.queueEvent(new Runnable() {
          @Override public void run() {
            mesh.build(vertex);
          }
        });
        
      }
    }.start();

    
  }

  /**
   * draw the mesh
   */
  public void draw(Camera camera) {
    shader.activate();
    shader.setMatrix("modelview", camera.rotations);
    shader.setMatrix("projector", camera.projector);
    mesh.draw();
  }

  /**
   * marching cubes class
   */
  class Mapper extends SurfaceMapper {

    @Override
    public float field(float x, float y, float z) {
      return (float) vm.get(x, y, z, 0);
    }

    @Override
    public void build(Vector v0, Vector v1, Vector v2, Vector n) {
      vertex.set(v0.x, v0.y, v0.z);
      vertex.set(v1.x, v1.y, v1.z);
      vertex.set(v2.x, v2.y, v2.z);
    }
    
  }
  
}




Java Source Code List

com.wordsaretoys.rise.geometry.Camera.java
com.wordsaretoys.rise.geometry.Geom.java
com.wordsaretoys.rise.geometry.Mote.java
com.wordsaretoys.rise.geometry.Ortho.java
com.wordsaretoys.rise.geometry.Quaternion.java
com.wordsaretoys.rise.geometry.Vector.java
com.wordsaretoys.rise.glwrapper.Mesh.java
com.wordsaretoys.rise.glwrapper.Shader.java
com.wordsaretoys.rise.glwrapper.Texture.java
com.wordsaretoys.rise.meshutil.HeightMapper.java
com.wordsaretoys.rise.meshutil.IndexBuffer.java
com.wordsaretoys.rise.meshutil.SurfaceMapper.java
com.wordsaretoys.rise.meshutil.VertexBuffer.java
com.wordsaretoys.rise.meshutil.Vindexer.java
com.wordsaretoys.rise.pattern.Bitmap.java
com.wordsaretoys.rise.pattern.F2FSumMap.java
com.wordsaretoys.rise.pattern.I2FCutMap.java
com.wordsaretoys.rise.pattern.I2FMap.java
com.wordsaretoys.rise.pattern.I2IMap.java
com.wordsaretoys.rise.pattern.Pattern.java
com.wordsaretoys.rise.pattern.Ring.java
com.wordsaretoys.rise.utility.Asset.java
com.wordsaretoys.rise.utility.Board.java
com.wordsaretoys.rise.utility.Dbg.java
com.wordsaretoys.rise.utility.Interval.java
com.wordsaretoys.rise.utility.Misc.java
com.wordsaretoys.rise.utility.Needle.java
com.wordsaretoys.splott.MainActivity.java
com.wordsaretoys.splott.parser.Compiler.java
com.wordsaretoys.splott.parser.SurfaceBaseListener.java
com.wordsaretoys.splott.parser.SurfaceLexer.java
com.wordsaretoys.splott.parser.SurfaceListener.java
com.wordsaretoys.splott.parser.SurfaceParser.java
com.wordsaretoys.splott.parser.SyntaxChecker.java
com.wordsaretoys.splott.parser.Vm.java
com.wordsaretoys.splott.plotter.GlView.java
com.wordsaretoys.splott.plotter.Render.java
com.wordsaretoys.splott.plotter.Surface.java