void drawtree(int n)
{
    if(n>0)
    {
    //////////////////////////
    //stack of matrices
     glPushMatrix();

     glTranslatef(-0.5,1.0,0);
     glRotatef(45, 0.0, 0.0, 1.0);

     // 1/sqrt(2)=0.707
     glScalef(0.707,0.707,0.707);

     //recursion
     drawtree(n-1);

     glPopMatrix();
    ////////////////////////////

     glPushMatrix();
     glTranslatef(0.5,1.0,0);
     glRotatef(-45, 0.0, 0.0, 1.0);
     glScalef(0.707,0.707,0.707);
     drawtree(n-1);
     glPopMatrix();
     //draw a cube
     glutSolidCube(1);
    }
}
Exemple #2
0
main( )
{ 

int gd = DETECT, gm ;
int drawtree ( int x1, int y1, float a, float l, float f, int n ) ;
initgraph ( &gd, &gm, "d:\\tc\\bgi" ) ;

 

drawtree ( 280, 350, 270, 60, 90, 6 ) ;

 

getch( ) ;
closegraph( ) ;
restorecrtmode( ) ;

}
Exemple #3
0
drawtree ( int x1, int y1, float a, float l, float f, int n )

{

int i, num = 3, x2, y2 ;
float spreadratio = 0.75, lenratio = 0.9 ;
float delang, ang ;

 

if ( n > 0 )
{

switch ( n )
{

case 1:

setcolor ( LIGHTGREEN ) ;
break ;

case 2:

setcolor ( GREEN ) ;
break ;

case 3:

setcolor ( RED ) ;
break ;

case 4:

setcolor ( BROWN ) ;
break ;

default:

setcolor ( DARKGRAY ) ;
break ;

}

 

x2 = x1 + l * cos ( 0.0174 * a ) ;
y2 = y1 + l * sin ( 0.0174 * a ) ;

 

for ( i = 0 ; i < n ; i++ )
{

line ( x1 + i, y1, x2 + i, y2 ) ;
line ( x1 - i, y1, x2 - i, y2 ) ;

}

 

randomize( ) ;
num = random ( 5 ) + 2 ;
if ( num > 1 )

delang = f / ( num - 1.0 ) ;

else

delang = 0.0 ;

 

ang = a - f / 2.0 - delang ;

for ( i = 1 ; i <= num ; i++ )
{

ang += delang ;
delay ( 10 ) ;
drawtree ( x2, y2, ang , l * lenratio, random ( 90 ) + 1 , n - 1 ) ;

}

}

else
{

setfillstyle ( SOLID_FILL, random ( 15 ) + 1 ) ;
fillellipse ( x1, y1, 3, 6 ) ;

}

}
Exemple #4
0
	void search(D &d, typename D::State &s0) {
		this->start();

		Node *root = pool.construct();
		root->parent = NULL;
		d.pack(root->state, s0);

		double pt[K];
		s0.vector(&d, pt);
		for (unsigned int i = 0; i < K; i++)
			root->point[i] = pt[i];
		tree.insert(pt, root);

		for ( ; ; ) {
			sample(pt);
			auto near = tree.nearest(pt);
			Node *node = near->data;
			State buf, &state = d.unpack(buf, node->state);
				
			SearchAlgorithm<D>::res.expd++;
	
			Node *kid = pool.construct();
			kid->parent = node;
			double bestpt[K];
			double dist = std::numeric_limits<double>::infinity();

			typename D::Operators ops(d, state);
			for (unsigned int i = 0; i < ops.size(); i++) {
				SearchAlgorithm<D>::res.gend++;
				if (node->ops.find(ops[i]) != node->ops.end())
					continue;

				Edge e(d, state, ops[i]);

				if (d.isgoal(e.state)) {
					d.pack(kid->state, e.state);
					kid->op = ops[i];
					solpath<D, Node>(d, kid, this->res);
					goto done;
				}

				double kidpt[K];
				e.state.vector(&d, kidpt);
				
				double dst = sqdist(pt, kidpt);
				if (dst < dist) {
					dist = dst;
					for (unsigned int j = 0; j < K; j++)
						bestpt[j] = kidpt[j];
					d.pack(kid->state, e.state);
					kid->op = ops[i];
				}
			}
			if (std::isinf(dist)) {
				pool.destruct(kid);
				continue;
			}
	
			node->ops.insert(kid->op);
			tree.insert(bestpt, kid);
			for (unsigned int i = 0; i < K; i++)
				kid->point[i] = bestpt[i];
		}

done:

		this->finish();
		drawtree(d);
	}
