W
Wonjun, Choi
void Calculator( int x, int *stem, int *twig, int *leaf )
{
int k = 0;
while( ++k <= x )
{ *twig = calculate( k-1 );
*leaf = calculate( k+1 );
*stem = i; // check it out !
}
}
this function is that which returns the count of stem, the
count of leaf, twig. I want to use this function in below opengl code.
how can I do?
the concept is below:
Total: 1, loop: 1, twig: 1, leaf: 4
Total: 2, loop: 1, twig: 1, leaf: 4
Total: 2, loop: 2, twig: 4, leaf: 1
Total: 3, loop: 1, twig: 1, leaf: 2
Total: 3, loop: 2, twig: 2, leaf: 3
Total: 3, loop: 3, twig: 5, leaf: 1
.......
as you can see the screenshot(http://ompldr.org/vYjB3NQ), I want to
draw like this
so I want to change below code. but I don't know how to change this:
below code draws tree.
void FractalTree(int level)
{
long savedseed; /* need to save seeds while building tree too */
if (level == Level) {
glPushMatrix();
glRotatef(drand48()*180, 0, 1, 0);
glCallList(STEMANDLEAVES);
glPopMatrix();
} else {
glCallList(STEM);
glPushMatrix();
glRotatef(drand48()*180, 0, 1, 0);
glTranslatef(0, 1, 0);
glScalef(0.7, 0.7, 0.7);
savedseed = (long) drand48()*ULONG_MAX; /* recurse on a 3-
way
branching */
glPushMatrix();
glRotatef(110 + drand48()*40, 0, 1, 0);
glRotatef(30 + drand48()*20, 0, 0, 1);
FractalTree(level + 1);
glPopMatrix();
// srand48(savedseed);
// savedseed = (long) drand48()*ULONG_MAX;
// glPushMatrix();
// glRotatef(-130 + drand48()*40, 0, 1, 0);
// glRotatef(30 + drand48()*20, 0, 0, 1);
// FractalTree(level + 1);
// glPopMatrix();
//
// srand48(savedseed);
// glPushMatrix();
// glRotatef(-20 + drand48()*40, 0, 1, 0);
// glRotatef(30 + drand48()*20, 0, 0, 1);
// FractalTree(level + 1);
// glPopMatrix();
glPopMatrix();
}
}
/*
* Create display lists for a leaf, a set of leaves, and a stem
*/
void CreateTreeLists(void)
{
GLUquadricObj *cylquad = gluNewQuadric();
int i;
// ÁÙ±â
glNewList(STEM, GL_COMPILE);
glPushMatrix();
glRotatef(-90, 1, 0, 0); // ÁÙ±âÀÇ °¢µµ
gluCylinder(cylquad, 0.1, 0.08, 1, 10, 2 ); //ÁÙ±âÀÇ ¿øÅë
glPopMatrix();
glEndList();
// ÀÙÀÇ ¾ç ¿·¸éÀ» ºÙ¿© Ç¥Çö
glNewList(LEAF, GL_COMPILE); /* I think this was jeff allen's leaf
idea */
glBegin(GL_TRIANGLES);
glNormal3f(-0.1, 0, 0.25); /* not normalized */ // Á¶¸íÀ» ³Ö±â À§ÇØ
glVertex3f(0, 0, 0);
glVertex3f(0.25, 0.25, 0.1);
glVertex3f(0, 0.5, 0);
// glNormal3f(0.1, 0, 0.25);
// glVertex3f(0, 0, 0);
// glVertex3f(0, 0.5, 0);
// glVertex3f(-0.25, 0.25, 0.1);
glEnd();
glEndList();
glNewList(STEMANDLEAVES, GL_COMPILE); //3°³ÀÇ °¡Áö
glPushMatrix();
glPushAttrib(GL_LIGHTING_BIT); //
glCallList(STEM); // 3°³ÀÇ °¡Áö »ý¼º
glCallList(LEAF_MAT); // ÀÙÀÇ »ö»ó
for(i = 0; i < 1; i++) {
glTranslatef(0, 0.333, 0); // ÀÙÀÌ Áٱ⿡ ºÙ¾îÀÖ´Â À§Ä¡ Á¶Àý
glRotatef(90, 0, 1, 0);
glPushMatrix();
glRotatef(0, 0, 1, 0);
glRotatef(50, 1, 0, 0);
glCallList(LEAF);
glPopMatrix();
// glPushMatrix();
// glRotatef(180, 0, 1, 0);
// glRotatef(60, 1, 0, 0);
// glCallList(LEAF);
// glPopMatrix();
}
glPopAttrib(); // »ö
glPopMatrix();
glEndList();
}
/*
* draw and build display list for tree
*/
void CreateTree(void)
{
srand48(TreeSeed);
glNewList(TREE, GL_COMPILE);
glPushMatrix();
glPushAttrib(GL_LIGHTING_BIT);
glCallList(TREE_MAT);
glTranslatef(0, -1, 0);
FractalTree(0);
glPopAttrib();
glPopMatrix();
glEndList();
{
int k = 0;
while( ++k <= x )
{ *twig = calculate( k-1 );
*leaf = calculate( k+1 );
*stem = i; // check it out !
}
}
this function is that which returns the count of stem, the
count of leaf, twig. I want to use this function in below opengl code.
how can I do?
the concept is below:
Total: 1, loop: 1, twig: 1, leaf: 4
Total: 2, loop: 1, twig: 1, leaf: 4
Total: 2, loop: 2, twig: 4, leaf: 1
Total: 3, loop: 1, twig: 1, leaf: 2
Total: 3, loop: 2, twig: 2, leaf: 3
Total: 3, loop: 3, twig: 5, leaf: 1
.......
as you can see the screenshot(http://ompldr.org/vYjB3NQ), I want to
draw like this
so I want to change below code. but I don't know how to change this:
below code draws tree.
void FractalTree(int level)
{
long savedseed; /* need to save seeds while building tree too */
if (level == Level) {
glPushMatrix();
glRotatef(drand48()*180, 0, 1, 0);
glCallList(STEMANDLEAVES);
glPopMatrix();
} else {
glCallList(STEM);
glPushMatrix();
glRotatef(drand48()*180, 0, 1, 0);
glTranslatef(0, 1, 0);
glScalef(0.7, 0.7, 0.7);
savedseed = (long) drand48()*ULONG_MAX; /* recurse on a 3-
way
branching */
glPushMatrix();
glRotatef(110 + drand48()*40, 0, 1, 0);
glRotatef(30 + drand48()*20, 0, 0, 1);
FractalTree(level + 1);
glPopMatrix();
// srand48(savedseed);
// savedseed = (long) drand48()*ULONG_MAX;
// glPushMatrix();
// glRotatef(-130 + drand48()*40, 0, 1, 0);
// glRotatef(30 + drand48()*20, 0, 0, 1);
// FractalTree(level + 1);
// glPopMatrix();
//
// srand48(savedseed);
// glPushMatrix();
// glRotatef(-20 + drand48()*40, 0, 1, 0);
// glRotatef(30 + drand48()*20, 0, 0, 1);
// FractalTree(level + 1);
// glPopMatrix();
glPopMatrix();
}
}
/*
* Create display lists for a leaf, a set of leaves, and a stem
*/
void CreateTreeLists(void)
{
GLUquadricObj *cylquad = gluNewQuadric();
int i;
// ÁÙ±â
glNewList(STEM, GL_COMPILE);
glPushMatrix();
glRotatef(-90, 1, 0, 0); // ÁÙ±âÀÇ °¢µµ
gluCylinder(cylquad, 0.1, 0.08, 1, 10, 2 ); //ÁÙ±âÀÇ ¿øÅë
glPopMatrix();
glEndList();
// ÀÙÀÇ ¾ç ¿·¸éÀ» ºÙ¿© Ç¥Çö
glNewList(LEAF, GL_COMPILE); /* I think this was jeff allen's leaf
idea */
glBegin(GL_TRIANGLES);
glNormal3f(-0.1, 0, 0.25); /* not normalized */ // Á¶¸íÀ» ³Ö±â À§ÇØ
glVertex3f(0, 0, 0);
glVertex3f(0.25, 0.25, 0.1);
glVertex3f(0, 0.5, 0);
// glNormal3f(0.1, 0, 0.25);
// glVertex3f(0, 0, 0);
// glVertex3f(0, 0.5, 0);
// glVertex3f(-0.25, 0.25, 0.1);
glEnd();
glEndList();
glNewList(STEMANDLEAVES, GL_COMPILE); //3°³ÀÇ °¡Áö
glPushMatrix();
glPushAttrib(GL_LIGHTING_BIT); //
glCallList(STEM); // 3°³ÀÇ °¡Áö »ý¼º
glCallList(LEAF_MAT); // ÀÙÀÇ »ö»ó
for(i = 0; i < 1; i++) {
glTranslatef(0, 0.333, 0); // ÀÙÀÌ Áٱ⿡ ºÙ¾îÀÖ´Â À§Ä¡ Á¶Àý
glRotatef(90, 0, 1, 0);
glPushMatrix();
glRotatef(0, 0, 1, 0);
glRotatef(50, 1, 0, 0);
glCallList(LEAF);
glPopMatrix();
// glPushMatrix();
// glRotatef(180, 0, 1, 0);
// glRotatef(60, 1, 0, 0);
// glCallList(LEAF);
// glPopMatrix();
}
glPopAttrib(); // »ö
glPopMatrix();
glEndList();
}
/*
* draw and build display list for tree
*/
void CreateTree(void)
{
srand48(TreeSeed);
glNewList(TREE, GL_COMPILE);
glPushMatrix();
glPushAttrib(GL_LIGHTING_BIT);
glCallList(TREE_MAT);
glTranslatef(0, -1, 0);
FractalTree(0);
glPopAttrib();
glPopMatrix();
glEndList();