儲存(堆疊)矩陣:將目前的矩陣堆疊進matrix stack的頂端
void glPushMatrix(void);
載入(取出)矩陣:將matrix stack頂端的矩陣取出覆蓋目前的矩陣
void glPopMatrix(void);
單位矩陣:將目前的矩陣改為單位矩陣(4X4)
void glLoadIdentity(void);
指定平移:
1 0 0 x | newX = X+x
0 1 0 y | newY = Y+y
0 0 1 z | newZ = Z+z
0 0 0 1 | 1 = 1
void glTranslated(GLdouble x, GLdouble y, GLdouble z);
void glTranslatef(GLfloat x, GLfloat y, GLfloat z);
x, y, z :平移矩陣
指定旋轉向量:
void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
angle :指定旋轉角度(度) 逆時針
x, y, z :以此向量為軸(會自動換成單位向量) 右手定理
glRotated(angle,0,1,1); != glRotated(angle,0,0,1); + glRotated(angle,0,1,0);
縮放:
x 0 0 0 | newX = xX
0 y 0 0 | newY = yY
0 0 z 0 | newZ = zZ
0 0 0 1 | 1 = 1
void glScaled(GLdouble x, GLdouble y, GLdouble z);
void glScalef(GLfloat x, GLfloat y, GLfloat z);
x, y, z :xyz軸以此比例尺放大縮小
指定視角:
void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
GLdouble centerX, GLdouble centerY, GLdouble centerZ,
GLdouble upX, GLdouble upY, GLdouble upZ);
eyeX, eyeY, eyeZ:指定從哪裡看
centerX, centerY, centerZ :指定看哪裡
upX, upY, upZ :指定向上的向量

函式:input
鍵盤讀取:
glutKeyboardFunc(keyborad);
void keyboard(unsigned char word, int x, int y)
{
word:讀到的字元
x, y :此時鼠標的位置(像素)(左上為0, 0、右下為W, H)
}
F1, Ctrl ...等功能鍵有另外的函式處理
滑鼠讀取:
glutMouseFunc(mouse);
void mouse(int button,int state,int x,int y)
{
button :左鍵(GLUT_LEFT_BUTTON)、中鍵(GLUT_MIDDLE_BUTTON)
、右鍵(GLUT_RIGHT_BUTTON)
state :按下去(GLUT_DOWN)、起來(GLUT_UP)
x, y :此時鼠標的位置(像素)(左上為0, 0、右下為W, H)
}
滑鼠拖曳移動:
glutMotionFunc(motion);
void motion(int x,int y)
{
x, y :此時鼠標的位置(像素)(左上為0, 0、右下為W, H)
裡面可加:glutPostRedisplay();告知系統重畫繪圖
}
滑鼠讀取:
glutMouseFunc(mouse);
void mouse(int button,int state,int x,int y)
{
button :左鍵(GLUT_LEFT_BUTTON)、中鍵(GLUT_MIDDLE_BUTTON)
、右鍵(GLUT_RIGHT_BUTTON)
state :按下去(GLUT_DOWN)、起來(GLUT_UP)
x, y :此時鼠標的位置(像素)(左上為0, 0、右下為W, H)
}
滑鼠拖曳移動:
glutMotionFunc(motion);
void motion(int x,int y)
{
x, y :此時鼠標的位置(像素)(左上為0, 0、右下為W, H)
裡面可加:glutPostRedisplay();告知系統重畫繪圖
}
沒有留言:
張貼留言