2016年3月21日 星期一

2016/3/21 Week05

Hw 01:

Step 1:
到下列網址 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 下載紅色框框內的東西


Step 2:
將下載好的兩個壓縮檔解壓縮後,把Data資料夾和glut32.dll移動至Windows資料夾裡面

///注意Data資料夾裡面不能再有Data資料夾,如果有要將最內層的所有檔案複製到第二層。


Step 2:
打開Transformation,並且改變個個數值,紅色數值改變為水平移動。
///此移動是以車子為中心點




垂直移動:



前後移動:





Step 3:


按滑鼠右鍵,選擇[x]Swap translate/rotate得到以下畫面
//像是放在碗裡,已晚的中心點來坐旋轉


比較不同旋轉的差別





Hw 02:

讓茶壺旋轉



#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的量值
        glRotated(rotX,0,1,0);///對X軸移動
        glRotated(rotY,0,1,0);///對Y軸移動
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原Maxtrix,回到剛剛Push的位置
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x, rotY=y;
    display();///glutPostRedisplay();
}

int main(int argc,char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH|GLUT_DEPTH);///設定2D 3D
    glutInitWindowSize(300,300);
    glutInitWindowPosition(600,0);
    glutCreateWindow("hello");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}



Hw 03:

自己的作業加上旋轉



#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    //(x-100)/100
    //-(y-100)/100
    //glVertex2f(,);
    glPushMatrix();
    glRotatef(rotY, 1,0,0);
    glRotatef(rotX, 0,1,0);
    glBegin(GL_POLYGON);
        glColor3ub(60,129,246);

        glVertex2f(-0.94,0.69);
        glVertex2f(-0.66,0.78);
        glVertex2f(-0.43,0.69);
        glVertex2f(-0.7,0.6);

    glEnd();

   /*太長以下省略*/

    glEnd();

    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x; rotY=y;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Hello 3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}

沒有留言:

張貼留言