step01-1
先去小葉老師的網站(https://jsyeh.org/3dcg10 )下載windows.zip及data.zip,之後把data資料夾移到windows資料夾裡面,然後開啟Transformations.exe。
step01-2
CodeBlocks-File_New_Project,GLUT專案,檔名為week03-1_translate
之後把內容的程式碼全部刪除改成下列圖片
step01-3
利用Github gist網站,之後複製Codeblock的程式碼到上面
step01-4
glPushMatrix();///備份矩陣
glTranslatef( 0.5, 0.5, 0);///改變矩陣
glPopMatrix();///還原矩陣
step02-1
開啟新的Projects 名稱改成week03-2_translate_mouse
把原本的程式碼複製上去。
之後要加上mouse的移動功能,要使用global變數。
#include <GL/glut.h>
float X=0, Y=0, Z=0; ///step03-1 使用 global 變數
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );///step03-1 清背景
glPushMatrix(); ///備份矩陣
glTranslatef( X, Y, Z ); ///step03-1 照著 X,Y,Z來移動
glutSolidTeapot( 0.3 );
glPopMatrix(); ///還原矩陣
glutSwapBuffers();
}
void mouse( int button, int state, int x, int y ) ///step03-1 mouse()
{ /// 左中右鍵 按下/放開 小x 小y 0...300
X = (x-150)/150.0; ///step03-1 減一半、除一半
Y = -(y-150)/150.0; ///step03-1 減一半、除一半、y變負的
}
int main(int argc, char* argv[] )
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03");
glutMouseFunc(mouse); ///step03-1 設定好 mouse函式
glutDisplayFunc(display);
glutMainLoop();
}
step02-2
使用滑鼠座標來製作圖案








沒有留言:
張貼留言