Download presentation
Presentation is loading. Please wait.
Published byNeil Morton Modified over 9 years ago
1
OpenGL: Modeling void DrawPyramid(){ glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.1, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 1.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.1, 0.0, 0.0); glVertex3f(0.0, 0.1, 0.0); glVertex3f(0.0, 0.0, 0.1); glEnd() ; }
2
Modeling: Cone void DrawCone(int res){ GLfloat d = 2*PI/res ; GLfloat a = 0; glBegin(GL_TRIANGLE_FAN); glVertex3f(0.0, 0.0, 0.0); for (int i = 0 ; i < res ; i++ ){ glVertex3f(cos(a), sin(a), 0.0); a += d ; } glEnd() ; a = 0.0 ; glBegin(GL_TRIANGLE_FAN); glVertex3f(0.0, 0.0, 1.0); for (int i = 0 ; i < res ; i++ ){ glVertex3f(cos(a), sin(a), 0.0); a += d ; } glEnd() ; }
3
Modeling: cylinder void DrawCylinder (int res){ GLfloat a, d = 2*PI/res ; glBegin(GL_TRIANGLE_FAN); glVertex3f(0.0, 0.0, 0.0); for (int i = 0, a = 0 ; i < res ; i++,a += d ) glVertex3f(cos(a), sin(a), 0.0); glEnd() ; glBegin(GL_TRIANGLE_FAN); glVertex3f(0.0, 0.0, 1.0); for ( i = 0, a = 0 ; i < res ; i++, a += d ) glVertex3f(cos(a), sin(a), 1.0); glEnd() ; glBegin(GL_TRIANGLE_STRIP); for ( i = 0, a = 0 ; i < res; i++, a += d) { glVertex3f(cos(a), sin(a), 0.0); glVertex3f(cos(a), sin(a), 1.0); } glEnd() ; }
4
Scene // Set Up glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity() ; glOrtho(-100,100,-100,100,-100,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Draw Scene glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Draw Cylinder glPushMatrix() ; glRotate(90, 1,0,0); glTranslate(0,0,10); glScale(10,10,10) DrawCylinder(50); glPopMatrix() ;
5
Scene // Draw Cube glPushMatrix() ; glTranslate(10,0,2); glScale(5,10,5) DrawCube(10); glPopMatrix() ; // Draw Cones glPushMatrix() ; glRotate(90, 0,1,0); glRotate(45, 0,0,1); glPushMatrix(); glTranslate(5,0,5); glScale(5,5,5) DrawCone(10); glPopMatrix() ; glTranslate(5,10,5); glScale(10,10,10); DrawCone(10); glPopMatrix() ;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.