Skip to main content

Recursive subdivision of tetrahedron to form 3D Sierpinski gasket using OpenGL

/* Recursive subdivision of tetrahedron to form 3D Sierpinski gasket */ #include #include typedef float point[3]; void menu(int); /* initial tetrahedron */ point v[]={{0.0, 0.0, 1.0}, {0.0, 0.942809, -0.33333}, {-0.816497, -0.471405, -0.333333}, {0.816497, -0.471405, -0.333333}}; static GLfloat theta[] = {0.0,0.0,0.0}; int n; void triangle( point a, point b, point c) /* display one triangle using a line loop for wire frame, a single normal for constant shading, or three normals for interpolative shading */ { glBegin(GL_POLYGON); glNormal3fv(a); glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); glEnd(); } void divide_triangle(point a, point b, point c, int m) { /* triangle subdivision using vertex numbers righthand rule applied to create outward pointing faces */ point v1, v2, v3; int j; if(m>0) { for(j=0; j<3; j++) v1[j]=(a[j]+b[j])/2; for(j=0; j<3; j++) v2[j]=(a[j]+c[j])/2; for(j=0; j<3; j++) v3[j]=(b[j]+c[j])/2; divide_triangle(a, v1, v2, m-1); divide_triangle(c, v2, v3, m-1); divide_triangle(b, v3, v1, m-1); } else(triangle(a,b,c)); /* draw triangle at end of recursion */ } void tetrahedron( int m) { /* Apply triangle subdivision to faces of tetrahedron */ 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 menu(int id) { if (id != 20) { n= id; } else { exit(0); } } 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) { int m_menu; if(argc>1) n=atoi(argv[1]); else n=4; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow("3D Gasket"); m_menu= glutCreateMenu(menu); glutAddMenuEntry("1",1); glutAddMenuEntry("2",2); glutAddMenuEntry("3",3); glutAddMenuEntry("4",4); glutAddMenuEntry("5",5); glutAddMenuEntry("6",6); glutAddMenuEntry("7",7); glutAddMenuEntry("8",8); glutAddMenuEntry("9",9); glutAddMenuEntry("10",10); glutAddMenuEntry("11",11); // glutAddMenuEntry("12",12); // glutAddMenuEntry("13",13); glutAddMenuEntry("Exit",20); glutAttachMenu(GLUT_LEFT_BUTTON); glutReshapeFunc(myReshape); glutDisplayFunc(display); glEnable(GL_DEPTH_TEST); glClearColor (1.0, 1.0, 1.0, 1.0); glutMainLoop(); }

Comments

Popular posts from this blog

Maxon Cinema 4D Studio R13.058 full Keygen Cracked Version | Mediafire Torrent Download Link

Download Maxon CINEMA 4D Studio Full Version With Keygen -Everything You Need for High-End 3D 32 and 64 bit MAXON CINEMA 4D STUDIO R13.058 (x86/x64) CINEMA 4D Studio is the very best that MAXON has to offer for professional 3D artists. If you want to create advanced 3D graphics but need a helping hand to ensure you create jaw-dropping graphics quickly and easily, then this is the choice for you.                     All You Ever Wanted This is our top-of-the-line product. It not only contains everything the other CINEMA 4D versions offer - it goes far beyond. CINEMA 4D Studio has all the tools you need to tackle even the most complex project. Minimum System Requirements Windows XP, Vista or 7 running on Intel or AMD CPU with SSE2-Support; Mac OS X 10.5.8 or higher running on an Intel-based Mac; 1024 MB free RAM, DVD ROM drive. Standard DVD installation can take up to 4 GB of disk space. Software must be registered for permanent use. SUPPORTED OPERATING SYS

C Program to add two matrices using pointers.

  #include<stdio.h> main() { int a[5][5],b[5][5],c[5][5],i,j,m,n; printf("\n Enter the Dimension of the Matrix:\n"); scanf("%d%d",&m,&n); printf("\nEnter the Elements of the first matix:"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",(*(a+i)+j)); } } printf("\nEnter the elements of the second matrix:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",(*(b+i)+j)); } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { *(*(c+i)+j)=*(*(a+i)+j)+ *(*(b+i)+j); } } printf("\nResultantMatrix:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%5d",*(*(c+i)+j)); } printf("\n"); } getch(); } Output:  Enter the Dimension of the Matrix: 2  2 Enter the Elements of the first matix: 1   2   3   4 Enter the elements of the second matrix: 9   8   7  6 ResultantMatrix:  

C Program to create a Teapot using OpenGL

  C Program to create a Teapot using OpenGL # include <stdio.h> # include <GL/glut.h> void wall ( double thickness ) { glPushMatrix ( ) ; glTranslated ( 0.5 , 0.5 * thickness , 0.5 ) ; glScaled ( 1.0 , thickness , 1.0 ) ; glutSolidCube ( 1.0 ) ; glPopMatrix ( ) ; } void tableLeg ( double thick , double len ) { glPushMatrix ( ) ; glTranslated ( 0 , len / 2 , 0 ) ; glScaled ( thick , len , thick ) ; glutSolidCube ( 1.0 ) ; glPopMatrix ( ) ; } void table ( double topWid , double topThick , double legThick , double legLen ) { glPushMatrix ( ) ; glTranslated ( 0 , legLen , 0 ) ; glScaled ( topWid , topThick , topWid ) ; glutSolidCube ( 1.0 ) ; glPopMatrix ( ) ; double dist = 0.95 * topWid / 2.0 - legThick / 2.0 ; glPushMatrix ( ) ; glTranslated ( dist , 0 , dist ) ; tableLeg ( legThick , legLen ) ; glTranslated ( 0.0 , 0.0 , - 2 * dist ) ; tableLeg ( legThick , legLen ) ; glTransla