2019年3月15日 星期五

耀鑫的筆記 Week04

一、嘗試使用glRotatef
1.先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/把datawin32glut32.dll下載下來

2.然後把win32解壓縮到windows資料夾中
3.把data也解壓縮到windows資料夾中
4.把glut32.dll丟到windows資料夾中
5.到windows資料夾中開啟Transformation.exe
6.用滑鼠拖曳glRotatef,觀察變化
二、
2.然後把libfreeglut複製並改名

3.開啟codeblocks,並開啟open glut方案
4.將裡面的程式碼改成
#include <GL/glut.h>
float x=0,y=0;///現在重點在滑鼠
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣,保護好
        glTranslatef((x-150)/150.0,-(y-150)/150.0,0);///用於移動
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣,恢復
    glutSwapBuffers();
}
void motion(int nowx,int nowy)
{
    x=nowx;y=nowy;
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///現在重點在滑鼠
    glutMainLoop();
}

glTranslatef     (x,y,z)     移動
   glRotatef  (angle,x,y,z)  旋轉
   glScalef    (x,y,z)    放大縮小


5.使用滑鼠拖曳移動茶壺

6.翻轉茶壺


glRotatef(y,1,0,0);
glRotatef(x,0,1,0);
增加以上兩行程式碼透過滑鼠翻轉茶壺

2 則留言: