2016年3月21日 星期一

Week05

旋轉 移動
mouse與旋轉
階層式旋轉
階層式移動
1
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

(A) Translate Rotate


(B) Rotate Translate


課堂作業1-2
左耳貼肩膀彎
橫著看程式碼
從最後一行看
rotate
translate
scale
先移動再旋轉


課堂作業1-3
從最後一行看
translate
rotate
scale
先旋轉再移動

課堂作業2


#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();    ///備份Matrix (Matrix裡有translate,rotate,scale的量值)
        glRotatef(rotX, 1,0,0);   ///圖2     /////(rotX,0,1,0)圖1
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();     ///還原Matrix(回到剛剛push時的樣子)
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=y;    ///圖2    ///rotX=x;圖1
    display();    ///可以用glutPostRedisplay();一樣的意思
}


int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);    ////double buffers有兩倍的記憶體,一                                                                                                                                                            個屬於螢幕上,一個是內部記憶體
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
課堂作業3

#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();    ///備份Matrix (Matrix裡有translate,rotate,scale的量值)
        glRotatef(rotX, 1,0,0); ///X的移動量,是跟Y軸旋轉
        glRotatef(rotY, 0,1,0); ///Y的移動量,是跟X軸旋轉
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();     ///還原Matrix(回到剛剛push時的樣子)
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;     ///同時用XY軸旋轉
    rotY=y;    ///同時用XY軸旋轉
    display();    ///可以用glutPostRedisplay();一樣的意思
}


int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);    ///double buffers有兩倍的記憶體,一個屬於                                                                                                                                            螢幕上,一個是內部記憶體
     glutInitWindowSize(400,400);glutInitWindowPosition(800,240);        ///視窗的大小還有視窗的位子
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}


沒有留言:

張貼留言