Android Open Source - splott Vm






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.parser;
//from  w  w  w  . j  a v a 2s .  c  om
import com.wordsaretoys.splott.parser.Compiler.Step;

public class Vm {
  
  double[] locals;
  Step[] steps;
  int output;
  
  public Vm(Step[] s, int lc, int o) {
    steps = s;
    locals = new double[lc];
    output = o;
  }
  
  public double get(double x, double y, double z, double t) {
    locals[0] = x;
    locals[1] = y;
    locals[2] = z;
    locals[3] = t;
    for (int i = 0; i < steps.length; i++) {
      Step step = steps[i];
      switch (step.type) {

      case LoadConstant:
        locals[step.local0] = step.constant;
        break;
        
      case OpAdd:
        locals[step.local2] = locals[step.local0] + locals[step.local1];
        break;
        
      case OpSubtract:
        locals[step.local2] = locals[step.local0] - locals[step.local1];
        break;

      case OpMultiply:
        locals[step.local2] = locals[step.local0] * locals[step.local1];
        break;

      case OpDivide:
        locals[step.local2] = locals[step.local0] / locals[step.local1];
        break;

      case OpExponent:
        locals[step.local2] = Math.pow(locals[step.local0], locals[step.local1]);
        break;
        
      case OpUminus:
        locals[step.local1] = -locals[step.local0];
        break;
        
      case FuncSine:
        locals[step.local1] = Math.sin(locals[step.local0]);
        break;
      
      case FuncCosine:
        locals[step.local1] = Math.cos(locals[step.local0]);
        break;

      case FuncLogarithm:
        locals[step.local1] = Math.log(locals[step.local0]);
        break;
        
      case FuncExponential:
        locals[step.local1] = Math.exp(locals[step.local0]);
        break;
      }
    }
    return locals[output];
  }
  
}




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