#mouse 滑鼠
1.安裝freeglut 拉到桌面 ,改lib 內檔名為libglut32.a
2.打開Codeblocks 新增專案 week03_mouse
3.10行程式貼上
4.加上mouse 的程式
5.執行程式就會出現茶壺,點滑鼠就會有Hello World
glTranslatef( ) glRotatef( ) glScalef ( )
glPushMatrix();///備分矩陣
glPopMatrix();///還原矩陣
以上考試會考!!
#include <GL/glut.h>
#include <stdio.h>///為了printf()
float teapotX = 0 , teapotY = 0;///新家的程式,用來放茶壺的座標
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glPushMatrix();///備分矩陣
glTranslatef(teapotX,teapotY,0);///座標移動
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
//glutSolidTeapot(0.3);///畫一個實心的茶壺,大小是0.3
glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
void mouse(int button,int state,int x,int y)
{///我們這裡要做巧妙的修正
teapotX = (x-150)/150.0;
teapotY = -(y-150)/150.0;
}
int main(int argc, char *argv[])
{ ///上面是特別的main函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來 (GLUT初始化)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
///上面這行是把顯示的模式設定好
glutCreateWindow("week03 mouse glTranslatef");///要開視窗
glutDisplayFunc(display);///要顯示的對應函式
glutMouseFunc(mouse);///這一行設定mouse函式
glutMainLoop();///最後用main迴圈,壓在最後面
}
#安培右手定則
9. 轉動( Z軸 )
10. 結合
沒有留言:
張貼留言