Exemple #5
0
static void DrawFire(ModeInfo * mi)
{
    int j;
    firestruct *fs = &fire[MI_SCREEN(mi)];
    Bool wire = MI_IS_WIREFRAME(mi);

    if (do_trackmouse && !MI_IS_ICONIC(mi))
	trackmouse(mi);

    if (do_wander)
    {
	GLfloat x, y, z;

#       define SINOID(SCALE,SIZE) \
        ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2)

        x = SINOID(0.031, 0.85);
        y = SINOID(0.017, 0.25);
        z = SINOID(0.023, 0.85);
        frame++;
        fs->obs[0] = x + DEF_OBS[0];
        fs->obs[1] = y + DEF_OBS[1];
        fs->obs[2] = z + DEF_OBS[2];
        fs->dir[1] = y;
        fs->dir[2] = z;
    }

    glEnable(GL_DEPTH_TEST);

    if (fs->fog)
	glEnable(GL_FOG);
    else
	glDisable(GL_FOG);

    glDepthMask(GL_TRUE);
    glClearColor(0.5, 0.5, 0.8, 1.0);	/* sky in the distance */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    calcposobs(fs);
    gluLookAt(fs->obs[0], fs->obs[1], fs->obs[2],
	      fs->obs[0] + fs->dir[0], fs->obs[1] + fs->dir[1],
	      fs->obs[2] + fs->dir[2], 0.0, 1.0, 0.0);


    glEnable(GL_TEXTURE_2D);

    /* draw ground using the computed texture */
#ifdef HAVE_GLBINDTEXTURE
    if (do_texture) {
	glColor4f(1.0,1.0,1.0,1.0);	/* white to get texture in it's true color */
	glBindTexture(GL_TEXTURE_2D, fs->groundid);
    }
    else
#endif /* HAVE_GLBINDTEXTURE */
        glColor4f(0.54, 0.27, 0.07, 1.0);	/* untextured ground color */
    glBegin(GL_QUADS);
    glTexCoord2fv(qt[0]);
    glVertex3fv(q[0]);
    glTexCoord2fv(qt[1]);
    glVertex3fv(q[1]);
    glTexCoord2fv(qt[2]);
    glVertex3fv(q[2]);
    glTexCoord2fv(qt[3]);
    glVertex3fv(q[3]);
    glEnd();

    glAlphaFunc(GL_GEQUAL, 0.9);
#ifdef HAVE_GLBINDTEXTURE
    if (fs->num_trees)
    {
	/* here do_texture IS True - and color used is white */
	glEnable(GL_ALPHA_TEST);
	glBindTexture(GL_TEXTURE_2D,fs->treeid);
	for(j=0;j<fs->num_trees;j++)
	    drawtree(fs->treepos[j].x ,fs->treepos[j].y ,fs->treepos[j].z );
    	glDisable(GL_ALPHA_TEST);
    }
