opengl: modeling void drawpyramid(){ glbegin(gl_triangles); glvertex3f(0.0, 0.0, 0.0);...

5
OpenGL: Modeling id 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() ;

Upload: neil-morton

Post on 13-Dec-2015

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 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,

OpenGL: Modelingvoid 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() ; }

Page 2: 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,

Modeling: Conevoid 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() ; }

Page 3: 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,

Modeling: cylindervoid 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() ; }

Page 4: 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,

Scene // Set UpglViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity() ;

glOrtho(-100,100,-100,100,-100,100);glMatrixMode(GL_MODELVIEW);glLoadIdentity();

// Draw SceneglClear(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() ;

Page 5: 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,

Scene // Draw CubeglPushMatrix() ;glTranslate(10,0,2);glScale(5,10,5)DrawCube(10);glPopMatrix() ;// Draw ConesglPushMatrix() ;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() ;