Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to draw stem, twig, leaf?

Reply
Thread Tools

how to draw stem, twig, leaf?

 
 
Wonjun, Choi
Guest
Posts: n/a
 
      10-30-2011

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();
 
Reply With Quote
 
 
 
 
Jean-Christophe
Guest
Posts: n/a
 
      10-30-2011
On 30 oct, 15:56, "Wonjun, Choi"

> ...
> 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?
> ...


Why not like this ?

----

int twig, leaf, stem; // global

void FractalTree(int level)
{
int k;

k = ... ; // up to you

if( level == Level )
{
...
twig = calculate(k-1);
leaf = calculate(k+1);
stem = k;
glCallList(STEMANDLEAVES);
...
}
else
{
...
FractalTree( level + 1 );
...
}
}

 
Reply With Quote
 
 
 
 
Wonjun, Choi
Guest
Posts: n/a
 
      10-31-2011
I need to increase the size of stem, the count of twig and the count
of leaf.

To increase the size of stem.
---------------------------------------------------------------------------
glNewList(STEM, GL_COMPILE);
glPushMatrix();
glRotatef(-90, 1, 0, 0);
gluCylinder(cylquad, 0.1, 0.07, increase count, 10, 2 );
glPopMatrix();
glEndList();
---------------------------------------------------------------------------
increase count is as same as Total

To increase the count of twig.
I don't know how to make this loop even though I know I should modify
this part.
should I call glCallList(STEM) before glCallList(STEMANDLEAVES)?
and how can I attach the twig to the particular joint of stem?
---------------------------------------------------------------------------
if (level == Total) {
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();
---------------------------------------------------------------------------

To increase the count of leaf.
should I look at this part? I am not sure.
---------------------------------------------------------------------------
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();
---------------------------------------------------------------------------
 
Reply With Quote
 
Jean-Christophe
Guest
Posts: n/a
 
      10-31-2011
On 31 oct, 09:49, "Wonjun, Choi"

> I need to increase the size of stem, the count
> of twig and the count of leaf.
> To increase the size of stem.
> glNewList(STEM, GL_COMPILE);
> glPushMatrix();
> glRotatef(-90, 1, 0, 0);
> gluCylinder(cylquad, 0.1, 0.07, increase_count, 10, 2 );
> glPopMatrix();
> glEndList();


Okay, so now I understand your question,
wich is indeed an OpenGL related question !
( it would have been far better if you
formulated it correctly the first time )
So you have to post it back to <comp.graphics.api.opengl>

The point is that you created a glNewList(STEM,GL_COMPILE)
so you can't change the values of 'increase_count' stem
once the list has been created. Each time you will call
the drawing thru this pre-compiled list, its parameters
will still have the values given at the time you created it.

A solution will be to NOT use a precompiled list so you
can change whatever you want at the time of the drawing.
This mean that, instead of calling glCallList(STEMANDLEAVES)
you call a function which dynamically does the actual drawing :

void DrawStem( int increase_count )
{
glPushMatrix();
glRotatef(-90, 1, 0, 0);
gluCylinder(cylquad, 0.1, 0.07, increase_count, 10, 2 );
// etc ...
glPopMatrix();
}

I suggest that you formulate your question cristal-clear,
and don't post tons of code, otherwise
nobody will take the time to unscramble it.

HTH
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
gifs or jpgs won't draw on some pages dougbabacool@voila.fr Firefox 3 01-13-2006 11:20 PM
Can't draw new maps mapmaker Firefox 2 10-22-2004 03:31 AM
Re: !! IMPORTANT !! Problem with owner draw listbox Yair Cohen ASP .Net 0 09-04-2003 05:54 PM
tool to draw FSM bubble diagram Ingmar Seifert VHDL 5 08-01-2003 06:13 PM



Advertisments