##translate 移動
float teapotX=0,teapotY=0; 新加的程式,用來放茶壺的座標
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();/// 備份矩陣
glTranslatef(teapotX,teapotY,0);///把座標移動
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
glutSwapBuffers();
##rotate 旋轉(角度,x,y,z)右手安培
float angle=0; ///旋轉角度
glRotatef(angle,0,0,1); ///z軸
glutMotionFunc(motion); ///設定motion的motion動作
mouse在拖曳motion動
## glutKeyboardFunc(keyboard);
key你正在按的按鍵 (key=='e') ///旋轉
int method =1; ///1:旋轉 2:移動
int oldX=0,oldY=0;
-----------
void keyboard(unsigned char key,int x,int y)
{
if(key=='e') method=1; ///旋轉rotate
if(key=='w') method=2; ///移動translate
}
#include <stdio.h>為了printf()
點擊茶壺頁面, 在另個視窗會跳出打出的訊息
紅字2=回彈(點下去0, 彈上來1)
x代表x座標 y代表y座標






沒有留言:
張貼留言