Exemplo n.º 1
0
Arquivo: Noise.cpp Projeto: aalex/osg
double noise2(double vec[2])
{
   int bx0, bx1, by0, by1, b00, b10, b01, b11;
   double rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
   int i, j;

   if (start) {
      start = 0;
      initNoise();
   }

   setup(0, bx0,bx1, rx0,rx1);
   setup(1, by0,by1, ry0,ry1);

   i = p[ bx0 ];
   j = p[ bx1 ];

   b00 = p[ i + by0 ];
   b10 = p[ j + by0 ];
   b01 = p[ i + by1 ];
   b11 = p[ j + by1 ];

   sx = s_curve(rx0);
   sy = s_curve(ry0);

   q = g2[ b00 ] ; u = at2(rx0,ry0);
   q = g2[ b10 ] ; v = at2(rx1,ry0);
   a = lerp(sx, u, v);

   q = g2[ b01 ] ; u = at2(rx0,ry1);
   q = g2[ b11 ] ; v = at2(rx1,ry1);
   b = lerp(sx, u, v);

   return lerp(sy, a, b);
}
Exemplo n.º 2
0
//--------------------------------------------------------------
void testApp::setup()
{
	ofSetFrameRate( 60 );
	ofSetVerticalSync( true );
	
	bDebug			= false;
	bSmoothing		= false;
	bPause			= false;
	bDrawPoints		= false;
	bDrawLines		= false;
	bDrawCurves		= false;
	bDrawSimplified	= false;
	bDrawColor		= true;
	bRotateColor	= true;
	
	screenRect.width	= ofGetWidth();
	screenRect.height	= ofGetHeight();

	switch ( 1 )
	{
		case 1 :
			noiseRect.width		= 160;
			noiseRect.height	= 120;
		break;

		case 2 :
			noiseRect.width		= 320;
			noiseRect.height	= 240;
		break;
			
		case 3 :
			noiseRect.width		= 640;
			noiseRect.height	= 480;
		break;
	}
	
	debugRect.width		= 160;
	debugRect.height	= 120;
	
	float largeRectExtra;
	largeRectExtra		= 0.04;			// the extra is to cover the whole screen. set to 0 to see what happens without it.
	
	largeRect			= ofxResizeUtil :: cropToSize( noiseRect, screenRect );
	largeRect.x			-= largeRect.width  * largeRectExtra * 0.5;
	largeRect.y			-= largeRect.height * largeRectExtra * 0.5;
	largeRect.width		*= 1 + largeRectExtra;
	largeRect.height	*= 1 + largeRectExtra;
	
	screenGrabUtil.setup( "movie/frame" );
	screenGrabUtil.setPause( true );
	
	tileSaver.init( 10, 0, true );
	
	initNoise();
	initOpenCv();
	initContours();
	initGui();
	initColor();
}
Exemplo n.º 3
0
void LICE_TexGen_CircNoise(LICE_IBitmap *dest, RECT *rect, float rv, float gv, float bv, float nrings, float power, int size)
{
  initNoise();

  int span=dest->getRowSpan();
  int w = dest->getWidth();
  int h = dest->getHeight();
  int x = 0;
  int y = 0;
  if(rect)
  {
    x = rect->left;
    y = rect->top;
    w = rect->right - rect->left;
    h = rect->bottom - rect->top;
  }

  if (x<0) { w+=x; x=0; }
  if (y<0) { h+=y; y=0; }
  if (x+w > dest->getWidth()) w=dest->getWidth()-x;
  if (y+h > dest->getHeight()) h=dest->getHeight()-y;

  if (w<1 || h<1) return;

  LICE_pixel *startp = dest->getBits();
  if (dest->isFlipped())
  {
    startp += x + (dest->getHeight()-1-y)*span;
    span=-span;
  }
  else startp  += x + y*span;

  float xyPeriod = nrings;
  float turbPower = power;
  const float iturbSize = 1.0f/(float)size;
  const float turbSize = (float)size;
   
  {
    LICE_pixel *p = startp;
    for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
      {
        float xValue = ((float)j - w / 2) / w;
        float yValue = ((float)i - h / 2) / h;

        float distValue = sqrt(xValue * xValue + yValue * yValue) + turbPower * turbulence(j, i, turbSize, iturbSize) / 256.0f;
        float col = (float)fabs(256.0 * sin(2 * xyPeriod * distValue * 3.14159));

        p[j] = LICE_RGBA((int)(col*rv),(int)(col*bv),(int)(col*gv),255);
      }
      p+=span;
   }
  }
}
Exemplo n.º 4
0
/// The constructor for the game class
///
/// This function is called on the creation of a new game.  It loads
/// all the data, initialises the screen and keyboard functions.
/// @param doGraphics Should this game initialise graphics?
Game::Game()
{
  logi.log("New game");
  logi.log("Initialising Graphics");
  initGraphics();
  initNoise();
  terrain = new Terrain(glm::vec3(0),this);
  person = new Avatar(glm::vec3(3010,0,4010),this);
  mouseCameraControl = false;
  currentGame = this;
  for (int i = 0;i<256;i++)keys[i] =false;
}
Exemplo n.º 5
0
Arquivo: Noise.cpp Projeto: aalex/osg
double noise3(double vec[3])
{
   int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
   double rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
   int i, j;

   if (start) {
      start = 0;
      initNoise();
   }

   setup(0, bx0,bx1, rx0,rx1);
   setup(1, by0,by1, ry0,ry1);
   setup(2, bz0,bz1, rz0,rz1);

   i = p[ bx0 ];
   j = p[ bx1 ];

   b00 = p[ i + by0 ];
   b10 = p[ j + by0 ];
   b01 = p[ i + by1 ];
   b11 = p[ j + by1 ];

   t  = s_curve(rx0);
   sy = s_curve(ry0);
   sz = s_curve(rz0);

   q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0);
   q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0);
   a = lerp(t, u, v);

   q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0);
   q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0);
   b = lerp(t, u, v);

   c = lerp(sy, a, b);

   q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1);
   q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1);
   a = lerp(t, u, v);

   q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1);
   q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1);
   b = lerp(t, u, v);

   d = lerp(sy, a, b);

   //fprintf(stderr, "%f\n", lerp(sz, c, d));

   return lerp(sz, c, d);
}
Exemplo n.º 6
0
Arquivo: Noise.cpp Projeto: aalex/osg
double noise1(double arg)
{
   int bx0, bx1;
   double rx0, rx1, sx, t, u, v, vec[1];

   vec[0] = arg;
   if (start) {
      start = 0;
      initNoise();
   }

   setup(0,bx0,bx1,rx0,rx1);

   sx = s_curve(rx0);
   u = rx0 * g1[ p[ bx0 ] ];
   v = rx1 * g1[ p[ bx1 ] ];

   return(lerp(sx, u, v));
}
Exemplo n.º 7
0
void LICE_TexGen_Noise(LICE_IBitmap *dest, RECT *rect, float rv, float gv, float bv, float intensity, int mode, int smooth)
{
  initNoise();

  int span=dest->getRowSpan();
  int w = dest->getWidth();
  int h = dest->getHeight();
  int x = 0;
  int y = 0;
  if(rect)
  {
    x = rect->left;
    y = rect->top;
    w = rect->right - rect->left;
    h = rect->bottom - rect->top;
  }

  if (x<0) { w+=x; x=0; }
  if (y<0) { h+=y; y=0; }
  if (x+w > dest->getWidth()) w=dest->getWidth()-x;
  if (y+h > dest->getHeight()) h=dest->getHeight()-y;

  if (w<1 || h<1) return;

  LICE_pixel *startp = dest->getBits();
  if (dest->isFlipped())
  {
    startp += x + (dest->getHeight()-1-y)*span;
    span=-span;
  }
  else startp  += x + y*span;

  {
    LICE_pixel *p = startp;
    for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
      {
        float x = (float)j/w*16*intensity;
        float y = (float)i/h*16*intensity;

        float val = 0;
        int size = smooth;
        while(size>=1)
        {
          switch(mode)
          {
          case NOISE_MODE_NORMAL: val += noise(x/size, y/size)*size; break;
          case NOISE_MODE_WOOD: val += (float)cos( x/size + noise(x/size,y/size) )*size/2; break;
          }
          size /= 2;
        }
        float col = (float)fabs(val/smooth)*255;
        if(col>255) col=255;

        p[j] = LICE_RGBA((int)(col*rv),(int)(col*gv),(int)(col*bv),255);
      }
      p+=span;
    }
  }
}