Example #1
0
float GradientCoherentNoise3D (float x, float y, float z, int seed, int noiseQuality)
{
  // Create a unit-length cube aligned along an integer boundary.  This cube
  // surrounds the input point.
  int x0 = (x > 0.0? (int)x: (int)x - 1);
  int x1 = x0 + 1;
  int y0 = (y > 0.0? (int)y: (int)y - 1);
  int y1 = y0 + 1;
  int z0 = (z > 0.0? (int)z: (int)z - 1);
  int z1 = z0 + 1;

  // Map the difference between the coordinates of the input value and the
  // coordinates of the cube's outer-lower-left vertex onto an S-curve.
  float xs = 0, ys = 0, zs = 0;
  switch (noiseQuality) {
    case 0:
      xs = (x - (float)x0);
      ys = (y - (float)y0);
      zs = (z - (float)z0);
      break;
    case 1:
      xs = SCurve3 (x - (float)x0);
      ys = SCurve3 (y - (float)y0);
      zs = SCurve3 (z - (float)z0);
      break;
    case 2:
      xs = SCurve5 (x - (float)x0);
      ys = SCurve5 (y - (float)y0);
      zs = SCurve5 (z - (float)z0);
      break;
  }

  // Now calculate the noise values at each vertex of the cube.  To generate
  // the coherent-noise value at the input point, interpolate these eight
  // noise values using the S-curve value as the interpolant (trilinear
  // interpolation.)
  float n0, n1, ix0, ix1, iy0, iy1;
  n0   = GradientNoise3D (x, y, z, x0, y0, z0, seed);
  n1   = GradientNoise3D (x, y, z, x1, y0, z0, seed);
  ix0  = LinearInterp (n0, n1, xs);
  n0   = GradientNoise3D (x, y, z, x0, y1, z0, seed);
  n1   = GradientNoise3D (x, y, z, x1, y1, z0, seed);
  ix1  = LinearInterp (n0, n1, xs);
  iy0  = LinearInterp (ix0, ix1, ys);
  n0   = GradientNoise3D (x, y, z, x0, y0, z1, seed);
  n1   = GradientNoise3D (x, y, z, x1, y0, z1, seed);
  ix0  = LinearInterp (n0, n1, xs);
  n0   = GradientNoise3D (x, y, z, x0, y1, z1, seed);
  n1   = GradientNoise3D (x, y, z, x1, y1, z1, seed);
  ix1  = LinearInterp (n0, n1, xs);
  iy1  = LinearInterp (ix0, ix1, ys);

  return LinearInterp (iy0, iy1, zs);
}
Example #2
0
//  VERSION  1A).  //
void MarchingCube::generateMesh()
{
	//TRIANGLE * triangles = new TRIANGLE[3*ncellsX*ncellsY*ncellsZ];
    //this should be enough space, if not change 4 to 5
	numTriangles = int(0);

	int YtimeZ = (ncellsY+1)*(ncellsZ+1);
	//go through all the points
	for(int i=0; i < ncellsX; i++)			//x axis
		for(int j=0; j < ncellsY; j++)		//y axis
			for(int k=0; k < ncellsZ; k++)	//z axis
			{
				//initialize vertices
				mp4Vector verts[8];
				int ind = i*YtimeZ + j*(ncellsZ+1) + k;
   /*(step 3)*/ verts[0] = mcPoints[ind];
				verts[1] = mcPoints[ind + YtimeZ];
				verts[2] = mcPoints[ind + YtimeZ + 1];
				verts[3] = mcPoints[ind + 1];
				verts[4] = mcPoints[ind + (ncellsZ+1)];
				verts[5] = mcPoints[ind + YtimeZ + (ncellsZ+1)];
				verts[6] = mcPoints[ind + YtimeZ + (ncellsZ+1) + 1];
				verts[7] = mcPoints[ind + (ncellsZ+1) + 1];
				
				//get the index
				int cubeIndex = int(0);
				for(int n=0; n < 8; n++)
   /*(step 4)*/		if(verts[n].val <= isoValue) cubeIndex |= (1 << n);

				//check if its completely inside or outside
   /*(step 5)*/ if(!edgeTable[cubeIndex]) continue;
			
				//get intersection vertices on edges and save into the array
   				mpVector intVerts[12];
   /*(step 6)*/ if(edgeTable[cubeIndex] & 1) intVerts[0] = LinearInterp(verts[0], verts[1], isoValue);
				if(edgeTable[cubeIndex] & 2) intVerts[1] = LinearInterp(verts[1], verts[2], isoValue);
				if(edgeTable[cubeIndex] & 4) intVerts[2] = LinearInterp(verts[2], verts[3], isoValue);
				if(edgeTable[cubeIndex] & 8) intVerts[3] = LinearInterp(verts[3], verts[0], isoValue);
				if(edgeTable[cubeIndex] & 16) intVerts[4] = LinearInterp(verts[4], verts[5], isoValue);
				if(edgeTable[cubeIndex] & 32) intVerts[5] = LinearInterp(verts[5], verts[6], isoValue);
				if(edgeTable[cubeIndex] & 64) intVerts[6] = LinearInterp(verts[6], verts[7], isoValue);
				if(edgeTable[cubeIndex] & 128) intVerts[7] = LinearInterp(verts[7], verts[4], isoValue);
				if(edgeTable[cubeIndex] & 256) intVerts[8] = LinearInterp(verts[0], verts[4], isoValue);
				if(edgeTable[cubeIndex] & 512) intVerts[9] = LinearInterp(verts[1], verts[5], isoValue);
				if(edgeTable[cubeIndex] & 1024) intVerts[10] = LinearInterp(verts[2], verts[6], isoValue);
				if(edgeTable[cubeIndex] & 2048) intVerts[11] = LinearInterp(verts[3], verts[7], isoValue);

				//now build the triangles using triTable
				for (int n=0; triTable[cubeIndex][n] != -1; n+=3) {
    /*(step 7)*/ 	triangles[numTriangles].p[0] = intVerts[triTable[cubeIndex][n+2]];
					triangles[numTriangles].p[1] = intVerts[triTable[cubeIndex][n+1]];
					triangles[numTriangles].p[2] = intVerts[triTable[cubeIndex][n]];
    /*(step 8)*/ 	triangles[numTriangles].norm = ((triangles[numTriangles].p[1] -
                                                     triangles[numTriangles].p[0]).Cross(triangles[numTriangles].p[2] -
                                                    triangles[numTriangles].p[0])).Normalize();
					numTriangles++;
				}
			
			}	//END OF FOR LOOP
}
Example #3
0
File: Color.cpp Project: m1h4/Touch
void Color::Darken(float s)
{
    LinearInterp(Color(a,0.0f,0.0f,0.0f),s);
}
Example #4
0
File: Color.cpp Project: m1h4/Touch
void Color::Saturation(float s)
{
    float v = (r + g + b) / 3.0f;

    LinearInterp(Color(a,v,v,v),s);
}
Example #5
0
File: Color.cpp Project: m1h4/Touch
void Color::Brighten(float s)
{
    LinearInterp(Color(a,1.0f,1.0f,1.0f),s);
}