2020年3月17日 星期二

Sunnnnnnnnnnnnnn

第三週哦哦哦哦哦


複習

到 -> http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下載data . win32(解壓縮) . glut32.dll
之後把data裡面的資料夾與glut32.dll放到win32裡
打開裡面的shape~



No.1

複習上個禮拜的茶壺 Teapot
順便考慮一下晚餐要吃什麼?


新增一行程式碼 是這週的作業:滑鼠

關於滑鼠的程式碼
下面的Printf是讓我們知道"值"


第一行
0是左鍵 1是中鍵 2是右鍵

第二行
0是壓下1是彈起

第三四行是x,y軸


這是改完以後的程式碼
把座標值改好
滑鼠點哪裡,茶壺就到哪裡


茶裡查理

...?
-----


程式碼:
#include <GL/glut.h>
#include <stdio.h>
float teapotX=0, teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(teapotX, teapotY, 0);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
    printf("%f %f\n", (x-150)/150.0, (y-150)/150.0);
    teapotX=  (x-150)/150.0;
    teapotY= -(y-150)/150.0;
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");


    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

-----


No.2

Main程式不變
以下的程式碼可以自己畫出想要的圖形
先在小黑窗點想要的圖案
複製座標位置貼到程式碼
再跑一次就會出來了哦 水拉!

-----
程式碼:
#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glVertex2f((163-150)/150.0, - (35-150)/150.0);
    glVertex2f((124-150)/150.0, - (92-150)/150.0);
     glVertex2f((82-150)/150.0, - (137-150)/150.0);
    glVertex2f((37-150)/150.0, - (205-150)/150.0);
    glVertex2f((110-150)/150.0, - (210-150)/150.0);
    glVertex2f((183-150)/150.0, - (210-150)/150.0);
    glVertex2f((279-150)/150.0, - (214-150)/150.0);
    glVertex2f((246-150)/150.0, - (160-150)/150.0);
    glVertex2f((206-150)/150.0, - (90-150)/150.0);
    glVertex2f((161-150)/150.0, - (28-150)/150.0);
    glVertex2f((144-150)/150.0, - (2-150)/150.0);


glEnd();
glutSwapBuffers();
}
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);
    }
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");


    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

-----


以下是回家作業與它超~長的程式碼
大家記得戴口罩





---
碼:
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>

void display()

