Array2D<float> ShallowWater::advect(const Array2D<float> & src) { Array2D<float> temp; temp.init(src.getDimX(), src.getDimY()); float x, y; temp = src; for(int j = 1; j < src.getDimY()-1; j++) { for(int i = 1; i < src.getDimX()-1; i++) { x = i - m_dt * m_vX(i, j); y = j - m_dt * m_vY(i, j); temp.setValue(i, j, src.interpolate(x, y)); } } return temp; }
Array2D<math::Vec3f> ShallowWater::computeNormals(const Array2D<float> & src) const { math::Vec3f a, b, c, d; Array2D<math::Vec3f> upNorms; upNorms.init(src.getDimX()-1, src.getDimY()-1); Array2D<math::Vec3f> downNorms; downNorms.init(src.getDimX()-1, src.getDimY()-1); Array2D<math::Vec3f> temp; temp.init(src.getDimX(), src.getDimY()); for(int i = 0; i < upNorms.getDimX(); i++) { for(int j = 0; j < upNorms.getDimY(); j++) { a = math::Vec3f(i*m_dx, src(i, j), j*m_dy); b = math::Vec3f((i+1)*m_dx, src(i+1, j), j*m_dy); c = math::Vec3f((i+1)*m_dx, src(i+1, j+1), (j+1)*m_dy); d = math::Vec3f(i*m_dx, src(i, j+1), (j+1)*m_dy); upNorms.setValue(i, j, d-a ^ b-a); downNorms.setValue(i, j, b-c ^ d-c); } } for(int i = 0; i < src.getDimX(); i++) { for(int j = 0; j < src.getDimY(); j++) { math::Vec3f tmp(0.0, 0.0, 0.0); int tmpNb = 0; if(i-1 >= 0 && j < src.getDimY()-1) { tmpNb += 2; tmp += upNorms(i-1, j) + downNorms(i-1, j); } if(j-1 >= 0 && i < src.getDimX()-1) { tmpNb += 2; tmp += upNorms(i, j-1) + downNorms(i, j-1); } if(j-1 >= 0 && i-1 >= 0) { tmpNb++; tmp += downNorms(i-1, j-1); } if(i < src.getDimX()-1 && j < src.getDimY()-1) { tmpNb++; tmp += upNorms(i, j); } temp.setValue(i, j, (tmp/tmpNb).normalize()); } } return temp; }