week 4
1. 作業互相評選2. 主題:平移/旋轉/縮放
3. Mouse 操作
4. glTranslate f(x,y,z);
glRotate f(角度,x,y,z);
glScale f(x,y,z);
1.作業評選,選五張上傳MOODLE
2.先到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 下載教材(跟上週一樣)
3.到 FB 下載 freeglut
並且開啟 codeblocks,開 new project,選擇 GLUT 專案
#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
if(state == GLUT_DOWN)
printf("glVertex2f((%d-150)/150.0,-(%d-150)/150.0);\n",x,y);
}
void display()
{
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(175,193,81);
glBegin(GL_POLYGON);
glVertex2f((158-150)/150.0,(46-150)/150.0); /四個四個一組
glVertex2f((52-150)/150.0,(156-150)/150.0);
glVertex2f((163-150)/150.0,(231-150)/150.0);
glVertex2f((251-150)/150.0,(146-150)/150.0);
glEnd();
glBegin(GL_POLYGON);
glVertex2f((22-150)/150.0,-(25-150)/150.0);
glVertex2f((20-150)/150.0,-(81-150)/150.0);
glVertex2f((93-150)/150.0,-(77-150)/150.0);
glVertex2f((103-150)/150.0,-(19-150)/150.0);
glEnd();
glBegin(GL_POLYGON);
glVertex2f((214-150)/150.0,-(19-150)/150.0);
glVertex2f((217-150)/150.0,-(74-150)/150.0);
glVertex2f((127-150)/150.0,-(262-150)/150.0);
glVertex2f((185-150)/150.0,-(259-150)/150.0);
glEnd();
glBegin(GL_POLYGON);
glVertex2f((37-150)/150.0,-(113-150)/150.0); /三個三個一組
glVertex2f((37-150)/150.0,-(183-150)/150.0);
glVertex2f((287-150)/150.0,-(145-150)/150.0);
glEnd();
glBegin(GL_POLYGON);
glVertex2f((256-150)/150.0,-(105-150)/150.0);
glVertex2f((255-150)/150.0,-(182-150)/150.0);
glVertex2f((287-150)/150.0,-(141-150)/150.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMainLoop();
}
**圓形**
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void mouse(int button,int state,int x,int y)
{
if(state == GLUT_DOWN)
printf("glVertex2f((%d-150)/150.0,-(%d-150)/150.0);\n",x,y);
}
void display()
{
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(175,193,81);
glPushMatrix();
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
{
glVertex2f(0.2*cos(angle),0.2*sin(angle));
}
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0,0.5,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
{
glVertex2f( 0.2*cos(angle), 0.2*sin(angle) );
}
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5,0,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265357989 *2;angle+=0.1)
{
glVertex2f(0.2*cos(angle),0.2*sin(angle));
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言