x,y,z軸的3D移動方向
右手(一定要是右手)比個讚當X,當一條針從巨人旁邊刺入時,人會往其他手指(除了大拇指)握著的方向轉
做Y時想像針從底下往上刺
Z從背後刺入,想像大拇指從巨人背後刺入
物品隨著滑鼠x右移動
茶壺隨著滑鼠在Z軸移動
但目前只要移動到某個地方停下來,再次旋轉時茶壺會回到終點
#include <GL/glut.h>
float myAngle=0;///宣告角度變數
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清畫面
glPushMatrix();
glRotatef(myAngle,0,0,1);///對Z做旋轉
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int oldX=0;///宣告變數
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN) oldX=x;///(1)按下去時記住在哪裡
}
void motion(int x,int y)
{
myAngle+=(x-oldX);///(2)你加了幾度
oldX=x;///(3)
display();///每次移動就呼叫display函式,重畫畫面、旋轉、畫出茶壺
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week04 rotate");
glutMotionFunc(motion);///motion 函式
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
















沒有留言:
張貼留言