2024年3月4日 星期一

fangg week03

 

##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()
點擊茶壺頁面, 在另個視窗會跳出打出的訊息

紅字1=左鍵(左鍵0, 中鍵1, 右鍵2)
紅字2=回彈(點下去0, 彈上來1)
x代表x座標 y代表y座標

可直接改成程式碼

滑鼠點擊,茶壺即移動



 讓茶壺旋轉的程式


 按'W'可移動位置, 按'E'可旋轉, 類似於maya程式

沒有留言:

張貼留言