2022年3月15日 星期二

END之書 week04

 1. rotate 旋轉


1.1 http://jsyeh.org/3dcg10/

1.1 download   "data"、"win32"

      windows.zip => 下載 => windows => Transformation.exe

      data.zip => 下載 => windows => data => 模型.obj  


1.2 執行 Transformation.exe   => 右上右鍵(換模型)

      (just like last week)


(0.0.0) => 往左、右

(0.0.1) => 原地左右旋轉

(0.1.0) => 往左、右

(0.1.1) => 從左上往頭頂(或相反),最後回原點

(1.0.0) => 往上、下

(1.0.1) => 從右下往右手(或相反),最後回原點

(1.1.0) => 往左上、右下

(1.1.1) => 從右下往頭頂(或相反),最後回原點


1-2 rotate teapot



#include <GL/glut.h> 


void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

        glRotated(90, 0,0,1);

        glutSolidTeapot(0.5);

    glPopMatrix();

    glutSwapBuffers();

}


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

{

    glutInit(&argc, argv); 

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); 


    glutCreateWindow("week04旋轉"); 


    glutDisplayFunc(display); 


    glutMainLoop(); 

}


1-3 mouse rotate teapot(滑鼠放開再點會重置)



#include <GL/glut.h>

float angle=0;

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();///備份

        glRotated(angle, 0,0,1);


        glutSolidTeapot(0.5);

    glPopMatrix();///還原

    glutSwapBuffers();

}


void motion(int x,int y)

{

    angle=x;

    display();///重畫畫面

}


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

{

    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);


    glutCreateWindow("week04旋轉");


    glutDisplayFunc(display);


    glutMotionFunc(motion);///mouse motion


    glutMainLoop();

}

1-4  mouse rotate teapot(不會重置)



#include <GL/glut.h>
float angle=0,oldx=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份
        glRotated(angle, 0,0,1);

        glutSolidTeapot(0.5);
    glPopMatrix();///還原
    glutSwapBuffers();
}

void motion(int x,int y)
{
    angle += (x-oldx);
    oldx=x;
    display();///重畫畫面
}

void mouse (int button,int state,int x,int y)
{
    oldx=x;///定錨
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week04旋轉");

    glutDisplayFunc(display);

    glutMotionFunc(motion);///mouse motion
    glutMouseFunc(mouse);///mouse按下放開
    glutMainLoop();
}


沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...