2019年3月14日 星期四

WEEK04-馬丁

(1) 主題 :移動 Tarnslate
(2) 示範 :glTranslatef(x,y,z)



1.進入http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/下載這三個的檔案





2.win32解壓縮為資料夾,再將data也解壓縮為資料夾,最後將data的資料夾跟glut32.dll檔案放入windows

3.進入https://www.transmissionzero.co.uk/software/freeglut-devel/下載檔案


4.freeglut講壓縮至桌面,將lib資料夾內的libfreeglut.a複製一個並改名為libglut32.a

5.開啟CodeBlocks打上下面這程式碼,這個程式碼是對的,不會有兩個茶壺跑出

#include <GL/glut.h>
void display()
{
     glPushMatrix();
     glTranslatef(0.3,0.3,0);
     glutSolidTeapot( 0.3 );
     glPopMatrix();
     glutSwapBuffers();
}
int main(int argc, char**argv)
{

     glutInit(&argc, argv);
     glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
     glutCreateWindow("week04");
     glutDisplayFunc(display);
     glutMainLoop();
}

6.以下程式碼可以用滑鼠控制茶壺,將它拖移

#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();
}

沒有留言:

張貼留言