2021年3月15日 星期一

week04之人傑騙老師用teams上課

 1、先用上週的茶壺程式碼

#include<GL/glut.h>//使用GLUT外掛

#include<stdio.h>//今日02

void display()

{

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//清空

    glutSolidTeapot(0.3);//實心茶壺

    glutSwapBuffers();//交換兩倍的buffers

}

void mouse(int button,int state,int x,int y)//今日03

{

    printf("button:%d,state:%d,x:%d,y:%d\n",button,state,x,y);

}

int main(int argc,char**argv)//以前是int main()

{

    glutInit(&argc,argv);//GLUT初始值

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//顯示模式

    glutCreateWindow("week04");//開窗

    glutDisplayFunc(display);//等一下要顯示的函式

    glutMouseFunc(mouse);//今日01

    glutMainLoop();//主要迴圈

}

今日01為滑鼠函數 03的button為滑鼠左右滾輪 state為按或放 x,y分別為座標
2、把void mouse(int button,int state,int x,int y)//今日03

{

    printf("button:%d,state:%d,x:%d,y:%d\n",button,state,x,y);

}裡面改成

if(state==GLUT_DOWN){

        printf("glVertex3f((%d-150)/150.0,-(%d-150)/150.0\n",x,y);

 }假如現在狀態為放開滑鼠會顯示座標





3、
#include<GL/glut.h>//使用GLUT外掛
#include<stdio.h>//今日02
float teapotx=0,teapoty=0;//今日2-01
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//清空
    glPushMatrix();//今日2-03矩陣備份
    glTranslated(teapotx,teapoty,0);//今日2-04照著座標移動
    glutSolidTeapot(0.3);//實心茶壺
    glPopMatrix();//矩陣還原
    glutSwapBuffers();//交換兩倍的buffers
}
//void mouse(int button,int state,int x,int y)//今日03
//{
//   if(state==GLUT_DOWN){
//        printf("glVertex3f((%d-150)/150.0,-(%d-150)/150.0\n",x,y);
//  }
    //printf("button:%d,state:%d,x:%d,y:%d\n",button,state,x,y);
//}
void motion(int x,int y){//今日2-02
    teapotx=(x-150)/150.0;
    teapoty=-(y-150)/150.0;
    display();
}
int main(int argc,char**argv)//以前是int main()
{
    glutInit(&argc,argv);//GLUT初始值

    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//顯示模式

    glutCreateWindow("week04");//開窗

    glutDisplayFunc(display);//等一下要顯示的函式
    //glutMouseFunc(mouse);//今日01
    glutMotionFunc(motion);//今日2-02
    glutMainLoop();//主要迴圈
}
可以用滑鼠拖曳茶壺
4、了解旋轉的過程
後面三個參數選定x y z
選轉的方向就像是安培右手一樣







沒有留言:

張貼留言

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

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