#week03
## week03-1 mouse 滑鼠
1.freeglut 拉到桌面,再把lib 的libfreeglut.a複製成libglut32.a
2.CodeBlocks File-New-Project,GLUT專案
week03_mouse
3.把blog/github的10行程式貼進來
4.再三行
##Transformatiom
1.到https://jsyeh.org/3dcg10/ 下載課本範例
data win32
2.將windows解壓縮,再將data.zip裡的data進windows資料夾內
3.打開Tramsformation
1.file-glut專案-專案名week03-mouse_glTranslate
2.複製mouse內容並加上新的程式碼
float teapotX=0,teapotY=0;///新加的程式,用來放茶壺的座標
void mouse (int button,int state,int x,int y)
{
teapotX=(x-150)/150.0;
teapotY = -(y-150)/150.0;
}//state->0;下去,:上來
display 內加
glCleat(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffer();
##week03-3 glRotatef旋轉(角度,x,y,z)
1.file-glut專案 week03_mouse_glRotatef
2.複製 week03_mouse_glTranslate的程式碼
include下方加上
float angle=0; //旋轉角度
display的glPushMatrix();
將glTranslatef(teapotX,teapotY,0);註解
glRotatef(angle,0,0,1);//z軸
void motion(int x,int y)
{
angle=x;
display();
}
main
glutMotionFunc(motion);///設定motion的motion動作
mouse在拖拽motion動
##glTranslate+glRotate
1.file -glut專案-week03_mouse_translate_rotate
2.複製week03_mouse_glRotatef的程式碼
main
glutkeyboardFunc(keyboard);
motion
void keyboard(unsigned char key,int x,int y)
{
if(key =='e')method=1;
if(key=='w')method=2;
}
修改motion
void motion(int x,int y)
{
if(method==1){
angle +=x-oldX;
}
else if(method==2)
{
teapotX+=(x-oldX)/150.0;
teapotY+=(x-oldY)/150.0;
}
oldX =x;
oldY=y;
display();
}
mouse上加上
int method=1;
int oldX = 0, oldY = 0;
display解開註解
glTranslatef(teapotX,teapotY,0);
沒有留言:
張貼留言