2023年3月1日 星期三

辰_電腦圖學Week03

 

Week03 移動~~


上週的作業忘記做ㄌ..

以下期中必考
_______________________________

glTranslatef(x,y,z) 

glPushMatrix() 

glPopMatrix()

____________________________


先建置上週所教的作業環境
以及下載老師給的檔案

 https://jsyeh.org/3dcg10/

data data.zip // win32 windows.zip // glut32.dll

解壓縮 // windows.zip //找到transformation.exe

 // 把data丟進windows裡解壓  // data.zip 模型庫





設置茶壺 利用滑鼠幫忙

#include <GL/glut.h>
void display()
{

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///重要
    glPushMatrix(); //備份矩陣
        glTranslatef( 0.5 , 0, 0); //圖形會亂動,不要忘記f(浮點數)
        glutSolidTeapot( 0.3 );
    glPopMatrix();//還原矩陣
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutCreateWindow("GLUT Shapes");
  glutDisplayFunc(display);
  glutMainLoop();
}


________________________________________________
滑鼠可以標點!!!

#include <GL/glut.h>

#include <stdio.h>

void display()

{

    glBegin(GL_POLYGON);

    glVertex2f(1.816, -0.860);

    glVertex2f(1.860, -0.640);

    glVertex2f(1.960, -0.400);

    glVertex2f(2.064, -0.240);

    glVertex2f(2.196, -0.140);

    glVertex2f(2.292, -0.100);

    glVertex2f(2.480, -0.064);

    glVertex2f(2.588, -0.060);

    glVertex2f(2.824, -0.092);

    glVertex2f(3.016, -0.140);

    glVertex2f(3.136, -0.176);

    glVertex2f(3.268, -0.240);

    glVertex2f(3.360, -0.320);

    glVertex2f(3.452, -0.440);

    glVertex2f(3.476, -0.544);

    glVertex2f(3.496, -0.660);

    glVertex2f(3.472, -0.724);

    glVertex2f(3.420, -0.756);

    glVertex2f(3.320, -0.768);

    glVertex2f(3.184, -0.780);

    glVertex2f(2.936, -0.784);

    glVertex2f(2.800, -0.792);

    glVertex2f(2.536, -0.780);

    glVertex2f(2.300, -0.764);

    glVertex2f(2.180, -0.764);

    glVertex2f(1.948, -0.764);

    glVertex2f(1.928, -0.764);

    glVertex2f(1.920, -0.764);

    glEnd();

    glBegin(GL_POLYGON);

    glEnd();

    glutSwapBuffers();

}


void mouse(int button, int state, int x, int y) ///小寫的

{

    float X = (x-250)/250.0;

    float Y = -(y-250)/250.0; ///口訣: 減一半、除一半, y負號

    if(state==GLUT_DOWN){  ///只有按下mouse,才印出程式,等下要剪貼!

        printf("    glVertex2f(%.3f, %.3f);\n", X, Y);

    }

}

int main(int argc, char* argv[] )

{

    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);

    glutInitWindowSize(1980,1080);

    glutCreateWindow("glut draw");


    glutDisplayFunc(display);

    glutMouseFunc(mouse); ///呼叫函式


    glutMainLoop();

}


沒有留言:

張貼留言