#include "stdio.h"
#include "stdlib.h"
#include "GL/glut.h"
typedef float point[3];
point v[]=
{{0.0,0.0,1.0},{0.0,0.9,-0.3},{-0.8,-0.4,-0.3},{0.8,-0.4,-0.3}};
static float theta[]={0.0,0.0,0.0};
int n;
void triangle(point a,point b,point c)
{
glBegin(GL_POLYGON);
glNormal3fv(a);
glVertex3fv(a);
glVertex3fv(b);
glVertex3fv(c);
glEnd();
}
void divide_triangle(point a,point b,point c,int m)
{
point v1,v2,v3;
int j;
if(m>0)
{
for(j=0;j<3;j++) j="0;j<3;j++)" j="0;j<3;j++)">
void tetrahedron(int m)
{
glColor3f(1.0,0.0,0.0);
divide_triangle(v[0],v[1],v[2],m);
glColor3f(0.0,1.0,0.0);
divide_triangle(v[3],v[2],v[1],m);
glColor3f(0.0,0.0,1.0);
divide_triangle(v[0],v[3],v[1],m);
glColor3f(0.0,0.0,0.0);
divide_triangle(v[0],v[2],v[3],m);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
tetrahedron(n);
glFlush();
}
void myReshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h) glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); else glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0,-10.0,10.0); glMatrixMode(GL_MODELVIEW); glutPostRedisplay(); }
void main(int argc, char **argv)
{
printf("No. of subdivisions\n");
scanf("%d",&n);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("3dgasket");
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glEnable(GL_DEPTH_TEST); //extremely important..!
glClearColor(1.0,1.0,1.0,1.0);
glutMainLoop();
}
小波思基
- 粉丝: 86
- 资源: 1万+
最新资源
- 白色简洁风格的旅行线路企业网站模板下载.zip
- 白色简洁风格的旅游服务整站网站源码下载.zip
- 白色简洁风格的旅游酒店入住后台管理源码下载.zip
- 白色简洁风格的旅游徒步企业网站模板.zip
- 白色简洁风格的旅游视频网页模板下载.zip
- 白色简洁风格的忙碌中倒计时源码下载.zip
- 白色简洁风格的律师法律机构整战网站模板.rar
- 白色简洁风格的律师业务企业网站源码下载.zip
- 白色简洁风格的迷雾森林404错误页源码下载.zip
- 白色简洁风格的美味餐厅整站网站源码下载.zip
- 白色简洁风格的美味食材餐厅整站网站源码下载.zip
- 白色简洁风格的木材加工制造模板下载.zip
- 白色简洁风格的木板绿叶404错误页源码下载.zip
- 白色简洁风格的男士内裤专卖整站网站源码下载.zip
- 白色简洁风格的鸟类大全整站网站模板.zip
- 白色简洁风格的农业科技公司企业网站源码下载.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