2021年3月15日 星期一

如果能不跑800 week04

 1.茶壺方位



#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void mouse(int botton,int state,int x,int y)
{
    printf("botton:%d state:%d x:%d y:%d\n",botton,state,x,y);
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160431 如 week04");
    glutDisplayFunc(display);
    glutMouseFunc( mouse );
    glutMainLoop();
}


2.茶壺座標
   ///可以用滑鼠點出的座標加多邊形寫法畫出茶壺


#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}
void mouse(int botton,int state,int x,int y)
{
    printf(" glVertex3f((%d-150)/150.0, -(y-150)/150.0,0);\n");
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160431 如 week04");

    glutDisplayFunc(display);
    glutMouseFunc( mouse );

    glutMainLoop();
}


3.茶壺移動


#include <GL/glut.h>
#include <stdio.h>
float teapotX=0, teapotY=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslated(teapotX, teapotY,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glEnd();
    glutSwapBuffers();
}
///void mouse(int botton,int state,int x,int y)
///{
   /// printf(" glVertex3f((%d-150)/150.0, -(y-150)/150.0,0);\n");
///}

void motion(int x, int y)
{
    teapotX=(x-150)/150.0;
    teapotY=-(y-150)/150.0;
    display();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160431 如 week04");

    glutDisplayFunc(display);
    ///glutMouseFunc( mouse );
    glutMotionFunc(motion);
    glutMainLoop();
}


4.了解x,y,z 移動旋轉縮放




沒有留言:

張貼留言

Week18期末作業(橘貓的跳舞熊熊)

 期末作業(橘貓的跳舞熊熊) 影片: https://youtu.be/R89tptMaQZw 程式碼: #include <opencv/highgui.h> #include <opencv/cv.h> #include <GL/glut.h...