#endif /* HAVE_GLBINDTEXTURE */
    glDisable(GL_TEXTURE_2D);
    glDepthMask(GL_FALSE);

    if (fs->shadows) {
	/* draw shadows with black color */
	glBegin(wire ? GL_LINE_STRIP : GL_TRIANGLES);
	for (j = 0; j < fs->np; j++) {
	    glColor4f(black[0], black[1], black[2], fs->p[j].c[0][3]);
	    glVertex3f(fs->p[j].p[0][0], 0.1, fs->p[j].p[0][2]);

	    glColor4f(black[0], black[1], black[2], fs->p[j].c[1][3]);
	    glVertex3f(fs->p[j].p[1][0], 0.1, fs->p[j].p[1][2]);

	    glColor4f(black[0], black[1], black[2], fs->p[j].c[2][3]);
	    glVertex3f(fs->p[j].p[2][0], 0.1, fs->p[j].p[2][2]);
	}
	glEnd();
    }

    glBegin(wire ? GL_LINE_STRIP : GL_TRIANGLES);
    for (j = 0; j < fs->np; j++) {
	/* draw particles: colors are computed in setpart */
	glColor4fv(fs->p[j].c[0]);
	glVertex3fv(fs->p[j].p[0]);

	glColor4fv(fs->p[j].c[1]);
	glVertex3fv(fs->p[j].p[1]);

	glColor4fv(fs->p[j].c[2]);
	glVertex3fv(fs->p[j].p[2]);

	setpart(fs, &fs->p[j]);
    }
    glEnd();

    /* draw rain particles if no fire particles */
    if (!fs->np)
    {
        float timeused = gettimerain();
        glDisable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glBegin(GL_LINES);
	for (j = 0; j < NUMPART; j++) {
	    glColor4f(0.7f,0.95f,1.0f,0.0f);
	    glVertex3fv(fs->r[j].oldpos);
	    glColor4f(0.3f,0.7f,1.0f,1.0f);
	    glVertex3fv(fs->r[j].pos);
	    setpartrain(fs, &fs->r[j],timeused);
	}
	glEnd();
	glShadeModel(GL_FLAT);
    }

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_FOG);

    /* manage framerate display */
    if (MI_IS_FPS(mi)) do_fps (mi);
    glPopMatrix();
}
Exemple #6
0
static void drawfire(void)
{
  static int count=0;
  static char frbuf[80];
  int	j;
  float fr;

  dojoy();

  glEnable(GL_DEPTH_TEST);

  if(fog)
    glEnable(GL_FOG);
  else
    glDisable(GL_FOG);

  glDepthMask(GL_TRUE);
  glClearColor(1.0,1.0,1.0,1.0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
  calcposobs();
  gluLookAt(obs[0],obs[1],obs[2],
	    obs[0]+dir[0],obs[1]+dir[1],obs[2]+dir[2],
	    0.0,1.0,0.0);

  glColor4f(1.0,1.0,1.0,1.0);

  glEnable(GL_TEXTURE_2D);

  glBindTexture(GL_TEXTURE_2D,groundid);
  glBegin(GL_QUADS);
  glTexCoord2fv(qt[0]);
  glVertex3fv(q[0]);
  glTexCoord2fv(qt[1]);
  glVertex3fv(q[1]);
  glTexCoord2fv(qt[2]);
  glVertex3fv(q[2]);
  glTexCoord2fv(qt[3]);
  glVertex3fv(q[3]);
  glEnd();

  glEnable(GL_ALPHA_TEST);
  glAlphaFunc(GL_GEQUAL,0.9);

  glBindTexture(GL_TEXTURE_2D,treeid);
  for(j=0;j<NUMTREE;j++)
    drawtree(treepos[j][0],treepos[j][1],treepos[j][2]);
  
  glDisable(GL_TEXTURE_2D);
  glDepthMask(GL_FALSE);
  glDisable(GL_ALPHA_TEST);

  if(shadows) {
    glBegin(GL_TRIANGLES);
    for(j=0;j<np;j++) {
      glColor4f(black[0],black[1],black[2],p[j].c[0][3]);
      glVertex3f(p[j].p[0][0],0.1,p[j].p[0][2]);

      glColor4f(black[0],black[1],black[2],p[j].c[1][3]);
      glVertex3f(p[j].p[1][0],0.1,p[j].p[1][2]);

      glColor4f(black[0],black[1],black[2],p[j].c[2][3]);
      glVertex3f(p[j].p[2][0],0.1,p[j].p[2][2]);
    }
    glEnd();
  }

  glBegin(GL_TRIANGLES);
  for(j=0;j<np;j++) {
    glColor4fv(p[j].c[0]);
    glVertex3fv(p[j].p[0]);

    glColor4fv(p[j].c[1]);
    glVertex3fv(p[j].p[1]);

    glColor4fv(p[j].c[2]);
    glVertex3fv(p[j].p[2]);

    setpart(&p[j]);
  }
  glEnd();

  if((count % FRAME)==0) {
    fr=gettime();
    sprintf(frbuf,"Frame rate: %f",FRAME/fr);
  }

  glDisable(GL_TEXTURE_2D);
  glDisable(GL_ALPHA_TEST);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_FOG);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-0.5,639.5,-0.5,479.5,-1.0,1.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glColor3f(1.0,0.0,0.0);
  glRasterPos2i(10,10);
  printstring(GLUT_BITMAP_HELVETICA_18,frbuf);
  glRasterPos2i(370,470);
  printstring(GLUT_BITMAP_HELVETICA_10,"Fire V1.5 Written by David Bucciarelli ([email protected])");

  if(help)
    printhelp();

  reshape(WIDTH,HEIGHT);
  glPopMatrix();

  glutSwapBuffers();

  count++;
}
Exemple #7
0
static void
drawfire(void)
{
   static char frbuf[80] = "";
   int j;
   static double t0 = -1.;
   double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
   if (t0 < 0.0)
      t0 = t;
   dt = (t - t0) * 1.0;
   t0 = t;

   dojoy();

   if (NiceFog)
      glHint(GL_FOG_HINT, GL_NICEST);
   else
      glHint(GL_FOG_HINT, GL_DONT_CARE);

   glEnable(GL_DEPTH_TEST);

   if (fog)
      glEnable(GL_FOG);
   else
      glDisable(GL_FOG);

   glDepthMask(GL_TRUE);
   glClearColor(1.0, 1.0, 1.0, 1.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glPushMatrix();
   calcposobs();
   gluLookAt(obs[0], obs[1], obs[2],
	     obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2],
	     0.0, 1.0, 0.0);

   glColor4f(1.0, 1.0, 1.0, 1.0);

   glEnable(GL_TEXTURE_2D);

   glBindTexture(GL_TEXTURE_2D, groundid);
#if 1
   glBegin(GL_QUADS);
   glTexCoord2fv(qt[0]);
   glVertex3fv(q[0]);
   glTexCoord2fv(qt[1]);
   glVertex3fv(q[1]);
   glTexCoord2fv(qt[2]);
   glVertex3fv(q[2]);
   glTexCoord2fv(qt[3]);
   glVertex3fv(q[3]);
   glEnd();
#else
   /* Subdivide the ground into a bunch of quads.  This improves fog
    * if GL_FOG_HINT != GL_NICEST
    */
   {
      float x, y;
      float dx = 1.0, dy = 1.0;
      glBegin(GL_QUADS);
      for (y = -DIMP; y < DIMP; y += 1.0) {
         for (x = -DIMP; x < DIMP; x += 1.0) {
            glTexCoord2f(0, 0);   glVertex3f(x, 0, y);
            glTexCoord2f(1, 0);   glVertex3f(x+dx, 0, y);
            glTexCoord2f(1, 1);   glVertex3f(x+dx, 0, y+dy);
            glTexCoord2f(0, 1);   glVertex3f(x, 0, y+dy);
         }
      }
      glEnd();
   }
#endif


   glEnable(GL_ALPHA_TEST);
   glAlphaFunc(GL_GEQUAL, 0.9);

   glBindTexture(GL_TEXTURE_2D, treeid);
   for (j = 0; j < NUMTREE; j++)
      drawtree(treepos[j][0], treepos[j][1], treepos[j][2]);

   glDisable(GL_TEXTURE_2D);
   glDepthMask(GL_FALSE);
   glDisable(GL_ALPHA_TEST);

   if (shadows) {
      glBegin(GL_TRIANGLES);
      for (j = 0; j < np; j++) {
	 glColor4f(black[0], black[1], black[2], p[j].c[0][3]);
	 glVertex3f(p[j].p[0][0], 0.1, p[j].p[0][2]);

	 glColor4f(black[0], black[1], black[2], p[j].c[1][3]);
	 glVertex3f(p[j].p[1][0], 0.1, p[j].p[1][2]);

	 glColor4f(black[0], black[1], black[2], p[j].c[2][3]);
	 glVertex3f(p[j].p[2][0], 0.1, p[j].p[2][2]);
      }
      glEnd();
   }

   glBegin(GL_TRIANGLES);
   for (j = 0; j < np; j++) {
      glColor4fv(p[j].c[0]);
      glVertex3fv(p[j].p[0]);

      glColor4fv(p[j].c[1]);
      glVertex3fv(p[j].p[1]);

      glColor4fv(p[j].c[2]);
      glVertex3fv(p[j].p[2]);

      setpart(&p[j]);
   }
   glEnd();

   glDisable(GL_TEXTURE_2D);
   glDisable(GL_ALPHA_TEST);
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_FOG);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glColor3f(1.0, 0.0, 0.0);
   glRasterPos2i(10, 10);
   printstring(GLUT_BITMAP_HELVETICA_18, frbuf);
   glRasterPos2i(370, 470);
   printstring(GLUT_BITMAP_HELVETICA_10,
	       "Fire V1.5 Written by David Bucciarelli ([email protected])");

   if (help)
      printhelp();

   reshape(WIDTH, HEIGHT);
   glPopMatrix();

   glutSwapBuffers();

   Frames++;
   {
      GLint t = glutGet(GLUT_ELAPSED_TIME);
      if (t - T0 >= 2000) {
         GLfloat seconds = (t - T0) / 1000.0;
         GLfloat fps = Frames / seconds;
         sprintf(frbuf, "Frame rate: %f", fps);
         printf("%s\n", frbuf);
         fflush(stdout);
         T0 = t;
         Frames = 0;
      }
   }
}
Exemple #8
0
int main(int argc, char** argv){
    int nodeCount = 10;
    if(argc > 1)
        nodeCount = atoi(argv[1]);
    bNode *a = NULL;
    Tree tree=(&a);
 /*   
    printf("instantiate tree..\n");
    printf("Adding elements using addL\n");
    for(int i = 10;i >= 0; i--)
        addL(tree,i);
    printf("Tree:\n");
    drawtree(tree);
    
    printf("Now removing all elements from the tree\n");
    
    while (size(tree)) {
        printf("--remvR--\n");
        remvR(tree);
        printf("Tree:\n");
        drawtree(tree);
    }
*/   

    printf("--------------------------\n");
    printf("Adding elements using addL\n");
    printf("--------------------------\n");
    for(int i = 0;i < nodeCount; i++){        
        printf("Adding %i using addL\n",i);
        addL(tree,i);
        printf("Tree:\n");
        printaslist(tree);
        drawtree(tree);
        printf("\n\n");
    }
    
    printf("--------------------------\n");
    printf("    Testing lookup        \n");
    printf("--------------------------\n");
    printf("Current tree as list:\n");
    printaslist(tree);
    for(int i = 0; i < size(tree); i++)
        printf("lookup: tree[%i] == %i\n",i,(int)lookup(tree,i));
    
    
    printf("-------------------------------\n");
    printf("Remove all elements using remvR\n");
    printf("-------------------------------\n");
    while (size(tree)) {
     remvR(tree);
     printf("Tree:\n");
     printaslist(tree);
     drawtree(tree);
     printf("\n\n");
    }
    
    printf("--------------------------\n");
    printf("Adding elements using addR\n");
    printf("--------------------------\n");
    for(int i = 0;i < nodeCount; i++){        
        printf("Adding %i using addR\n",i);
        addR(tree,i);
        printf("Tree:\n");
        printaslist(tree);
        drawtree(tree);
        printf("\n\n");
    }
    
    printf("-------------------------------\n");
    printf("Remove all elements using remvL\n");
    printf("-------------------------------\n");
    while (size(tree)) {
        remvL(tree);
        printf("Tree:\n");
        printaslist(tree);
        drawtree(tree);
        printf("\n\n");
    } 
    
    return 0;
}
void treeInit(int n)
{
    // draw a red tree
   glColor3f(1.0, 0.0, 0.0);
   drawtree(n);
}