2022年3月15日 星期二

新手上碌_week04

 WEEK_04:

主題:旋轉 rotate,旋轉角度,旋轉軸,glRotatef(angle,x,y,z)

1.看範例:https://jsyeh.org/3dcg10/ >>>下載win32 , data >>>解壓縮>>transformation

使用右手定則


開啟茶壺檔>>>新增glRotatef(angle,x,y,z);

motion() &&  glutMotionFunc(motion);滑鼠控制

>>滑鼠移動停止後再點擊,茶壺會回到原來位置>>>解決不連續的問題:
利用上周教的mouse():不連續,適合擷取點座標

#include <GL/glut.h>///使用GLUT的外掛
float angle=0,oldx=0;
void display(){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///畫之前先清除畫面
    glPushMatrix();///備份矩陣
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);///畫茶壺
    glPopMatrix();///還原矩陣

    glutSwapBuffers();///畫好後呈現出來
}
void motion(int x,int y){
    angle+=(x-oldx);
    oldx=x;    ///把舊的X設為最後滑鼠停止的位置
    display();///變更後再重畫 畫面
}
void mouse(int button,int state,int x,int y){
    oldx=x;
}
int main(int argc,char** argv){
    glutInit(&argc,argv);///把參數送給glutInit初始化
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);///雙緩衝區+3D深度功能
    glutCreateWindow("第04周的程式喔!");///開啟GLUT視窗

    glutDisplayFunc(display);///用來顯示的程式
    glutMotionFunc(motion);///mouse motion移動
    glutMouseFunc(mouse);///03周教的滑鼠控制

    glutMainLoop();///主要的程式迴圈
}












沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...