2021年3月15日 星期一

賣女孩的小火柴Week04


💻電腦圖學💻

本日主題:移動、旋轉、放大縮小




                電腦圖學 Week04 2021-03-15
1. 主題: 移動、旋轉、放大縮小
2. glTranslatef(x, y, z);
3. glRotatef( angle, x, y, z);
4. glScalef(x, y, z);
5. 主題: mouse motion函式


                              


#include <GL/glut.h>
#include <stdio.h>
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glEnd();
    glutSwapBuffers();///交換兩倍的buffers
}
void mouse(int button,int state,int x,int y)
{
    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,0);\n",x,y);
    }
}

int main(int argc,char ** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160201賣女孩的小火柴");///開啟視窗


    glutDisplayFunc(display);///顯示的函示
    glutMouseFunc(mouse);
    glutMainLoop();///主要迴圈
}


#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();
    glEnd();
    glutSwapBuffers();///交換兩倍的buffers
}

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_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("08160201賣女孩的小火柴");///開啟視窗


    glutDisplayFunc(display);///顯示的函示   
    glutMotionFunc(motion);
    glutMainLoop();///主要迴圈
}





                                    glTranslatef(0.000.000.00);

                             改變物體的 (    X ,   Y  ,   Z  ) 

                                               glRptatef (0.0,1.00,0.00,0.00);

                                     改變物體旋轉方向

                                     旋轉可用右手定律了解旋轉的方向

                                      glRptatef (0.0,1.00,0.00,0.00);

                                      開始旋轉



                                      glRptatef (0.0,1.00,0.00,0.00);

                                      朝座標X的方向比讚

                                                glRptatef (0.0,1.00,0.00,0.00);

                                      朝座標Y的方向比讚


加課:GitHub 做自己的網站







                                   打完字後,在下一行打上= = = = =





                                     






 





 

沒有留言:

張貼留言

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

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