<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -28,10 +28,24 @@
   MIT License
  */
 
+var Config = {
+    gridDim: 64,
+    shift1: 6,
+    shift2: 12,
+    ballCount: 128,
+    
+    GP_TYPE_META: 0x1,
+    GP_TYPE_BORDER: 0x2,
+    GP_TYPE_TEXT: 0x4
+};
+
 var MetaBalls = new Class({
   balls: null,
+  grid: null,
   
-  initialize: function(count) {
+  initialize: function(grid) {
+    this.grid = grid;
+    var count = Config.ballCount;
     var b = this.balls = new Array(count);
     for(var i=0; i &lt; count; i++) {
       //add metaobject
@@ -41,13 +55,73 @@ var MetaBalls = new Class({
         'b': 0
       });
     }
+  },
+  
+  update: function(from, to) {
+    var balls = this.balls;
+    var dim = Config.gridDim;
+    var points = this.grid.points;
+    var shift1 = Config.shift1, shift2 = Config.shift2;
+    var meta = Config.GP_TYPE_META;
+    
+    while (from &lt; num) {
+      var ballsFrom = balls[from];
+      var influenceRange = 1 + (ballsFrom.b &gt;&gt; 0);
+      var pos = ballsFrom.pos;
+      var posx = (pos.x &gt;&gt; 0);
+      var posy = (pos.y &gt;&gt; 0);
+      var posz = (pos.z &gt;&gt; 0);   
+      for (var z = posz-influenceRange; z &lt; posz+influenceRange; ++z) {
+        if (z &lt; 0 || z &gt;= dim)
+          continue;
+
+        for (var y = posy-influenceRange; y &lt; posy+influenceRange; ++y) {
+          if (y &lt; 0 || y &gt;= dim)
+            continue;
+
+          for (var x = posx-influenceRange; x &lt; posx+influenceRange; ++x) {
+            if (x &lt; 0 || x &gt;= dim)
+              continue;
+
+            var dist = {
+                'x': pos.x - x,
+                'y': pos.y - y,
+                'z': pos.z - z
+            };
+            var dist2 = dist.x * dist.x + dist.y * dist.y + dist.z * dist.z;
+            var range2 = ballsFrom.b * ballsFrom.b;
+
+            if (range2 &gt; dist2) {
+              var gp = points[(z&lt;&lt;shift2) + (y&lt;&lt;shift1) + x];
+              gp.value += ballsFrom.a * 
+                (1.0f - 
+                0.4444444f * dist2 * dist2 * dist2 / (range2 * range2 * range2) + 
+                1.8888888f * dist2 * dist2 / (range2 * range2) - 
+                2.4444444f * dist2 / range2);
+              
+              gp.flags |= meta;
+            }
+          }
+        }
+      }
+      ++from;
+    }
   }
 });
 
 var MetaGrid = new Class({
-  points: null,
+  points: null, 
+  
+  dim: null,
+  dimSq: null,
+  dimCb: null,
   
-  initialize: function(count) {
+  initialize: function() {
+    var count = Config.gridDim;
+    this.dim = count;
+    this.dimSq = count * count;
+    this.dimCb = count * count * count;
+    
     var p = this.points = new Array(count);
     for(var i=0; i &lt; count; i++) {
       //add gridpoint
@@ -56,5 +130,24 @@ var MetaGrid = new Class({
         'flags': 0
       });
     }
-  } 
+  },
+  
+  move: function(fac) {
+    var movecount = this.dimCb;
+    var dimSq = this.dimSq;
+    var points = this.points;
+    
+    while (movecount--) {
+      if (((movecount &gt;&gt; 12) &amp; 0x3f) &gt; 0) {
+        var p = points[movecount];
+        var pdiff = points[movecount - dimSq];
+        
+        p.value = fac * pdiff.value;
+        p.flags = pdiff.flags;
+      } else {
+        points[movecount].value = 0;
+      }
+    } 
+  }
+
 });</diff>
      <filename>examples/gles/metaballs/metaballs.js</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
 attribute vec4 pos; 
 
 void main() { 
-  gl_Position = vec4(pos.x * float(370), pos.y * float(240), 0.0, 1.0); 
+  gl_Position = vec4(pos.x * float(370), pos.y * float(240), 0.0, 1.0);
 }
\ No newline at end of file</diff>
      <filename>examples/gles/shaders/m3d-vshader.sl</filename>
    </modified>
    <modified>
      <diff>@@ -1205,7 +1205,7 @@ Handle&lt;Value&gt; GLESglTexImage2DFileCallback(const Arguments&amp; args) {
   String::Utf8Value value(args[0]);
   char* filepath_str = *value;
 
-  char* filename = Utils::getRealPath(filepath_str);
+  char* filename = V8GLUtils::getRealPath(filepath_str);
 
   //take care of relative/absolute paths.
   Image* img = loadPNG(filename);
@@ -1534,7 +1534,7 @@ Handle&lt;Value&gt; GLESglShaderSourceFileCallback(const Arguments&amp; args) {
     return v8::Undefined();
 
   char* filepath_str = *filepath_ascii;
-  char* filename = Utils::getRealPath(filepath_str);
+  char* filename = V8GLUtils::getRealPath(filepath_str);
 
   std::ifstream in_file(filename);
 </diff>
      <filename>glesbindings/glesbind.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1181,7 +1181,7 @@ Handle&lt;Value&gt; GLESglTexImage2DFileCallback(const Arguments&amp; args) {
   String::Utf8Value value(args[0]);
   char* filepath_str = *value;
 
-  char* filename = Utils::getRealPath(filepath_str);
+  char* filename = V8GLUtils::getRealPath(filepath_str);
 
   //take care of relative/absolute paths.
   Image* img = loadPNG(filename);
@@ -1510,7 +1510,7 @@ Handle&lt;Value&gt; GLESglShaderSourceFileCallback(const Arguments&amp; args) {
     return v8::Undefined();
 
   char* filepath_str = *filepath_ascii;
-  char* filename = Utils::getRealPath(filepath_str);
+  char* filename = V8GLUtils::getRealPath(filepath_str);
 
   std::ifstream in_file(filename);
 </diff>
      <filename>glesbindings/glescustom.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 #include &quot;utils.h&quot;
 #include &lt;string&gt;
 
-namespace Utils {
+namespace V8GLUtils {
 	char separator = '/';
 	char* root_path;
 
@@ -9,38 +9,38 @@ namespace Utils {
 	  //Set the root_path for opening shader files with
 	  //relative paths
 	  //take path from executable
-	  char* pch = strrchr(program_path, Utils::separator);
+	  char* pch = strrchr(program_path, V8GLUtils::separator);
 	  int last_index = pch - program_path +1;
 	  char* tmp_exec_path = new char[last_index +1];
 	  strncpy(tmp_exec_path, program_path, last_index);
 	  tmp_exec_path[last_index] = '\0';
 
 	  //take relative path from javascript file
-	  char* p1ch = strrchr(jsfile_path, Utils::separator);
+	  char* p1ch = strrchr(jsfile_path, V8GLUtils::separator);
 	  int last_index1 = p1ch - jsfile_path +1;
 	  char* tmp_js_path = new char[last_index1 +1];
 	  strncpy(tmp_js_path, jsfile_path, last_index1);
 	  tmp_js_path[last_index1] = '\0';
 
-	  Utils::root_path = new char[last_index + last_index1 +1];
+	  V8GLUtils::root_path = new char[last_index + last_index1 +1];
 
-	  strcpy(Utils::root_path, tmp_exec_path);
-	  strcat(Utils::root_path, tmp_js_path);
+	  strcpy(V8GLUtils::root_path, tmp_exec_path);
+	  strcat(V8GLUtils::root_path, tmp_js_path);
 
 	  delete[] tmp_exec_path;
 	  delete[] tmp_js_path;
 	}
 
 	char* getRootPath(void) {
-		return Utils::root_path;
+		return V8GLUtils::root_path;
 	}
 
 	char* getRealPath(char* filepath_str) {
 		//read the file source
 		char* filename = NULL;
-		if(filepath_str[0] != Utils::separator) {
-		  filename = new char[strlen(Utils::root_path) + strlen(filepath_str) +1];
-		  strcpy(filename, Utils::root_path);
+		if(filepath_str[0] != V8GLUtils::separator) {
+		  filename = new char[strlen(V8GLUtils::root_path) + strlen(filepath_str) +1];
+		  strcpy(filename, V8GLUtils::root_path);
 		  strcat(filename, filepath_str);
 		} else {
 		  filename = new char[strlen(filepath_str) +1];</diff>
      <filename>utils.cpp</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
-#ifndef UTILS_H_
-#define UTILS_H_
+#ifndef V8GLUTILS_H_
+#define V8GLUTILS_H_
 
-namespace Utils {
+namespace V8GLUtils {
 		void setRootPath(char* program_path, char* jsfile_path);
 
 		char* getRootPath(void);</diff>
      <filename>utils.h</filename>
    </modified>
    <modified>
      <diff>@@ -102,7 +102,7 @@ Handle&lt;Value&gt; load(const Arguments&amp; args) {
 	  //get argument
 	  String::Utf8Value value0(args[i]);
 	  char* arg0 = *value0;
-	  string str(Utils::getRealPath(arg0));
+	  string str(V8GLUtils::getRealPath(arg0));
 	  if(!exec(str)) {
 		  fprintf(stderr, &quot;Error reading '%s'.\n&quot;, arg0);
 		  return v8::Undefined();
@@ -153,7 +153,7 @@ bool V8GL::initialize(int* pargc, char** argv, string scriptname) {
 	  GlesFactory::self_ = Persistent&lt;Object&gt;::New(Gles-&gt;NewInstance());
 
 	  //Set (only once) the absolute path for the .js file being executed.
-	  Utils::setRootPath(argv[0], argv[1]);
+	  V8GLUtils::setRootPath(argv[0], argv[1]);
 
 	  // Compile and run the script
 	  if (!executeScript(scriptname))</diff>
      <filename>v8-gl.cpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>dcae47cfc7edf133a10d9387c8d3bee90c0b8007</id>
    </parent>
  </parents>
  <author>
    <name>philogb</name>
    <email>philogb@gmail.com</email>
  </author>
  <url>http://github.com/philogb/v8-gl/commit/0c076747731e9a20fbc206403a5aea34298d0a9f</url>
  <id>0c076747731e9a20fbc206403a5aea34298d0a9f</id>
  <committed-date>2009-10-23T13:13:38-07:00</committed-date>
  <authored-date>2009-10-23T13:13:38-07:00</authored-date>
  <message>Ambiguous Utils changed for V8GLUtils</message>
  <tree>8a8f32e942c5a78ecf162189382fadfae536996d</tree>
  <committer>
    <name>philogb</name>
    <email>philogb@gmail.com</email>
  </committer>
</commit>
