上課進度
1.主題:移動
2.示範:glTranslate(x,y,z)
3.先跟上禮拜一樣打開http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
下在以下三個框起來的網址
5.再把data移到window的資料夾裡
6.再把glut32拉到window的資料夾裡
7.打開一個名叫Transformation的資料
8.打開後會出現這個
用滑鼠點紅色框框裡的數字在上下滑動能讓裡面的車子移動
把下載完的移到桌面再進入lib的資料夾
10.進去後複製圖片中所選的資料再重新命名為libglut32
11.打開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("06160396-Week04");
glutDisplayFunc(display);
glutMainLoop();
}
會出現下面這圖
12.想要用滑鼠來移動茶壺須修改程式如下
#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);
///glVertex2f((x-150)/150.0, -(y-150)/150.0, 0));
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("06160396-Week04");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
下面是圖片
沒有留言:
張貼留言