Monday, August 2, 2010

Colloid begins

The game idea is a blue bubble that falls on planet and starts to spread. The locals are trying to burn out the goo, so you control the flow direction, accumulation, temperature and other goo's properties to overwhelm the defenses. Some articles for goo simulation:

Good overview:
http://software.intel.com/en-us/articles/fluid-simulation-for-video-games-part-1/

Some algorithmics:
http://www.colinbraley.com/Pubs/FluidSimColinBraley.pdf



Conjugate Gradient:
http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf
http://planetmath.org/encyclopedia/ConjugateGradientAlgorithm.html

Sparse symmetric matrix implementation:

package yarangi.math.algebra;

import java.util.HashMap;
import java.util.Map;

public class SparseSymmetricMatrix implements IMatrix
{

 private Map  matrix;
 
 private int width;
 
 public SparseSymmetricMatrix(int width)
 {
  this.width = width;
  
  this.matrix = new HashMap  (width*width/4);
 }
 
 public SparseSymmetricMatrix(int width, double loadFactor)
 {
  this.width = width;
  
  this.matrix = new HashMap  ((int)(loadFactor*width*width));
 }

 
 public void set(double value, int i, int j)
 {
  matrix.put(index(i, j), value);
  if(index(i, j) < 0)
 }
 
 public double get(int i, int j) {
  Double value = matrix.get(index(i, j));
  return value == null ? 0 : value;
 }
 
 
 private int index(int i, int j)
 {
  if(i > j)
   return j * width + i;
  return i * width + j;
 }

 public IVector mul(IVector vector) {
  IVector result = new Vector(width);
  
  for(int key : matrix.keySet())
  {
   double value = matrix.get(key);
   int row1 = key % width;
   int row2 = key / width;
   result.set(result.get(row1)+value*vector.get(row2), row1);
   if(row1 != row2)
    result.set(result.get(row2)+value*vector.get(row1), row2);
  }
  
  return result;
  
 }

 public IVector mulTranspose(IVector vector) {
  return mul(vector);
 }
}




May also be of interest:


No comments:

Post a Comment