資源簡介
openGL實現分形樹的源代碼,openGL實現分形樹的源代碼

代碼片段和文件信息
#include?
#include?
#include?
#include?
#define?N?5
int?g_mousePosition[2]={0?0};
float?g_centerRotate[]={0?0?0};
bool?g_leftMouseButtonDown=false;
GLUquadric?*qObj;
GLuint?theLeaf;
float?R[N+1]?H[N+1]?k?p?q?m?alpha?z[N+1]?a=6;
float?Gauss(float?min?float?max)
{
int?a?=?rand()?b?=?rand()?c?=?rand()?d?=?rand();
int?x?=?a?+?b?+?c?+?d;
double?y?=?(x*sqrt(3))/RAND_MAX-sqrt(12);
double?mid?=?(min?+?max)/2;
float?z?=?(float)(mid?+?(max?-?mid)*y/(2*sqrt(3)));
return?z;
}
void?setData(void)
{
R[N]?=?0.3;
H[N]?=?2.4;
z[N]?=?H[N];
k?=?0.5;
p?=?0.6;
q?=?0.5;?
m?=?0.7;
alpha?=?45;
for(int?i=N-1;?i>=0;?i--)
{
R[i]?=?R[i+1]*q;
H[i]?=?H[i+1]*m;
z[i]?=?z[i+1]*p;
}
}
void?init?(void)
{
GLfloat?white_light[]={0.6?0.6?0.6?1.0};
GLfloat?light_position[]={4?4?4?0};
qObj?=?gluNewQuadric();
glClearColor(0.6?0.6?0.6?0.0);
glClearDepth(1.0);
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0?GL_AMBIENT?white_light);
glLightfv(GL_LIGHT0?GL_DIFFUSE?white_light);
glLightfv(GL_LIGHT0?GL_SPECULAR?white_light);
glLightfv(GL_LIGHT0?GL_POSITION?light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
}
void?drawTree(int?n)
{
GLfloat?no_mat[]?=?{0.0?0.0?0.0?1.0};
GLfloat?diffuse[]?=?{0.1?0.15?0.1?1.0};
GLfloat?specular[]?=?{0.1?0.1?0.1?1.0};
if(n?==?0)
{
float?h?=?Gauss(0.4?0.7);
gluCylinder(qObj?R[n]?k*R[n]?H[n]*h?20?20);
glTranslatef(0?0?H[n]*h);
glMaterialfv(GL_FRONT?GL_AMBIENT?no_mat);
glMaterialfv(GL_FRONT?GL_DIFFUSE?diffuse);
glMaterialfv(GL_FRONT?GL_SPECULAR?specular);
glMaterialf(GL_FRONT?GL_SHININESS?5);
glRotatef(Gauss(10?50)?1?0?0);
glRotatef(45?0?1?0);
glRotatef(90?1?0?0);
glScalef(1?1?0.1);
glutSolidCube(0.15);
return;
}
else
{
gluCylinder(qObj?R[n]?k*R[n]?H[n]?20?20);
glTranslatef(0?0?H[n]);
glPushMatrix();
glTranslatef(0?0?-H[n]*Gauss(0.0?0.4));
glRotatef(Gauss(30?80)?0?0?1);
glRotatef(Gauss(40?70)?0?1?0);
drawTree(n-1);
glPopMatrix();
glPushMatrix();
glTranslatef(0?0?-H[n]*Gauss(0.0?0.4));
glRotatef(Gauss(140?200)?0?0?1);
glRotatef(Gauss(40?70)?0?1?0);
drawTree(n-1);
glPopMatrix();
glPushMatrix();
glTranslatef(0?0?-H[n]*Gauss(0.0?0.4));
glRotatef(Gauss(260?320)?0?0?1);
glRotatef(Gauss(40?70)?0?1?0);
drawTree(n-1);
glPopMatrix();
glRotatef(Gauss(5?15)?0?1?0);
glRotatef(Gauss(30?50)?0?0?1);
drawTree(n-1);
}
}
void?display?(void)
{
GLfloat?no_mat[]?=?{0.0?0.0?0.0?1.0};
GLfloat?tree_diffuse[]?=?{0.3?0.25?0.1?1.0};
GLfloat?tree_specular[]?=?{0.1?0.1?0.1?1.0};
glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
glLoadIdentity?();
gluLookAt(0.0?-4.0?0.0?0.0?0.0?0.0?0.0?0.0?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????217140??2009-10-18?19:49??open?gl實現分形樹\Debug\test.exe
?????文件?????299156??2009-10-18?19:49??open?gl實現分形樹\Debug\test.ilk
?????文件??????18671??2009-10-18?19:48??open?gl實現分形樹\Debug\test.obj
?????文件?????443392??2009-10-11?21:47??open?gl實現分形樹\Debug\test.pdb
?????文件??????41984??2010-04-23?16:58??open?gl實現分形樹\Debug\vc60.idb
?????文件??????61440??2009-10-11?21:47??open?gl實現分形樹\Debug\vc60.pdb
?????文件???????5449??2006-06-08?14:40??open?gl實現分形樹\test.cpp
?????文件???????3377??2006-06-08?13:30??open?gl實現分形樹\test.dsp
?????文件????????533??2006-06-08?18:28??open?gl實現分形樹\test.dsw
?????文件?????217138??2006-06-08?14:40??open?gl實現分形樹\test.exe
?????文件??????50176??2010-04-23?16:59??open?gl實現分形樹\test.ncb
?????文件??????53760??2010-04-23?16:59??open?gl實現分形樹\test.opt
?????文件????????738??2009-10-18?19:49??open?gl實現分形樹\test.plg
?????目錄??????????0??2009-10-11?21:47??open?gl實現分形樹\Debug
?????目錄??????????0??2010-04-23?16:59??open?gl實現分形樹
-----------?---------??----------?-----??----
??????????????1413172????????????????????16
- 上一篇:基于LABVIEW的AM信號的調制和解調
- 下一篇:Gmres算法解線性方程組
評論
共有 條評論