{
    glClearColor(255,255,255,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_POLYGON);
    glColor3f(0.0,0.0,0.0);
    glVertex2f((280-150)/150.0, - (20-150)/150.0);
    glVertex2f((280-150)/150.0, - (280-150)/150.0);
    glVertex2f((20-150)/150.0, - (280-150)/150.0);
    glVertex2f((20-150)/150.0, - (20-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(255.0,255.0,255.0);
    glVertex2f(115/150.0, - (-115)/150.0);
    glVertex2f(115/150.0, - (115)/150.0);
    glVertex2f(-115/150.0, - (115)/150.0);
    glVertex2f(-115/150.0, - (-115)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(255.0,255.0,255.0);
    glVertex2f((95-150)/150.0, - (265-150)/150.0);
    glVertex2f((205-150)/150.0, - (265-150)/150.0);
    glVertex2f((200-150)/150.0, - (280-150)/150.0);
    glVertex2f((100-150)/150.0, - (280-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f((59/255.0),(191/255.0),(237/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.17*cos(angle)-0.3,0.17*sin(angle));
    }
    glEnd();


    glBegin(GL_POLYGON);
    glColor3f((243/255.0),(90/255.0),(95/255.0));
    for(float angle=0 ; angle<=3.1415926 * 2 ;angle+=0.01)
    {
    glVertex2f(0.17*cos(angle)+0.3,0.17*sin(angle));
    }
    glEnd();


    glBegin(GL_POLYGON);
    glColor3f(255/255.0,255/255.0,255/255.0);
    glVertex2f((105-150)/150.0, - (164-150)/150.0);
    glVertex2f((111-150)/150.0, - (166-150)/150.0);
    glVertex2f((124-150)/150.0, - (149-150)/150.0);
    glVertex2f((119-150)/150.0, - (147-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(255/255.0,255/255.0,255/255.0);
    glVertex2f((195-150)/150.0, - (164-150)/150.0);
    glVertex2f((201-150)/150.0, - (166-150)/150.0);
    glVertex2f((214-150)/150.0, - (149-150)/150.0);
    glVertex2f((209-150)/150.0, - (147-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,0.0,0.0);
    glVertex2f((138-150)/150.0, - (147-150)/150.0);
    glVertex2f((138-150)/150.0, - (154-150)/150.0);
    glVertex2f((165-150)/150.0, - (153-150)/150.0);
    glVertex2f((166-150)/150.0, - (146-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,0.0,0.0);
    glVertex2f((96-150)/150.0, - (100-150)/150.0);
    glVertex2f((69-150)/150.0, - (151-150)/150.0);
    glVertex2f((77-150)/150.0, - (151-150)/150.0);
    glVertex2f((105-150)/150.0, - (100-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,0.0,0.0);
    glVertex2f((134-150)/150.0, - (89-150)/150.0);
    glVertex2f((107-150)/150.0, - (135-150)/150.0);
    glVertex2f((116-150)/150.0, - (135-150)/150.0);
    glVertex2f((142-150)/150.0, - (89-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,0.0,0.0);
    glVertex2f((162-150)/150.0, - (87-150)/150.0);
    glVertex2f((137-150)/150.0, - (133-150)/150.0);
    glVertex2f((144-150)/150.0, - (133-150)/150.0);
    glVertex2f((170-150)/150.0, - (87-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,0.0,0.0);
    glVertex2f((187-150)/150.0, - (87-150)/150.0);
    glVertex2f((166-150)/150.0, - (125-150)/150.0);
    glVertex2f((173-150)/150.0, - (125-150)/150.0);
    glVertex2f((195-150)/150.0, - (87-150)/150.0);
    glEnd();

     glBegin(GL_POLYGON);
    glVertex2f((212-150)/150.0, - (105-150)/150.0);
    glVertex2f((237-150)/150.0, - (123-150)/150.0);
    glVertex2f((237-150)/150.0, - (118-150)/150.0);
    glVertex2f((212-150)/150.0, - (100-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glVertex2f((212-150)/150.0, - (120-150)/150.0);
    glVertex2f((237-150)/150.0, - (138-150)/150.0);
    glVertex2f((237-150)/150.0, - (133-150)/150.0);
    glVertex2f((212-150)/150.0, - (115-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glVertex2f((76-150)/150.0, - (178-150)/150.0);
    glVertex2f((79-150)/150.0, - (218-150)/150.0);
    glVertex2f((95-150)/150.0, - (227-150)/150.0);
    glVertex2f((105-150)/150.0, - (233-150)/150.0);
    glVertex2f((119-150)/150.0, - (239-150)/150.0);
    glVertex2f((135-150)/150.0, - (243-150)/150.0);
    glVertex2f((153-150)/150.0, - (246-150)/150.0);
    glVertex2f((176-150)/150.0, - (242-150)/150.0);
    glVertex2f((194-150)/150.0, - (236-150)/150.0);
    glVertex2f((209-150)/150.0, - (232-150)/150.0);
    glVertex2f((225-150)/150.0, - (212-150)/150.0);
    glVertex2f((225-150)/150.0, - (183-150)/150.0);
    glVertex2f((225-150)/150.0, - (179-150)/150.0);
    glVertex2f((190-150)/150.0, - (179-150)/150.0);
    glVertex2f((162-150)/150.0, - (179-150)/150.0);
    glVertex2f((151-150)/150.0, - (180-150)/150.0);
    glVertex2f((122-150)/150.0, - (177-150)/150.0);
    glVertex2f((102-150)/150.0, - (179-150)/150.0);
    glVertex2f((78-150)/150.0, - (180-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glVertex2f((79-150)/150.0, - (186-150)/150.0);
    glVertex2f((67-150)/150.0, - (176-150)/150.0);
    glVertex2f((55-150)/150.0, - (176-150)/150.0);
    glVertex2f((50-150)/150.0, - (192-150)/150.0);
    glVertex2f((55-150)/150.0, - (207-150)/150.0);
    glVertex2f((63-150)/150.0, - (214-150)/150.0);
    glVertex2f((80-150)/150.0, - (217-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glVertex2f((223-150)/150.0, - (186-150)/150.0);
    glVertex2f((229-150)/150.0, - (182-150)/150.0);
    glVertex2f((238-150)/150.0, - (178-150)/150.0);
    glVertex2f((230-150)/150.0, - (185-150)/150.0);
    glVertex2f((239-150)/150.0, - (178-150)/150.0);
    glVertex2f((246-150)/150.0, - (177-150)/150.0);
    glVertex2f((250-150)/150.0, - (181-150)/150.0);
    glVertex2f((252-150)/150.0, - (189-150)/150.0);
    glVertex2f((251-150)/150.0, - (199-150)/150.0);
    glVertex2f((247-150)/150.0, - (206-150)/150.0);
    glVertex2f((237-150)/150.0, - (213-150)/150.0);
    glVertex2f((229-150)/150.0, - (216-150)/150.0);
    glVertex2f((219-150)/150.0, - (215-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(255.0,255.0,255.0);
    glVertex2f((75-150)/150.0, - (191-150)/150.0);
    glVertex2f((78-150)/150.0, - (208-150)/150.0);
    glVertex2f((70-150)/150.0, - (209-150)/150.0);
    glVertex2f((60-150)/150.0, - (204-150)/150.0);
    glVertex2f((58-150)/150.0, - (197-150)/150.0);
    glVertex2f((56-150)/150.0, - (187-150)/150.0);
    glVertex2f((61-150)/150.0, - (181-150)/150.0);
    glVertex2f((67-150)/150.0, - (182-150)/150.0);
    glVertex2f((77-150)/150.0, - (192-150)/150.0);

    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(255.0,255.0,255.0);
    glVertex2f((224-150)/150.0, - (191-150)/150.0);
    glVertex2f((222-150)/150.0, - (207-150)/150.0);
    glVertex2f((230-150)/150.0, - (207-150)/150.0);
    glVertex2f((237-150)/150.0, - (205-150)/150.0);
    glVertex2f((242-150)/150.0, - (203-150)/150.0);
    glVertex2f((244-150)/150.0, - (198-150)/150.0);
    glVertex2f((244-150)/150.0, - (195-150)/150.0);
    glVertex2f((244-150)/150.0, - (187-150)/150.0);
    glVertex2f((242-150)/150.0, - (184-150)/150.0);
    glVertex2f((234-150)/150.0, - (188-150)/150.0);
    glVertex2f((224-150)/150.0, - (190-150)/150.0);
    glVertex2f((224-150)/150.0, - (204-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(180/255.0,180/255.0,180/255.0);
    glVertex2f((83-150)/150.0, - (183-150)/150.0);
    glVertex2f((150-150)/150.0, - (186-150)/150.0);
    glVertex2f((218-150)/150.0, - (183-150)/150.0);
    glVertex2f((217-150)/150.0, - (185-150)/150.0);
    glVertex2f((150-150)/150.0, - (187-150)/150.0);
    glVertex2f((84-150)/150.0, - (185-150)/150.0);
    glEnd();


    glBegin(GL_POLYGON);
    glColor3f(180/255.0,180/255.0,180/255.0);
    glVertex2f((156-150)/150.0, - (240-150)/150.0);
    glVertex2f((207-150)/150.0, - (228-150)/150.0);
    glVertex2f((207-150)/150.0, - (230-150)/150.0);
    glVertex2f((156-150)/150.0, - (242-150)/150.0);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(180/255.0,180/255.0,180/255.0);
    glVertex2f((207-150)/150.0, - (230-150)/150.0);
    glVertex2f((218-150)/150.0, - (216-150)/150.0);
    glVertex2f((216-150)/150.0, - (216-150)/150.0);
    glVertex2f((204-150)/150.0, - (230-150)/150.0);
    glEnd();

glutSwapBuffers();
}

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);
    }
}

int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week03");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

-----







6 則留言: