VisClient/org/hfbk/vis/visnode/VisFunction.java

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 import org.dronus.graph.Node;
00004 import org.hfbk.util.Scripter;
00005 import org.hfbk.util.Scripter.ScriptFunction;
00006 import org.lwjgl.util.vector.Vector3f;
00007 
00008 
00022 public class VisFunction extends VisHeightfield {
00023 
00024         String f;
00025 
00026         Scripter scripter=new Scripter();
00027         
00028         public VisFunction(Node node, Vector3f position) {
00029                 super(node, position);
00030 
00031                 f = node.text;
00032                 scripter.evaluate("function f(x, y, t){with(Math){return " + f + ";}};");
00033         }
00034 
00035         @Override
00036         float[][] heightMap(float t) {
00037                 int w=50,h=50;
00038                 
00039                 ScriptFunction f = scripter.getFunction("f");
00040                 
00041                 float[][] z = new float[w][h];
00042                 
00043                 for (int x = 0; x < w; x++) {
00044                         for (int y = 0; y < h; y++) {
00045                                 Object value = f.call(2*x/(float)w-1 ,  2*y/(float)h-1, t);
00046                                 z[x][y] = ((Double) value).floatValue();
00047                         }
00048                 }
00049                 return z;
00050         }
00051 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1